diff --git a/clang/lib/AST/Interp/Program.h b/clang/lib/AST/Interp/Program.h index 5123dde88c87b..3e3843e71a4ad 100644 --- a/clang/lib/AST/Interp/Program.h +++ b/clang/lib/AST/Interp/Program.h @@ -42,18 +42,17 @@ class Program final { Program(Context &Ctx) : Ctx(Ctx) {} ~Program() { + // Manually destroy all the blocks. They are almost all harmless, + // but primitive arrays might have an InitMap* heap allocated and + // that needs to be freed. + for (Global *G : Globals) + G->block()->invokeDtor(); + // Records might actually allocate memory themselves, but they // are allocated using a BumpPtrAllocator. Call their desctructors // here manually so they are properly freeing their resources. for (auto RecordPair : Records) RecordPair.second->~Record(); - - // Manually destroy all the blocks. They are almost all harmless, - // but primitive arrays might have an InitMap* heap allocated and - // that needs to be freed. - for (Global *G : Globals) { - G->block()->invokeDtor(); - } } /// Marshals a native pointer to an ID for embedding in bytecode.