Skip to content

Commit 9c25ce4

Browse files
committed
C++: Add testcase with two destructor calls without a temporary object expression at the top-level.
1 parent febd060 commit 9c25ce4

File tree

5 files changed

+155
-0
lines changed

5 files changed

+155
-0
lines changed

cpp/ql/test/library-tests/ir/ir/PrintAST.expected

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2367,6 +2367,42 @@ destructors_for_temps.cpp:
23672367
# 99| Type = [Struct] ClassWithDestructor3
23682368
# 99| ValueCategory = xvalue
23692369
# 100| getStmt(1): [ReturnStmt] return ...
2370+
# 102| [TopLevelFunction] void temp_test12(ClassWithDestructor3)
2371+
# 102| <params>:
2372+
# 102| getParameter(0): [Parameter] x
2373+
# 102| Type = [Struct] ClassWithDestructor3
2374+
# 102| getEntryPoint(): [BlockStmt] { ... }
2375+
# 103| getStmt(0): [ExprStmt] ExprStmt
2376+
# 103| getExpr(): [AddExpr] ... + ...
2377+
# 103| Type = [IntType] int
2378+
# 103| ValueCategory = prvalue
2379+
# 103| getLeftOperand(): [FunctionCall] call to get_x
2380+
# 103| Type = [PlainCharType] char
2381+
# 103| ValueCategory = prvalue
2382+
# 103| getQualifier(): [FunctionCall] call to getClassWithDestructor2
2383+
# 103| Type = [Class] ClassWithDestructor2
2384+
# 103| ValueCategory = prvalue
2385+
# 103| getQualifier(): [VariableAccess] x
2386+
# 103| Type = [Struct] ClassWithDestructor3
2387+
# 103| ValueCategory = lvalue
2388+
# 103| getQualifier().getFullyConverted(): [TemporaryObjectExpr] temporary object
2389+
# 103| Type = [Class] ClassWithDestructor2
2390+
# 103| ValueCategory = prvalue(load)
2391+
# 103| getRightOperand(): [Literal] 5
2392+
# 103| Type = [IntType] int
2393+
# 103| Value = [Literal] 5
2394+
# 103| ValueCategory = prvalue
2395+
# 103| getImplicitDestructorCall(0): [DestructorCall] call to ~ClassWithDestructor2
2396+
# 103| Type = [VoidType] void
2397+
# 103| ValueCategory = prvalue
2398+
# 103| getQualifier(): [ReuseExpr] reuse of temporary object
2399+
# 103| Type = [Class] ClassWithDestructor2
2400+
# 103| ValueCategory = xvalue
2401+
# 103| getLeftOperand().getFullyConverted(): [CStyleCast] (int)...
2402+
# 103| Conversion = [IntegralConversion] integral conversion
2403+
# 103| Type = [IntType] int
2404+
# 103| ValueCategory = prvalue
2405+
# 104| getStmt(1): [ReturnStmt] return ...
23702406
ir.c:
23712407
# 5| [TopLevelFunction] int getX(MyCoords*)
23722408
# 5| <params>:

cpp/ql/test/library-tests/ir/ir/aliased_ir.expected

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1544,6 +1544,47 @@ destructors_for_temps.cpp:
15441544
# 94| v94_6(void) = AliasedUse : ~m99_28
15451545
# 94| v94_7(void) = ExitFunction :
15461546

1547+
# 102| void temp_test12(ClassWithDestructor3)
1548+
# 102| Block 0
1549+
# 102| v102_1(void) = EnterFunction :
1550+
# 102| m102_2(unknown) = AliasedDefinition :
1551+
# 102| m102_3(unknown) = InitializeNonLocal :
1552+
# 102| m102_4(unknown) = Chi : total:m102_2, partial:m102_3
1553+
# 102| r102_5(glval<ClassWithDestructor3>) = VariableAddress[x] :
1554+
# 102| m102_6(ClassWithDestructor3) = InitializeParameter[x] : &:r102_5
1555+
# 103| r103_1(glval<ClassWithDestructor2>) = VariableAddress[#temp103:5] :
1556+
# 103| r103_2(glval<ClassWithDestructor3>) = VariableAddress[x] :
1557+
# 103| r103_3(glval<unknown>) = FunctionAddress[getClassWithDestructor2] :
1558+
# 103| r103_4(ClassWithDestructor2) = Call[getClassWithDestructor2] : func:r103_3, this:r103_2
1559+
# 103| m103_5(unknown) = ^CallSideEffect : ~m102_4
1560+
# 103| m103_6(unknown) = Chi : total:m102_4, partial:m103_5
1561+
# 103| v103_7(void) = ^IndirectReadSideEffect[-1] : &:r103_2, m102_6
1562+
# 103| m103_8(ClassWithDestructor3) = ^IndirectMayWriteSideEffect[-1] : &:r103_2
1563+
# 103| m103_9(ClassWithDestructor3) = Chi : total:m102_6, partial:m103_8
1564+
# 103| m103_10(ClassWithDestructor2) = Store[#temp103:5] : &:r103_1, r103_4
1565+
# 103| r103_11(glval<unknown>) = FunctionAddress[get_x] :
1566+
# 103| r103_12(char) = Call[get_x] : func:r103_11, this:r103_1
1567+
# 103| m103_13(unknown) = ^CallSideEffect : ~m103_6
1568+
# 103| m103_14(unknown) = Chi : total:m103_6, partial:m103_13
1569+
# 103| v103_15(void) = ^IndirectReadSideEffect[-1] : &:r103_1, m103_10
1570+
# 103| m103_16(ClassWithDestructor2) = ^IndirectMayWriteSideEffect[-1] : &:r103_1
1571+
# 103| m103_17(ClassWithDestructor2) = Chi : total:m103_10, partial:m103_16
1572+
# 103| r103_18(int) = Convert : r103_12
1573+
# 103| r103_19(int) = Constant[5] :
1574+
# 103| r103_20(int) = Add : r103_18, r103_19
1575+
# 103| r103_21(glval<ClassWithDestructor2>) = CopyValue : r103_1
1576+
# 103| r103_22(glval<unknown>) = FunctionAddress[~ClassWithDestructor2] :
1577+
# 103| v103_23(void) = Call[~ClassWithDestructor2] : func:r103_22, this:r103_21
1578+
# 103| m103_24(unknown) = ^CallSideEffect : ~m103_14
1579+
# 103| m103_25(unknown) = Chi : total:m103_14, partial:m103_24
1580+
# 103| v103_26(void) = ^IndirectReadSideEffect[-1] : &:r103_21, m103_17
1581+
# 103| m103_27(ClassWithDestructor2) = ^IndirectMayWriteSideEffect[-1] : &:r103_21
1582+
# 103| m103_28(ClassWithDestructor2) = Chi : total:m103_17, partial:m103_27
1583+
# 104| v104_1(void) = NoOp :
1584+
# 102| v102_7(void) = ReturnVoid :
1585+
# 102| v102_8(void) = AliasedUse : ~m103_25
1586+
# 102| v102_9(void) = ExitFunction :
1587+
15471588
ir.c:
15481589
# 7| void MyCoordsTest(int)
15491590
# 7| Block 0

cpp/ql/test/library-tests/ir/ir/destructors_for_temps.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,8 @@ void temp_test11() {
9797
// First, ~ClassWithDestructor2::ClassWithDestructor2(), and then the call
9898
// to `~ClassWithDestructor3::ClassWithDestructor3()`.
9999
makeClassWithDestructor3().getClassWithDestructor2();
100+
}
101+
102+
void temp_test12(ClassWithDestructor3 x) {
103+
x.getClassWithDestructor2().get_x() + 5;
100104
}

cpp/ql/test/library-tests/ir/ir/operand_locations.expected

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1375,6 +1375,46 @@
13751375
| destructors_for_temps.cpp:99:32:99:54 | ChiTotal | total:m99_6 |
13761376
| destructors_for_temps.cpp:99:32:99:54 | SideEffect | ~m99_6 |
13771377
| destructors_for_temps.cpp:99:32:99:54 | StoreValue | r99_9 |
1378+
| destructors_for_temps.cpp:102:6:102:16 | ChiPartial | partial:m102_3 |
1379+
| destructors_for_temps.cpp:102:6:102:16 | ChiTotal | total:m102_2 |
1380+
| destructors_for_temps.cpp:102:6:102:16 | SideEffect | ~m103_25 |
1381+
| destructors_for_temps.cpp:102:39:102:39 | Address | &:r102_5 |
1382+
| destructors_for_temps.cpp:103:5:103:5 | Address | &:r103_2 |
1383+
| destructors_for_temps.cpp:103:5:103:5 | Address | &:r103_2 |
1384+
| destructors_for_temps.cpp:103:5:103:5 | Arg(this) | this:r103_2 |
1385+
| destructors_for_temps.cpp:103:5:103:5 | ChiPartial | partial:m103_8 |
1386+
| destructors_for_temps.cpp:103:5:103:5 | ChiTotal | total:m102_6 |
1387+
| destructors_for_temps.cpp:103:5:103:5 | SideEffect | m102_6 |
1388+
| destructors_for_temps.cpp:103:5:103:31 | Address | &:r103_1 |
1389+
| destructors_for_temps.cpp:103:5:103:31 | Address | &:r103_1 |
1390+
| destructors_for_temps.cpp:103:5:103:31 | Address | &:r103_1 |
1391+
| destructors_for_temps.cpp:103:5:103:31 | Address | &:r103_21 |
1392+
| destructors_for_temps.cpp:103:5:103:31 | Address | &:r103_21 |
1393+
| destructors_for_temps.cpp:103:5:103:31 | Arg(this) | this:r103_1 |
1394+
| destructors_for_temps.cpp:103:5:103:31 | Arg(this) | this:r103_21 |
1395+
| destructors_for_temps.cpp:103:5:103:31 | CallTarget | func:r103_22 |
1396+
| destructors_for_temps.cpp:103:5:103:31 | ChiPartial | partial:m103_16 |
1397+
| destructors_for_temps.cpp:103:5:103:31 | ChiPartial | partial:m103_24 |
1398+
| destructors_for_temps.cpp:103:5:103:31 | ChiPartial | partial:m103_27 |
1399+
| destructors_for_temps.cpp:103:5:103:31 | ChiTotal | total:m103_10 |
1400+
| destructors_for_temps.cpp:103:5:103:31 | ChiTotal | total:m103_14 |
1401+
| destructors_for_temps.cpp:103:5:103:31 | ChiTotal | total:m103_17 |
1402+
| destructors_for_temps.cpp:103:5:103:31 | SideEffect | m103_10 |
1403+
| destructors_for_temps.cpp:103:5:103:31 | SideEffect | m103_17 |
1404+
| destructors_for_temps.cpp:103:5:103:31 | SideEffect | ~m103_14 |
1405+
| destructors_for_temps.cpp:103:5:103:31 | Unary | r103_1 |
1406+
| destructors_for_temps.cpp:103:5:103:39 | Left | r103_18 |
1407+
| destructors_for_temps.cpp:103:7:103:29 | CallTarget | func:r103_3 |
1408+
| destructors_for_temps.cpp:103:7:103:29 | ChiPartial | partial:m103_5 |
1409+
| destructors_for_temps.cpp:103:7:103:29 | ChiTotal | total:m102_4 |
1410+
| destructors_for_temps.cpp:103:7:103:29 | SideEffect | ~m102_4 |
1411+
| destructors_for_temps.cpp:103:7:103:29 | StoreValue | r103_4 |
1412+
| destructors_for_temps.cpp:103:33:103:37 | CallTarget | func:r103_11 |
1413+
| destructors_for_temps.cpp:103:33:103:37 | ChiPartial | partial:m103_13 |
1414+
| destructors_for_temps.cpp:103:33:103:37 | ChiTotal | total:m103_6 |
1415+
| destructors_for_temps.cpp:103:33:103:37 | SideEffect | ~m103_6 |
1416+
| destructors_for_temps.cpp:103:33:103:37 | Unary | r103_12 |
1417+
| destructors_for_temps.cpp:103:43:103:43 | Right | r103_19 |
13781418
| file://:0:0:0:0 | Address | &:r0_1 |
13791419
| file://:0:0:0:0 | Address | &:r0_1 |
13801420
| file://:0:0:0:0 | Address | &:r0_1 |

cpp/ql/test/library-tests/ir/ir/raw_ir.expected

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1399,6 +1399,40 @@ destructors_for_temps.cpp:
13991399
# 94| v94_5(void) = AliasedUse : ~m?
14001400
# 94| v94_6(void) = ExitFunction :
14011401

1402+
# 102| void temp_test12(ClassWithDestructor3)
1403+
# 102| Block 0
1404+
# 102| v102_1(void) = EnterFunction :
1405+
# 102| mu102_2(unknown) = AliasedDefinition :
1406+
# 102| mu102_3(unknown) = InitializeNonLocal :
1407+
# 102| r102_4(glval<ClassWithDestructor3>) = VariableAddress[x] :
1408+
# 102| mu102_5(ClassWithDestructor3) = InitializeParameter[x] : &:r102_4
1409+
# 103| r103_1(glval<ClassWithDestructor2>) = VariableAddress[#temp103:5] :
1410+
# 103| r103_2(glval<ClassWithDestructor3>) = VariableAddress[x] :
1411+
# 103| r103_3(glval<unknown>) = FunctionAddress[getClassWithDestructor2] :
1412+
# 103| r103_4(ClassWithDestructor2) = Call[getClassWithDestructor2] : func:r103_3, this:r103_2
1413+
# 103| mu103_5(unknown) = ^CallSideEffect : ~m?
1414+
# 103| v103_6(void) = ^IndirectReadSideEffect[-1] : &:r103_2, ~m?
1415+
# 103| mu103_7(ClassWithDestructor3) = ^IndirectMayWriteSideEffect[-1] : &:r103_2
1416+
# 103| mu103_8(ClassWithDestructor2) = Store[#temp103:5] : &:r103_1, r103_4
1417+
# 103| r103_9(glval<unknown>) = FunctionAddress[get_x] :
1418+
# 103| r103_10(char) = Call[get_x] : func:r103_9, this:r103_1
1419+
# 103| mu103_11(unknown) = ^CallSideEffect : ~m?
1420+
# 103| v103_12(void) = ^IndirectReadSideEffect[-1] : &:r103_1, ~m?
1421+
# 103| mu103_13(ClassWithDestructor2) = ^IndirectMayWriteSideEffect[-1] : &:r103_1
1422+
# 103| r103_14(int) = Convert : r103_10
1423+
# 103| r103_15(int) = Constant[5] :
1424+
# 103| r103_16(int) = Add : r103_14, r103_15
1425+
# 103| r103_17(glval<ClassWithDestructor2>) = CopyValue : r103_1
1426+
# 103| r103_18(glval<unknown>) = FunctionAddress[~ClassWithDestructor2] :
1427+
# 103| v103_19(void) = Call[~ClassWithDestructor2] : func:r103_18, this:r103_17
1428+
# 103| mu103_20(unknown) = ^CallSideEffect : ~m?
1429+
# 103| v103_21(void) = ^IndirectReadSideEffect[-1] : &:r103_17, ~m?
1430+
# 103| mu103_22(ClassWithDestructor2) = ^IndirectMayWriteSideEffect[-1] : &:r103_17
1431+
# 104| v104_1(void) = NoOp :
1432+
# 102| v102_6(void) = ReturnVoid :
1433+
# 102| v102_7(void) = AliasedUse : ~m?
1434+
# 102| v102_8(void) = ExitFunction :
1435+
14021436
ir.c:
14031437
# 7| void MyCoordsTest(int)
14041438
# 7| Block 0

0 commit comments

Comments
 (0)