summaryrefslogtreecommitdiffstats
path: root/source/slang/ir.h
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2018-02-19 19:53:45 -0500
committerYong He <yonghe@outlook.com>2018-02-19 19:53:45 -0500
commit5de62bbe4dddc64895ddb17c4eb3572c3c9be248 (patch)
treed12fd2a9bad9a632430e1262de8f7e7da388bffa /source/slang/ir.h
parentff8adf7b45121aada0b4f4403b0f45a6e2dfe475 (diff)
more to fixing memory leaks
1. reorder destruction order of several key classes to avoid using deleted IR objects when destroying Types 2. remove Session::canonicalTypes and make each Type own a RefPtr to the canonicalType, to allow types to be destroyed along with each IRModule it belongs to.
Diffstat (limited to 'source/slang/ir.h')
-rw-r--r--source/slang/ir.h20
1 files changed, 18 insertions, 2 deletions
diff --git a/source/slang/ir.h b/source/slang/ir.h
index 4cdd1f1de..fdca73a83 100644
--- a/source/slang/ir.h
+++ b/source/slang/ir.h
@@ -119,6 +119,10 @@ enum IRDecorationOp : uint16_t
struct IRObject
{
bool isDestroyed = false;
+ virtual void dispose()
+ {
+ isDestroyed = true;
+ }
virtual ~IRObject()
{
isDestroyed = true;
@@ -134,7 +138,6 @@ struct IRDecoration : public IRObject
IRDecoration* next;
IRDecorationOp op;
- virtual ~IRDecoration() = default;
};
// Use AST-level types directly to represent the
@@ -181,6 +184,8 @@ struct IRValue : public IRObject
// Free a value (which needs to have been removed
// from its parent, had its uses eliminated, etc.)
void deallocate();
+
+ virtual void dispose() override;
};
// Values that are contained in a doubly-linked
@@ -492,6 +497,11 @@ struct IRGlobalValue : IRValue
void removeFromParent();
void moveToEnd();
+ virtual void dispose() override
+ {
+ IRValue::dispose();
+ mangledName = String();
+ }
};
/// @brief A global value that potentially holds executable code.
@@ -541,6 +551,12 @@ struct IRFunc : IRGlobalValueWithCode
// which are actually the parameters of the first
// block.
IRParam* getFirstParam();
+
+ virtual void dispose() override
+ {
+ IRGlobalValueWithCode::dispose();
+ genericDecls = decltype(genericDecls)();
+ }
};
// A module is a parent to functions, global variables, types, etc.
@@ -563,7 +579,7 @@ struct IRModule : RefObject
{
for (auto val : irObjectsToFree)
if (!val->isDestroyed)
- val->~IRObject();
+ val->dispose();
irObjectsToFree = List<IRObject*>();
}
};