Skip to content

Commit

Permalink
C++: Add testcase with two destructor calls without a temporary objec…
Browse files Browse the repository at this point in the history
…t expression at the top-level.
  • Loading branch information
MathiasVP committed Apr 8, 2024
1 parent febd060 commit 670ca5a
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 0 deletions.
22 changes: 22 additions & 0 deletions cpp/ql/test/library-tests/ir/ir/PrintAST.expected
Original file line number Diff line number Diff line change
Expand Up @@ -2367,6 +2367,28 @@ destructors_for_temps.cpp:
# 99| Type = [Struct] ClassWithDestructor3
# 99| ValueCategory = xvalue
# 100| getStmt(1): [ReturnStmt] return ...
# 102| [TopLevelFunction] void temp_test12(ClassWithDestructor3)
# 102| <params>:
# 102| getParameter(0): [Parameter] x
# 102| Type = [Struct] ClassWithDestructor3
# 102| getEntryPoint(): [BlockStmt] { ... }
# 103| getStmt(0): [ExprStmt] ExprStmt
# 103| getExpr(): [FunctionCall] call to getClassWithDestructor2
# 103| Type = [Class] ClassWithDestructor2
# 103| ValueCategory = prvalue
# 103| getQualifier(): [VariableAccess] x
# 103| Type = [Struct] ClassWithDestructor3
# 103| ValueCategory = lvalue
# 103| getExpr().getFullyConverted(): [TemporaryObjectExpr] temporary object
# 103| Type = [Class] ClassWithDestructor2
# 103| ValueCategory = prvalue
# 103| getImplicitDestructorCall(0): [DestructorCall] call to ~ClassWithDestructor2
# 103| Type = [VoidType] void
# 103| ValueCategory = prvalue
# 103| getQualifier(): [ReuseExpr] reuse of temporary object
# 103| Type = [Class] ClassWithDestructor2
# 103| ValueCategory = xvalue
# 104| getStmt(1): [ReturnStmt] return ...
ir.c:
# 5| [TopLevelFunction] int getX(MyCoords*)
# 5| <params>:
Expand Down
31 changes: 31 additions & 0 deletions cpp/ql/test/library-tests/ir/ir/aliased_ir.expected
Original file line number Diff line number Diff line change
Expand Up @@ -1544,6 +1544,37 @@ destructors_for_temps.cpp:
# 94| v94_6(void) = AliasedUse : ~m99_28
# 94| v94_7(void) = ExitFunction :

# 102| void temp_test12(ClassWithDestructor3)
# 102| Block 0
# 102| v102_1(void) = EnterFunction :
# 102| m102_2(unknown) = AliasedDefinition :
# 102| m102_3(unknown) = InitializeNonLocal :
# 102| m102_4(unknown) = Chi : total:m102_2, partial:m102_3
# 102| r102_5(glval<ClassWithDestructor3>) = VariableAddress[x] :
# 102| m102_6(ClassWithDestructor3) = InitializeParameter[x] : &:r102_5
# 103| r103_1(glval<ClassWithDestructor2>) = VariableAddress[#temp103:5] :
# 103| r103_2(glval<ClassWithDestructor3>) = VariableAddress[x] :
# 103| r103_3(glval<unknown>) = FunctionAddress[getClassWithDestructor2] :
# 103| r103_4(ClassWithDestructor2) = Call[getClassWithDestructor2] : func:r103_3, this:r103_2
# 103| m103_5(unknown) = ^CallSideEffect : ~m102_4
# 103| m103_6(unknown) = Chi : total:m102_4, partial:m103_5
# 103| v103_7(void) = ^IndirectReadSideEffect[-1] : &:r103_2, m102_6
# 103| m103_8(ClassWithDestructor3) = ^IndirectMayWriteSideEffect[-1] : &:r103_2
# 103| m103_9(ClassWithDestructor3) = Chi : total:m102_6, partial:m103_8
# 103| m103_10(ClassWithDestructor2) = Store[#temp103:5] : &:r103_1, r103_4
# 103| r103_11(glval<ClassWithDestructor2>) = CopyValue : r103_1
# 103| r103_12(glval<unknown>) = FunctionAddress[~ClassWithDestructor2] :
# 103| v103_13(void) = Call[~ClassWithDestructor2] : func:r103_12, this:r103_11
# 103| m103_14(unknown) = ^CallSideEffect : ~m103_6
# 103| m103_15(unknown) = Chi : total:m103_6, partial:m103_14
# 103| v103_16(void) = ^IndirectReadSideEffect[-1] : &:r103_11, m103_10
# 103| m103_17(ClassWithDestructor2) = ^IndirectMayWriteSideEffect[-1] : &:r103_11
# 103| m103_18(ClassWithDestructor2) = Chi : total:m103_10, partial:m103_17
# 104| v104_1(void) = NoOp :
# 102| v102_7(void) = ReturnVoid :
# 102| v102_8(void) = AliasedUse : ~m103_15
# 102| v102_9(void) = ExitFunction :

ir.c:
# 7| void MyCoordsTest(int)
# 7| Block 0
Expand Down
4 changes: 4 additions & 0 deletions cpp/ql/test/library-tests/ir/ir/destructors_for_temps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,8 @@ void temp_test11() {
// First, ~ClassWithDestructor2::ClassWithDestructor2(), and then the call
// to `~ClassWithDestructor3::ClassWithDestructor3()`.
makeClassWithDestructor3().getClassWithDestructor2();
}

void temp_test12(ClassWithDestructor3 x) {
x.getClassWithDestructor2();
}
27 changes: 27 additions & 0 deletions cpp/ql/test/library-tests/ir/ir/operand_locations.expected
Original file line number Diff line number Diff line change
Expand Up @@ -1375,6 +1375,33 @@
| destructors_for_temps.cpp:99:32:99:54 | ChiTotal | total:m99_6 |
| destructors_for_temps.cpp:99:32:99:54 | SideEffect | ~m99_6 |
| destructors_for_temps.cpp:99:32:99:54 | StoreValue | r99_9 |
| destructors_for_temps.cpp:102:6:102:16 | ChiPartial | partial:m102_3 |
| destructors_for_temps.cpp:102:6:102:16 | ChiTotal | total:m102_2 |
| destructors_for_temps.cpp:102:6:102:16 | SideEffect | ~m103_15 |
| destructors_for_temps.cpp:102:39:102:39 | Address | &:r102_5 |
| destructors_for_temps.cpp:103:5:103:5 | Address | &:r103_2 |
| destructors_for_temps.cpp:103:5:103:5 | Address | &:r103_2 |
| destructors_for_temps.cpp:103:5:103:5 | Arg(this) | this:r103_2 |
| destructors_for_temps.cpp:103:5:103:5 | ChiPartial | partial:m103_8 |
| destructors_for_temps.cpp:103:5:103:5 | ChiTotal | total:m102_6 |
| destructors_for_temps.cpp:103:5:103:5 | SideEffect | m102_6 |
| destructors_for_temps.cpp:103:5:103:31 | Address | &:r103_1 |
| destructors_for_temps.cpp:103:5:103:31 | Address | &:r103_11 |
| destructors_for_temps.cpp:103:5:103:31 | Address | &:r103_11 |
| destructors_for_temps.cpp:103:5:103:31 | Arg(this) | this:r103_11 |
| destructors_for_temps.cpp:103:5:103:31 | CallTarget | func:r103_12 |
| destructors_for_temps.cpp:103:5:103:31 | ChiPartial | partial:m103_14 |
| destructors_for_temps.cpp:103:5:103:31 | ChiPartial | partial:m103_17 |
| destructors_for_temps.cpp:103:5:103:31 | ChiTotal | total:m103_6 |
| destructors_for_temps.cpp:103:5:103:31 | ChiTotal | total:m103_10 |
| destructors_for_temps.cpp:103:5:103:31 | SideEffect | m103_10 |
| destructors_for_temps.cpp:103:5:103:31 | SideEffect | ~m103_6 |
| destructors_for_temps.cpp:103:5:103:31 | Unary | r103_1 |
| destructors_for_temps.cpp:103:7:103:29 | CallTarget | func:r103_3 |
| destructors_for_temps.cpp:103:7:103:29 | ChiPartial | partial:m103_5 |
| destructors_for_temps.cpp:103:7:103:29 | ChiTotal | total:m102_4 |
| destructors_for_temps.cpp:103:7:103:29 | SideEffect | ~m102_4 |
| destructors_for_temps.cpp:103:7:103:29 | StoreValue | r103_4 |
| file://:0:0:0:0 | Address | &:r0_1 |
| file://:0:0:0:0 | Address | &:r0_1 |
| file://:0:0:0:0 | Address | &:r0_1 |
Expand Down
26 changes: 26 additions & 0 deletions cpp/ql/test/library-tests/ir/ir/raw_ir.expected
Original file line number Diff line number Diff line change
Expand Up @@ -1399,6 +1399,32 @@ destructors_for_temps.cpp:
# 94| v94_5(void) = AliasedUse : ~m?
# 94| v94_6(void) = ExitFunction :

# 102| void temp_test12(ClassWithDestructor3)
# 102| Block 0
# 102| v102_1(void) = EnterFunction :
# 102| mu102_2(unknown) = AliasedDefinition :
# 102| mu102_3(unknown) = InitializeNonLocal :
# 102| r102_4(glval<ClassWithDestructor3>) = VariableAddress[x] :
# 102| mu102_5(ClassWithDestructor3) = InitializeParameter[x] : &:r102_4
# 103| r103_1(glval<ClassWithDestructor2>) = VariableAddress[#temp103:5] :
# 103| r103_2(glval<ClassWithDestructor3>) = VariableAddress[x] :
# 103| r103_3(glval<unknown>) = FunctionAddress[getClassWithDestructor2] :
# 103| r103_4(ClassWithDestructor2) = Call[getClassWithDestructor2] : func:r103_3, this:r103_2
# 103| mu103_5(unknown) = ^CallSideEffect : ~m?
# 103| v103_6(void) = ^IndirectReadSideEffect[-1] : &:r103_2, ~m?
# 103| mu103_7(ClassWithDestructor3) = ^IndirectMayWriteSideEffect[-1] : &:r103_2
# 103| mu103_8(ClassWithDestructor2) = Store[#temp103:5] : &:r103_1, r103_4
# 103| r103_9(glval<ClassWithDestructor2>) = CopyValue : r103_1
# 103| r103_10(glval<unknown>) = FunctionAddress[~ClassWithDestructor2] :
# 103| v103_11(void) = Call[~ClassWithDestructor2] : func:r103_10, this:r103_9
# 103| mu103_12(unknown) = ^CallSideEffect : ~m?
# 103| v103_13(void) = ^IndirectReadSideEffect[-1] : &:r103_9, ~m?
# 103| mu103_14(ClassWithDestructor2) = ^IndirectMayWriteSideEffect[-1] : &:r103_9
# 104| v104_1(void) = NoOp :
# 102| v102_6(void) = ReturnVoid :
# 102| v102_7(void) = AliasedUse : ~m?
# 102| v102_8(void) = ExitFunction :

ir.c:
# 7| void MyCoordsTest(int)
# 7| Block 0
Expand Down

0 comments on commit 670ca5a

Please sign in to comment.