Skip to content

Commit e63a607

Browse files
committed
C++: Add another test with conditional construction.
1 parent b6ddb97 commit e63a607

10 files changed

+276
-0
lines changed

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

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2221,6 +2221,61 @@ destructors_for_temps.cpp:
22212221
# 59| Type = [Class] ClassWithDestructor2
22222222
# 59| ValueCategory = xvalue
22232223
# 60| getStmt(1): [ReturnStmt] return ...
2224+
# 62| [CopyAssignmentOperator] string& string::operator=(string const&)
2225+
# 62| <params>:
2226+
#-----| getParameter(0): [Parameter] (unnamed parameter 0)
2227+
#-----| Type = [LValueReferenceType] const string &
2228+
# 62| [CopyConstructor] void string::string(string const&)
2229+
# 62| <params>:
2230+
#-----| getParameter(0): [Parameter] (unnamed parameter 0)
2231+
#-----| Type = [LValueReferenceType] const string &
2232+
# 64| [Constructor] void string::string(char const*)
2233+
# 64| <params>:
2234+
# 64| getParameter(0): [Parameter] (unnamed parameter 0)
2235+
# 64| Type = [PointerType] const char *
2236+
# 65| [Destructor] void string::~string()
2237+
# 65| <params>:
2238+
# 68| [TopLevelFunction] bool const_ref_string(string const&)
2239+
# 68| <params>:
2240+
# 68| getParameter(0): [Parameter] (unnamed parameter 0)
2241+
# 68| Type = [LValueReferenceType] const string &
2242+
# 70| [TopLevelFunction] bool conditional_temp_via_conjunction(bool)
2243+
# 70| <params>:
2244+
# 70| getParameter(0): [Parameter] b
2245+
# 70| Type = [BoolType] bool
2246+
# 71| getEntryPoint(): [BlockStmt] { ... }
2247+
# 72| getStmt(0): [ReturnStmt] return ...
2248+
# 72| getExpr(): [LogicalAndExpr] ... && ...
2249+
# 72| Type = [BoolType] bool
2250+
# 72| ValueCategory = prvalue
2251+
# 72| getLeftOperand(): [VariableAccess] b
2252+
# 72| Type = [BoolType] bool
2253+
# 72| ValueCategory = prvalue(load)
2254+
# 72| getRightOperand(): [FunctionCall] call to const_ref_string
2255+
# 72| Type = [BoolType] bool
2256+
# 72| ValueCategory = prvalue
2257+
# 72| getArgument(0): [ConstructorCall] call to string
2258+
# 72| Type = [VoidType] void
2259+
# 72| ValueCategory = prvalue
2260+
# 72| getArgument(0):
2261+
# 72| Type = [ArrayType] const char[1]
2262+
# 72| Value = [StringLiteral] ""
2263+
# 72| ValueCategory = lvalue
2264+
# 72| getArgument(0).getFullyConverted(): [ArrayToPointerConversion] array to pointer conversion
2265+
# 72| Type = [PointerType] const char *
2266+
# 72| ValueCategory = prvalue
2267+
# 72| getArgument(0).getFullyConverted(): [ReferenceToExpr] (reference to)
2268+
# 72| Type = [LValueReferenceType] const string &
2269+
# 72| ValueCategory = prvalue
2270+
# 72| getExpr(): [TemporaryObjectExpr] temporary object
2271+
# 72| Type = [SpecifiedType] const string
2272+
# 72| ValueCategory = lvalue
2273+
# 72| getImplicitDestructorCall(0): [DestructorCall] call to ~string
2274+
# 72| Type = [VoidType] void
2275+
# 72| ValueCategory = prvalue
2276+
# 72| getQualifier(): [ReuseExpr] reuse of temporary object
2277+
# 72| Type = [SpecifiedType] const string
2278+
# 72| ValueCategory = xvalue
22242279
ir.c:
22252280
# 5| [TopLevelFunction] int getX(MyCoords*)
22262281
# 5| <params>:

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

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1373,6 +1373,77 @@ destructors_for_temps.cpp:
13731373
# 58| v58_11(void) = ReturnVoid :
13741374
#-----| Goto -> Block 1
13751375

1376+
# 70| bool conditional_temp_via_conjunction(bool)
1377+
# 70| Block 0
1378+
# 70| v70_1(void) = EnterFunction :
1379+
# 70| m70_2(unknown) = AliasedDefinition :
1380+
# 70| m70_3(unknown) = InitializeNonLocal :
1381+
# 70| m70_4(unknown) = Chi : total:m70_2, partial:m70_3
1382+
# 70| r70_5(glval<bool>) = VariableAddress[b] :
1383+
# 70| m70_6(bool) = InitializeParameter[b] : &:r70_5
1384+
# 72| r72_1(glval<bool>) = VariableAddress[#return] :
1385+
# 72| r72_2(glval<bool>) = VariableAddress[b] :
1386+
# 72| r72_3(bool) = Load[b] : &:r72_2, m70_6
1387+
# 72| v72_4(void) = ConditionalBranch : r72_3
1388+
#-----| False -> Block 1
1389+
#-----| True -> Block 4
1390+
1391+
# 72| Block 1
1392+
# 72| m72_5(string) = Phi : from 4:m72_38
1393+
# 72| m72_6(unknown) = Phi : from 0:~m70_4, from 4:~m72_42
1394+
# 72| r72_7(glval<bool>) = VariableAddress[#temp72:12] :
1395+
# 72| r72_8(bool) = Constant[0] :
1396+
# 72| m72_9(bool) = Store[#temp72:12] : &:r72_7, r72_8
1397+
#-----| Goto -> Block 2
1398+
1399+
# 72| Block 2
1400+
# 72| m72_10(string) = Phi : from 1:m72_5, from 3:m72_38
1401+
# 72| m72_11(unknown) = Phi : from 1:~m72_6, from 3:~m72_42
1402+
# 72| m72_12(bool) = Phi : from 1:m72_9, from 3:m72_26
1403+
# 72| r72_13(glval<bool>) = VariableAddress[#temp72:12] :
1404+
# 72| r72_14(bool) = Load[#temp72:12] : &:r72_13, m72_12
1405+
# 72| r72_15(glval<string>) = CopyValue : r72_28
1406+
# 72| r72_16(glval<unknown>) = FunctionAddress[~string] :
1407+
# 72| v72_17(void) = Call[~string] : func:r72_16, this:r72_15
1408+
# 72| m72_18(unknown) = ^CallSideEffect : ~m72_11
1409+
# 72| m72_19(unknown) = Chi : total:m72_11, partial:m72_18
1410+
# 72| v72_20(void) = ^IndirectReadSideEffect[-1] : &:r72_15, m72_10
1411+
# 72| m72_21(string) = ^IndirectMayWriteSideEffect[-1] : &:r72_15
1412+
# 72| m72_22(string) = Chi : total:m72_10, partial:m72_21
1413+
# 72| m72_23(bool) = Store[#return] : &:r72_1, r72_14
1414+
# 70| r70_7(glval<bool>) = VariableAddress[#return] :
1415+
# 70| v70_8(void) = ReturnValue : &:r70_7, m72_23
1416+
# 70| v70_9(void) = AliasedUse : ~m72_19
1417+
# 70| v70_10(void) = ExitFunction :
1418+
1419+
# 72| Block 3
1420+
# 72| r72_24(glval<bool>) = VariableAddress[#temp72:12] :
1421+
# 72| r72_25(bool) = Constant[1] :
1422+
# 72| m72_26(bool) = Store[#temp72:12] : &:r72_24, r72_25
1423+
#-----| Goto -> Block 2
1424+
1425+
# 72| Block 4
1426+
# 72| r72_27(glval<unknown>) = FunctionAddress[const_ref_string] :
1427+
# 72| r72_28(glval<string>) = VariableAddress[#temp72:34] :
1428+
# 72| m72_29(string) = Uninitialized[#temp72:34] : &:r72_28
1429+
# 72| r72_30(glval<unknown>) = FunctionAddress[string] :
1430+
# 72| r72_31(glval<char[1]>) = StringConstant[""] :
1431+
# 72| r72_32(char *) = Convert : r72_31
1432+
# 72| v72_33(void) = Call[string] : func:r72_30, this:r72_28, 0:r72_32
1433+
# 72| m72_34(unknown) = ^CallSideEffect : ~m70_4
1434+
# 72| m72_35(unknown) = Chi : total:m70_4, partial:m72_34
1435+
# 72| v72_36(void) = ^BufferReadSideEffect[0] : &:r72_32, ~m70_3
1436+
# 72| m72_37(string) = ^IndirectMayWriteSideEffect[-1] : &:r72_28
1437+
# 72| m72_38(string) = Chi : total:m72_29, partial:m72_37
1438+
# 72| r72_39(string &) = CopyValue : r72_28
1439+
# 72| r72_40(bool) = Call[const_ref_string] : func:r72_27, 0:r72_39
1440+
# 72| m72_41(unknown) = ^CallSideEffect : ~m72_35
1441+
# 72| m72_42(unknown) = Chi : total:m72_35, partial:m72_41
1442+
# 72| v72_43(void) = ^BufferReadSideEffect[0] : &:r72_39, ~m72_38
1443+
# 72| v72_44(void) = ConditionalBranch : r72_40
1444+
#-----| False -> Block 1
1445+
#-----| True -> Block 3
1446+
13761447
ir.c:
13771448
# 7| void MyCoordsTest(int)
13781449
# 7| Block 0

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ multipleIRTypes
2020
lostReachability
2121
backEdgeCountMismatch
2222
useNotDominatedByDefinition
23+
| destructors_for_temps.cpp:72:34:72:35 | Unary | Operand 'Unary' is not dominated by its definition in function '$@'. | destructors_for_temps.cpp:70:6:70:37 | bool conditional_temp_via_conjunction(bool) | bool conditional_temp_via_conjunction(bool) |
2324
switchInstructionWithoutDefaultEdge
2425
notMarkedAsConflated
2526
wronglyMarkedAsConflated

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ missingOperand
22
unexpectedOperand
33
duplicateOperand
44
missingPhiOperand
5+
| destructors_for_temps.cpp:72:12:72:36 | Phi: ... && ... | Instruction 'Phi: ... && ...' is missing an operand for predecessor block 'EnterFunction: conditional_temp_via_conjunction' in function '$@'. | destructors_for_temps.cpp:70:6:70:37 | bool conditional_temp_via_conjunction(bool) | bool conditional_temp_via_conjunction(bool) |
56
missingOperandType
67
| destructors_for_temps.cpp:39:3:39:53 | ChiTotal | Operand 'ChiTotal' of instruction 'Chi' is missing a type in function '$@'. | destructors_for_temps.cpp:38:6:38:15 | void temp_test5(bool) | void temp_test5(bool) |
78
| ir.cpp:1425:5:1425:30 | ChiTotal | Operand 'ChiTotal' of instruction 'Chi' is missing a type in function '$@'. | ir.cpp:1414:6:1414:21 | void temporary_string() | void temporary_string() |
@@ -23,6 +24,7 @@ multipleIRTypes
2324
lostReachability
2425
backEdgeCountMismatch
2526
useNotDominatedByDefinition
27+
| destructors_for_temps.cpp:72:34:72:35 | Unary | Operand 'Unary' is not dominated by its definition in function '$@'. | destructors_for_temps.cpp:70:6:70:37 | bool conditional_temp_via_conjunction(bool) | bool conditional_temp_via_conjunction(bool) |
2628
switchInstructionWithoutDefaultEdge
2729
notMarkedAsConflated
2830
wronglyMarkedAsConflated

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,17 @@ void temp_test8(bool b) {
5757

5858
void temp_test8_simple(bool b) {
5959
b ? throw ClassWithDestructor2().get_x() : 'a';
60+
}
61+
62+
struct string
63+
{
64+
string(const char *);
65+
~string();
66+
};
67+
68+
bool const_ref_string(const string &);
69+
70+
bool conditional_temp_via_conjunction(bool b)
71+
{
72+
return b && const_ref_string("");
6073
}

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

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,6 +1239,65 @@
12391239
| destructors_for_temps.cpp:59:38:59:42 | SideEffect | ~m59_10 |
12401240
| destructors_for_temps.cpp:59:38:59:42 | StoreValue | r59_14 |
12411241
| destructors_for_temps.cpp:59:48:59:50 | StoreValue | r59_22 |
1242+
| destructors_for_temps.cpp:70:6:70:37 | Address | &:r70_7 |
1243+
| destructors_for_temps.cpp:70:6:70:37 | ChiPartial | partial:m70_3 |
1244+
| destructors_for_temps.cpp:70:6:70:37 | ChiTotal | total:m70_2 |
1245+
| destructors_for_temps.cpp:70:6:70:37 | Load | m72_23 |
1246+
| destructors_for_temps.cpp:70:6:70:37 | SideEffect | ~m72_19 |
1247+
| destructors_for_temps.cpp:70:44:70:44 | Address | &:r70_5 |
1248+
| destructors_for_temps.cpp:72:5:72:37 | Address | &:r72_1 |
1249+
| destructors_for_temps.cpp:72:12:72:12 | Address | &:r72_2 |
1250+
| destructors_for_temps.cpp:72:12:72:12 | Condition | r72_3 |
1251+
| destructors_for_temps.cpp:72:12:72:12 | Load | m70_6 |
1252+
| destructors_for_temps.cpp:72:12:72:36 | Address | &:r72_7 |
1253+
| destructors_for_temps.cpp:72:12:72:36 | Address | &:r72_13 |
1254+
| destructors_for_temps.cpp:72:12:72:36 | Address | &:r72_24 |
1255+
| destructors_for_temps.cpp:72:12:72:36 | Load | m72_12 |
1256+
| destructors_for_temps.cpp:72:12:72:36 | Phi | from 0:~m70_4 |
1257+
| destructors_for_temps.cpp:72:12:72:36 | Phi | from 1:m72_5 |
1258+
| destructors_for_temps.cpp:72:12:72:36 | Phi | from 1:m72_9 |
1259+
| destructors_for_temps.cpp:72:12:72:36 | Phi | from 1:~m72_6 |
1260+
| destructors_for_temps.cpp:72:12:72:36 | Phi | from 3:m72_26 |
1261+
| destructors_for_temps.cpp:72:12:72:36 | Phi | from 3:m72_38 |
1262+
| destructors_for_temps.cpp:72:12:72:36 | Phi | from 3:~m72_42 |
1263+
| destructors_for_temps.cpp:72:12:72:36 | Phi | from 4:m72_38 |
1264+
| destructors_for_temps.cpp:72:12:72:36 | Phi | from 4:~m72_42 |
1265+
| destructors_for_temps.cpp:72:12:72:36 | StoreValue | r72_8 |
1266+
| destructors_for_temps.cpp:72:12:72:36 | StoreValue | r72_14 |
1267+
| destructors_for_temps.cpp:72:12:72:36 | StoreValue | r72_25 |
1268+
| destructors_for_temps.cpp:72:17:72:32 | CallTarget | func:r72_27 |
1269+
| destructors_for_temps.cpp:72:17:72:32 | ChiPartial | partial:m72_41 |
1270+
| destructors_for_temps.cpp:72:17:72:32 | ChiTotal | total:m72_35 |
1271+
| destructors_for_temps.cpp:72:17:72:32 | Condition | r72_40 |
1272+
| destructors_for_temps.cpp:72:17:72:32 | SideEffect | ~m72_35 |
1273+
| destructors_for_temps.cpp:72:34:72:35 | Address | &:r72_15 |
1274+
| destructors_for_temps.cpp:72:34:72:35 | Address | &:r72_15 |
1275+
| destructors_for_temps.cpp:72:34:72:35 | Address | &:r72_28 |
1276+
| destructors_for_temps.cpp:72:34:72:35 | Address | &:r72_28 |
1277+
| destructors_for_temps.cpp:72:34:72:35 | Address | &:r72_32 |
1278+
| destructors_for_temps.cpp:72:34:72:35 | Address | &:r72_39 |
1279+
| destructors_for_temps.cpp:72:34:72:35 | Arg(0) | 0:r72_32 |
1280+
| destructors_for_temps.cpp:72:34:72:35 | Arg(0) | 0:r72_39 |
1281+
| destructors_for_temps.cpp:72:34:72:35 | Arg(this) | this:r72_15 |
1282+
| destructors_for_temps.cpp:72:34:72:35 | Arg(this) | this:r72_28 |
1283+
| destructors_for_temps.cpp:72:34:72:35 | CallTarget | func:r72_16 |
1284+
| destructors_for_temps.cpp:72:34:72:35 | CallTarget | func:r72_30 |
1285+
| destructors_for_temps.cpp:72:34:72:35 | ChiPartial | partial:m72_18 |
1286+
| destructors_for_temps.cpp:72:34:72:35 | ChiPartial | partial:m72_21 |
1287+
| destructors_for_temps.cpp:72:34:72:35 | ChiPartial | partial:m72_34 |
1288+
| destructors_for_temps.cpp:72:34:72:35 | ChiPartial | partial:m72_37 |
1289+
| destructors_for_temps.cpp:72:34:72:35 | ChiTotal | total:m70_4 |
1290+
| destructors_for_temps.cpp:72:34:72:35 | ChiTotal | total:m72_10 |
1291+
| destructors_for_temps.cpp:72:34:72:35 | ChiTotal | total:m72_11 |
1292+
| destructors_for_temps.cpp:72:34:72:35 | ChiTotal | total:m72_29 |
1293+
| destructors_for_temps.cpp:72:34:72:35 | SideEffect | m72_10 |
1294+
| destructors_for_temps.cpp:72:34:72:35 | SideEffect | ~m70_3 |
1295+
| destructors_for_temps.cpp:72:34:72:35 | SideEffect | ~m70_4 |
1296+
| destructors_for_temps.cpp:72:34:72:35 | SideEffect | ~m72_11 |
1297+
| destructors_for_temps.cpp:72:34:72:35 | SideEffect | ~m72_38 |
1298+
| destructors_for_temps.cpp:72:34:72:35 | Unary | r72_28 |
1299+
| destructors_for_temps.cpp:72:34:72:35 | Unary | r72_28 |
1300+
| destructors_for_temps.cpp:72:34:72:35 | Unary | r72_31 |
12421301
| file://:0:0:0:0 | Address | &:r0_1 |
12431302
| file://:0:0:0:0 | Address | &:r0_1 |
12441303
| file://:0:0:0:0 | Address | &:r0_1 |

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ multipleIRTypes
2020
lostReachability
2121
backEdgeCountMismatch
2222
useNotDominatedByDefinition
23+
| destructors_for_temps.cpp:72:34:72:35 | Unary | Operand 'Unary' is not dominated by its definition in function '$@'. | destructors_for_temps.cpp:70:6:70:37 | bool conditional_temp_via_conjunction(bool) | bool conditional_temp_via_conjunction(bool) |
2324
| ir.cpp:1535:8:1535:8 | Unary | Operand 'Unary' is not dominated by its definition in function '$@'. | ir.cpp:1535:8:1535:8 | void StructuredBindingDataMemberStruct::StructuredBindingDataMemberStruct() | void StructuredBindingDataMemberStruct::StructuredBindingDataMemberStruct() |
2425
| try_except.c:13:13:13:13 | Left | Operand 'Left' is not dominated by its definition in function '$@'. | try_except.c:6:6:6:6 | void f() | void f() |
2526
| try_except.c:13:13:13:13 | Left | Operand 'Left' is not dominated by its definition in function '$@'. | try_except.c:6:6:6:6 | void f() | void f() |

0 commit comments

Comments
 (0)