Skip to content

Commit a0de95d

Browse files
committed
C++: Add testcases that produces an 'missingOperandType' and 'missingPhiOperand' consistency errors.
1 parent 45e7154 commit a0de95d

File tree

6 files changed

+241
-0
lines changed

6 files changed

+241
-0
lines changed

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

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2276,6 +2276,56 @@ destructors_for_temps.cpp:
22762276
# 72| getQualifier(): [ReuseExpr] reuse of temporary object
22772277
# 72| Type = [SpecifiedType] const string
22782278
# 72| ValueCategory = xvalue
2279+
# 75| [TopLevelFunction] ClassWithDestructor2 make()
2280+
# 75| <params>:
2281+
# 77| [TopLevelFunction] void temp_test9()
2282+
# 77| <params>:
2283+
# 77| getEntryPoint(): [BlockStmt] { ... }
2284+
# 78| getStmt(0): [ExprStmt] ExprStmt
2285+
# 78| getExpr(): [FunctionCall] call to make
2286+
# 78| Type = [Class] ClassWithDestructor2
2287+
# 78| ValueCategory = prvalue
2288+
# 78| getImplicitDestructorCall(0): [DestructorCall] call to ~ClassWithDestructor2
2289+
# 78| Type = [VoidType] void
2290+
# 78| ValueCategory = prvalue
2291+
# 78| getQualifier(): [ReuseExpr] reuse of temporary object
2292+
# 78| Type = [Class] ClassWithDestructor2
2293+
# 78| ValueCategory = xvalue
2294+
# 78| getExpr().getFullyConverted(): [TemporaryObjectExpr] temporary object
2295+
# 78| Type = [Class] ClassWithDestructor2
2296+
# 78| ValueCategory = prvalue
2297+
# 79| getStmt(1): [ReturnStmt] return ...
2298+
# 81| [TopLevelFunction] void temp_test10(int)
2299+
# 81| <params>:
2300+
# 81| getParameter(0): [Parameter] i
2301+
# 81| Type = [IntType] int
2302+
# 81| getEntryPoint(): [BlockStmt] { ... }
2303+
# 82| getStmt(0): [WhileStmt] while (...) ...
2304+
# 82| getCondition(): [LTExpr] ... < ...
2305+
# 82| Type = [BoolType] bool
2306+
# 82| ValueCategory = prvalue
2307+
# 82| getLesserOperand(): [VariableAccess] i
2308+
# 82| Type = [IntType] int
2309+
# 82| ValueCategory = prvalue(load)
2310+
# 82| getGreaterOperand(): [Literal] 10
2311+
# 82| Type = [IntType] int
2312+
# 82| Value = [Literal] 10
2313+
# 82| ValueCategory = prvalue
2314+
# 82| getStmt(): [BlockStmt] { ... }
2315+
# 83| getStmt(0): [ExprStmt] ExprStmt
2316+
# 83| getExpr(): [FunctionCall] call to make
2317+
# 83| Type = [Class] ClassWithDestructor2
2318+
# 83| ValueCategory = prvalue
2319+
# 83| getImplicitDestructorCall(0): [DestructorCall] call to ~ClassWithDestructor2
2320+
# 83| Type = [VoidType] void
2321+
# 83| ValueCategory = prvalue
2322+
# 83| getQualifier(): [ReuseExpr] reuse of temporary object
2323+
# 83| Type = [Class] ClassWithDestructor2
2324+
# 83| ValueCategory = xvalue
2325+
# 83| getExpr().getFullyConverted(): [TemporaryObjectExpr] temporary object
2326+
# 83| Type = [Class] ClassWithDestructor2
2327+
# 83| ValueCategory = prvalue
2328+
# 85| getStmt(1): [ReturnStmt] return ...
22792329
ir.c:
22802330
# 5| [TopLevelFunction] int getX(MyCoords*)
22812331
# 5| <params>:

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

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,6 +1434,75 @@ destructors_for_temps.cpp:
14341434
#-----| False -> Block 1
14351435
#-----| True -> Block 3
14361436

1437+
# 77| void temp_test9()
1438+
# 77| Block 0
1439+
# 77| v77_1(void) = EnterFunction :
1440+
# 77| m77_2(unknown) = AliasedDefinition :
1441+
# 77| m77_3(unknown) = InitializeNonLocal :
1442+
# 77| m77_4(unknown) = Chi : total:m77_2, partial:m77_3
1443+
# 78| r78_1(glval<ClassWithDestructor2>) = VariableAddress[#temp78:5] :
1444+
# 78| r78_2(glval<unknown>) = FunctionAddress[make] :
1445+
# 78| r78_3(ClassWithDestructor2) = Call[make] : func:r78_2
1446+
# 78| m78_4(unknown) = ^CallSideEffect : ~m77_4
1447+
# 78| m78_5(unknown) = Chi : total:m77_4, partial:m78_4
1448+
# 78| r78_6(glval<ClassWithDestructor2>) = CopyValue : r78_1
1449+
# 78| r78_7(glval<unknown>) = FunctionAddress[~ClassWithDestructor2] :
1450+
# 78| v78_8(void) = Call[~ClassWithDestructor2] : func:r78_7, this:r78_6
1451+
# 78| m78_9(unknown) = ^CallSideEffect : ~m78_5
1452+
# 78| m78_10(unknown) = Chi : total:m78_5, partial:m78_9
1453+
# 78| v78_11(void) = ^IndirectReadSideEffect[-1] : &:r78_6, ~m?
1454+
# 78| m78_12(ClassWithDestructor2) = ^IndirectMayWriteSideEffect[-1] : &:r78_6
1455+
# 78| m78_13(ClassWithDestructor2) = Chi : total:~m?, partial:m78_12
1456+
# 78| m78_14(ClassWithDestructor2) = Store[#temp78:5] : &:r78_1, r78_3
1457+
# 79| v79_1(void) = NoOp :
1458+
# 77| v77_5(void) = ReturnVoid :
1459+
# 77| v77_6(void) = AliasedUse : ~m78_10
1460+
# 77| v77_7(void) = ExitFunction :
1461+
1462+
# 81| void temp_test10(int)
1463+
# 81| Block 0
1464+
# 81| v81_1(void) = EnterFunction :
1465+
# 81| m81_2(unknown) = AliasedDefinition :
1466+
# 81| m81_3(unknown) = InitializeNonLocal :
1467+
# 81| m81_4(unknown) = Chi : total:m81_2, partial:m81_3
1468+
# 81| r81_5(glval<int>) = VariableAddress[i] :
1469+
# 81| m81_6(int) = InitializeParameter[i] : &:r81_5
1470+
#-----| Goto -> Block 1
1471+
1472+
# 82| Block 1
1473+
# 82| m82_1(ClassWithDestructor2) = Phi : from 2:m83_14
1474+
# 82| m82_2(unknown) = Phi : from 0:~m81_4, from 2:~m83_10
1475+
# 82| r82_3(glval<int>) = VariableAddress[i] :
1476+
# 82| r82_4(int) = Load[i] : &:r82_3, m81_6
1477+
# 82| r82_5(int) = Constant[10] :
1478+
# 82| r82_6(bool) = CompareLT : r82_4, r82_5
1479+
# 82| v82_7(void) = ConditionalBranch : r82_6
1480+
#-----| False -> Block 3
1481+
#-----| True -> Block 2
1482+
1483+
# 83| Block 2
1484+
# 83| r83_1(glval<ClassWithDestructor2>) = VariableAddress[#temp83:9] :
1485+
# 83| r83_2(glval<unknown>) = FunctionAddress[make] :
1486+
# 83| r83_3(ClassWithDestructor2) = Call[make] : func:r83_2
1487+
# 83| m83_4(unknown) = ^CallSideEffect : ~m82_2
1488+
# 83| m83_5(unknown) = Chi : total:m82_2, partial:m83_4
1489+
# 83| r83_6(glval<ClassWithDestructor2>) = CopyValue : r83_1
1490+
# 83| r83_7(glval<unknown>) = FunctionAddress[~ClassWithDestructor2] :
1491+
# 83| v83_8(void) = Call[~ClassWithDestructor2] : func:r83_7, this:r83_6
1492+
# 83| m83_9(unknown) = ^CallSideEffect : ~m83_5
1493+
# 83| m83_10(unknown) = Chi : total:m83_5, partial:m83_9
1494+
# 83| v83_11(void) = ^IndirectReadSideEffect[-1] : &:r83_6, m82_1
1495+
# 83| m83_12(ClassWithDestructor2) = ^IndirectMayWriteSideEffect[-1] : &:r83_6
1496+
# 83| m83_13(ClassWithDestructor2) = Chi : total:m82_1, partial:m83_12
1497+
# 83| m83_14(ClassWithDestructor2) = Store[#temp83:9] : &:r83_1, r83_3
1498+
#-----| Goto (back edge) -> Block 1
1499+
1500+
# 85| Block 3
1501+
# 85| v85_1(void) = NoOp :
1502+
# 81| v81_7(void) = ReturnVoid :
1503+
# 81| v81_8(void) = AliasedUse : ~m82_2
1504+
# 81| v81_9(void) = ExitFunction :
1505+
14371506
ir.c:
14381507
# 7| void MyCoordsTest(int)
14391508
# 7| Block 0

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,8 +2,10 @@ missingOperand
22
unexpectedOperand
33
duplicateOperand
44
missingPhiOperand
5+
| destructors_for_temps.cpp:82:11:82:11 | Phi: i | Instruction 'Phi: i' is missing an operand for predecessor block 'EnterFunction: temp_test10' in function '$@'. | destructors_for_temps.cpp:81:6:81:16 | void temp_test10(int) | void temp_test10(int) |
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) |
8+
| destructors_for_temps.cpp:78:5:78:10 | ChiTotal | Operand 'ChiTotal' of instruction 'Chi' is missing a type in function '$@'. | destructors_for_temps.cpp:77:6:77:15 | void temp_test9() | void temp_test9() |
79
| 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() |
810
| ir.cpp:1437:5:1437:39 | ChiTotal | Operand 'ChiTotal' of instruction 'Chi' is missing a type in function '$@'. | ir.cpp:1428:6:1428:30 | void temporary_destructor_only() | void temporary_destructor_only() |
911
duplicateChiOperand

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,16 @@ bool const_ref_string(const string &);
7070
bool conditional_temp_via_conjunction(bool b)
7171
{
7272
return b && const_ref_string("");
73+
}
74+
75+
ClassWithDestructor2 make();
76+
77+
void temp_test9() {
78+
make();
79+
}
80+
81+
void temp_test10(int i) {
82+
while(i < 10) {
83+
make();
84+
}
7385
}

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

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,6 +1284,55 @@
12841284
| destructors_for_temps.cpp:72:34:72:35 | SideEffect | ~m72_28 |
12851285
| destructors_for_temps.cpp:72:34:72:35 | Unary | r72_18 |
12861286
| destructors_for_temps.cpp:72:34:72:35 | Unary | r72_21 |
1287+
| destructors_for_temps.cpp:77:6:77:15 | ChiPartial | partial:m77_3 |
1288+
| destructors_for_temps.cpp:77:6:77:15 | ChiTotal | total:m77_2 |
1289+
| destructors_for_temps.cpp:77:6:77:15 | SideEffect | ~m78_10 |
1290+
| destructors_for_temps.cpp:78:5:78:8 | CallTarget | func:r78_2 |
1291+
| destructors_for_temps.cpp:78:5:78:8 | ChiPartial | partial:m78_4 |
1292+
| destructors_for_temps.cpp:78:5:78:8 | ChiTotal | total:m77_4 |
1293+
| destructors_for_temps.cpp:78:5:78:8 | SideEffect | ~m77_4 |
1294+
| destructors_for_temps.cpp:78:5:78:8 | StoreValue | r78_3 |
1295+
| destructors_for_temps.cpp:78:5:78:10 | Address | &:r78_1 |
1296+
| destructors_for_temps.cpp:78:5:78:10 | Address | &:r78_6 |
1297+
| destructors_for_temps.cpp:78:5:78:10 | Address | &:r78_6 |
1298+
| destructors_for_temps.cpp:78:5:78:10 | Arg(this) | this:r78_6 |
1299+
| destructors_for_temps.cpp:78:5:78:10 | CallTarget | func:r78_7 |
1300+
| destructors_for_temps.cpp:78:5:78:10 | ChiPartial | partial:m78_9 |
1301+
| destructors_for_temps.cpp:78:5:78:10 | ChiPartial | partial:m78_12 |
1302+
| destructors_for_temps.cpp:78:5:78:10 | ChiTotal | total:m78_5 |
1303+
| destructors_for_temps.cpp:78:5:78:10 | ChiTotal | total:~m? |
1304+
| destructors_for_temps.cpp:78:5:78:10 | SideEffect | ~m78_5 |
1305+
| destructors_for_temps.cpp:78:5:78:10 | SideEffect | ~m? |
1306+
| destructors_for_temps.cpp:78:5:78:10 | Unary | r78_1 |
1307+
| destructors_for_temps.cpp:81:6:81:16 | ChiPartial | partial:m81_3 |
1308+
| destructors_for_temps.cpp:81:6:81:16 | ChiTotal | total:m81_2 |
1309+
| destructors_for_temps.cpp:81:6:81:16 | SideEffect | ~m82_2 |
1310+
| destructors_for_temps.cpp:81:22:81:22 | Address | &:r81_5 |
1311+
| destructors_for_temps.cpp:82:11:82:11 | Address | &:r82_3 |
1312+
| destructors_for_temps.cpp:82:11:82:11 | Left | r82_4 |
1313+
| destructors_for_temps.cpp:82:11:82:11 | Load | m81_6 |
1314+
| destructors_for_temps.cpp:82:11:82:11 | Phi | from 0:~m81_4 |
1315+
| destructors_for_temps.cpp:82:11:82:11 | Phi | from 2:m83_14 |
1316+
| destructors_for_temps.cpp:82:11:82:11 | Phi | from 2:~m83_10 |
1317+
| destructors_for_temps.cpp:82:11:82:16 | Condition | r82_6 |
1318+
| destructors_for_temps.cpp:82:15:82:16 | Right | r82_5 |
1319+
| destructors_for_temps.cpp:83:9:83:12 | CallTarget | func:r83_2 |
1320+
| destructors_for_temps.cpp:83:9:83:12 | ChiPartial | partial:m83_4 |
1321+
| destructors_for_temps.cpp:83:9:83:12 | ChiTotal | total:m82_2 |
1322+
| destructors_for_temps.cpp:83:9:83:12 | SideEffect | ~m82_2 |
1323+
| destructors_for_temps.cpp:83:9:83:12 | StoreValue | r83_3 |
1324+
| destructors_for_temps.cpp:83:9:83:14 | Address | &:r83_1 |
1325+
| destructors_for_temps.cpp:83:9:83:14 | Address | &:r83_6 |
1326+
| destructors_for_temps.cpp:83:9:83:14 | Address | &:r83_6 |
1327+
| destructors_for_temps.cpp:83:9:83:14 | Arg(this) | this:r83_6 |
1328+
| destructors_for_temps.cpp:83:9:83:14 | CallTarget | func:r83_7 |
1329+
| destructors_for_temps.cpp:83:9:83:14 | ChiPartial | partial:m83_9 |
1330+
| destructors_for_temps.cpp:83:9:83:14 | ChiPartial | partial:m83_12 |
1331+
| destructors_for_temps.cpp:83:9:83:14 | ChiTotal | total:m82_1 |
1332+
| destructors_for_temps.cpp:83:9:83:14 | ChiTotal | total:m83_5 |
1333+
| destructors_for_temps.cpp:83:9:83:14 | SideEffect | m82_1 |
1334+
| destructors_for_temps.cpp:83:9:83:14 | SideEffect | ~m83_5 |
1335+
| destructors_for_temps.cpp:83:9:83:14 | Unary | r83_1 |
12871336
| file://:0:0:0:0 | Address | &:r0_1 |
12881337
| file://:0:0:0:0 | Address | &:r0_1 |
12891338
| file://:0:0:0:0 | Address | &:r0_1 |

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

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,6 +1306,65 @@ destructors_for_temps.cpp:
13061306
#-----| False -> Block 1
13071307
#-----| True -> Block 3
13081308

1309+
# 77| void temp_test9()
1310+
# 77| Block 0
1311+
# 77| v77_1(void) = EnterFunction :
1312+
# 77| mu77_2(unknown) = AliasedDefinition :
1313+
# 77| mu77_3(unknown) = InitializeNonLocal :
1314+
# 78| r78_1(glval<ClassWithDestructor2>) = VariableAddress[#temp78:5] :
1315+
# 78| r78_2(glval<unknown>) = FunctionAddress[make] :
1316+
# 78| r78_3(ClassWithDestructor2) = Call[make] : func:r78_2
1317+
# 78| mu78_4(unknown) = ^CallSideEffect : ~m?
1318+
# 78| r78_5(glval<ClassWithDestructor2>) = CopyValue : r78_1
1319+
# 78| r78_6(glval<unknown>) = FunctionAddress[~ClassWithDestructor2] :
1320+
# 78| v78_7(void) = Call[~ClassWithDestructor2] : func:r78_6, this:r78_5
1321+
# 78| mu78_8(unknown) = ^CallSideEffect : ~m?
1322+
# 78| v78_9(void) = ^IndirectReadSideEffect[-1] : &:r78_5, ~m?
1323+
# 78| mu78_10(ClassWithDestructor2) = ^IndirectMayWriteSideEffect[-1] : &:r78_5
1324+
# 78| mu78_11(ClassWithDestructor2) = Store[#temp78:5] : &:r78_1, r78_3
1325+
# 79| v79_1(void) = NoOp :
1326+
# 77| v77_4(void) = ReturnVoid :
1327+
# 77| v77_5(void) = AliasedUse : ~m?
1328+
# 77| v77_6(void) = ExitFunction :
1329+
1330+
# 81| void temp_test10(int)
1331+
# 81| Block 0
1332+
# 81| v81_1(void) = EnterFunction :
1333+
# 81| mu81_2(unknown) = AliasedDefinition :
1334+
# 81| mu81_3(unknown) = InitializeNonLocal :
1335+
# 81| r81_4(glval<int>) = VariableAddress[i] :
1336+
# 81| mu81_5(int) = InitializeParameter[i] : &:r81_4
1337+
#-----| Goto -> Block 1
1338+
1339+
# 82| Block 1
1340+
# 82| r82_1(glval<int>) = VariableAddress[i] :
1341+
# 82| r82_2(int) = Load[i] : &:r82_1, ~m?
1342+
# 82| r82_3(int) = Constant[10] :
1343+
# 82| r82_4(bool) = CompareLT : r82_2, r82_3
1344+
# 82| v82_5(void) = ConditionalBranch : r82_4
1345+
#-----| False -> Block 3
1346+
#-----| True -> Block 2
1347+
1348+
# 83| Block 2
1349+
# 83| r83_1(glval<ClassWithDestructor2>) = VariableAddress[#temp83:9] :
1350+
# 83| r83_2(glval<unknown>) = FunctionAddress[make] :
1351+
# 83| r83_3(ClassWithDestructor2) = Call[make] : func:r83_2
1352+
# 83| mu83_4(unknown) = ^CallSideEffect : ~m?
1353+
# 83| r83_5(glval<ClassWithDestructor2>) = CopyValue : r83_1
1354+
# 83| r83_6(glval<unknown>) = FunctionAddress[~ClassWithDestructor2] :
1355+
# 83| v83_7(void) = Call[~ClassWithDestructor2] : func:r83_6, this:r83_5
1356+
# 83| mu83_8(unknown) = ^CallSideEffect : ~m?
1357+
# 83| v83_9(void) = ^IndirectReadSideEffect[-1] : &:r83_5, ~m?
1358+
# 83| mu83_10(ClassWithDestructor2) = ^IndirectMayWriteSideEffect[-1] : &:r83_5
1359+
# 83| mu83_11(ClassWithDestructor2) = Store[#temp83:9] : &:r83_1, r83_3
1360+
#-----| Goto (back edge) -> Block 1
1361+
1362+
# 85| Block 3
1363+
# 85| v85_1(void) = NoOp :
1364+
# 81| v81_6(void) = ReturnVoid :
1365+
# 81| v81_7(void) = AliasedUse : ~m?
1366+
# 81| v81_8(void) = ExitFunction :
1367+
13091368
ir.c:
13101369
# 7| void MyCoordsTest(int)
13111370
# 7| Block 0

0 commit comments

Comments
 (0)