Skip to content

Commit

Permalink
Fix destructing order (#474)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcauberer authored Feb 24, 2024
1 parent 51ef9d7 commit 0e2e77c
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .run/spice.run.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="spice" type="CMakeRunConfiguration" factoryName="Application" PROGRAM_PARAMS="run -d -O2 -ir ../../media/test-project/test.spice" REDIRECT_INPUT="false" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" EMULATE_TERMINAL="false" PASS_PARENT_ENVS_2="true" PROJECT_NAME="Spice" TARGET_NAME="spice" CONFIG_NAME="Debug" RUN_TARGET_PROJECT_NAME="Spice" RUN_TARGET_NAME="spice">
<configuration default="false" name="spice" type="CMakeRunConfiguration" factoryName="Application" PROGRAM_PARAMS="run -d -O2 ../../media/test-project/test.spice" REDIRECT_INPUT="false" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" EMULATE_TERMINAL="false" PASS_PARENT_ENVS_2="true" PROJECT_NAME="Spice" TARGET_NAME="spice" CONFIG_NAME="Debug" RUN_TARGET_PROJECT_NAME="Spice" RUN_TARGET_NAME="spice">
<envs>
<env name="LLVM_BUILD_INCLUDE_DIR" value="D:/LLVM/build-release/include" />
<env name="LLVM_INCLUDE_DIR" value="D:/LLVM/llvm/include" />
Expand Down
6 changes: 5 additions & 1 deletion src/typechecker/TypeCheckerImplicit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,11 @@ void TypeChecker::implicitlyCallStructDtor(SymbolTableEntry *entry, StmtLstNode
void TypeChecker::doScopeCleanup(StmtLstNode *node) {
// Get all variables, that are approved for deallocation
std::vector<SymbolTableEntry *> vars = currentScope->getVarsGoingOutOfScope();
for (SymbolTableEntry *var : std::ranges::reverse_view(vars)) {
// Sort by reverse declaration order
auto lambda = [](const SymbolTableEntry *a, const SymbolTableEntry *b) { return a->declNode->codeLoc > b->declNode->codeLoc; };
std::ranges::sort(vars, lambda);
// Call dtor for each variable. We call the dtor in reverse declaration order
for (SymbolTableEntry *var : vars) {
// Only generate dtor call for structs and if not omitted
if (!var->getType().is(TY_STRUCT) || var->omitDtorCall)
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ define dso_local i32 @main() #0 {
%18 = icmp eq i32 %17, 1
%19 = select i1 %18, i32 9, i32 12
%20 = call i32 (ptr, ...) @printf(ptr noundef @printf.str.4, i32 %19)
call void @_ZN6String4dtorEv(ptr %1)
call void @_ZN6String4dtorEv(ptr %2)
call void @_ZN6String4dtorEv(ptr %1)
%21 = load i32, ptr %result, align 4
ret i32 %21
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ define dso_local i32 @main() #0 {
%9 = load %struct.String, ptr %2, align 8
%fct4 = load ptr, ptr %callbackWithArgs2, align 8
call void %fct4(%struct.String %9, i1 false)
call void @_ZN6String4dtorEv(ptr %1)
call void @_ZN6String4dtorEv(ptr %2)
call void @_ZN6String4dtorEv(ptr %1)
%10 = load i32, ptr %result, align 4
ret i32 %10
}
Expand Down

0 comments on commit 0e2e77c

Please sign in to comment.