Skip to content

Commit

Permalink
C++: Add the simplest testcase that produces an 'missingPhiOperand' c…
Browse files Browse the repository at this point in the history
…onsistency error.
  • Loading branch information
MathiasVP committed Apr 6, 2024
1 parent 8ab6330 commit 50c6b3b
Show file tree
Hide file tree
Showing 6 changed files with 152 additions and 0 deletions.
31 changes: 31 additions & 0 deletions cpp/ql/test/library-tests/ir/ir/PrintAST.expected
Original file line number Diff line number Diff line change
Expand Up @@ -2295,6 +2295,37 @@ destructors_for_temps.cpp:
# 83| Type = [Class] ClassWithDestructor2
# 83| ValueCategory = prvalue
# 84| getStmt(1): [ReturnStmt] return ...
# 87| [TopLevelFunction] void temp_test10(int)
# 87| <params>:
# 87| getParameter(0): [Parameter] i
# 87| Type = [IntType] int
# 87| getEntryPoint(): [BlockStmt] { ... }
# 88| getStmt(0): [WhileStmt] while (...) ...
# 88| getCondition(): [LTExpr] ... < ...
# 88| Type = [BoolType] bool
# 88| ValueCategory = prvalue
# 88| getLesserOperand(): [VariableAccess] i
# 88| Type = [IntType] int
# 88| ValueCategory = prvalue(load)
# 88| getGreaterOperand(): [Literal] 10
# 88| Type = [IntType] int
# 88| Value = [Literal] 10
# 88| ValueCategory = prvalue
# 88| getStmt(): [BlockStmt] { ... }
# 91| getStmt(0): [ExprStmt] ExprStmt
# 91| getExpr(): [FunctionCall] call to make
# 91| Type = [Class] ClassWithDestructor2
# 91| ValueCategory = prvalue
# 91| getImplicitDestructorCall(0): [DestructorCall] call to ~ClassWithDestructor2
# 91| Type = [VoidType] void
# 91| ValueCategory = prvalue
# 91| getQualifier(): [ReuseExpr] reuse of temporary object
# 91| Type = [Class] ClassWithDestructor2
# 91| ValueCategory = xvalue
# 91| getExpr().getFullyConverted(): [TemporaryObjectExpr] temporary object
# 91| Type = [Class] ClassWithDestructor2
# 91| ValueCategory = prvalue
# 93| getStmt(1): [ReturnStmt] return ...
ir.c:
# 5| [TopLevelFunction] int getX(MyCoords*)
# 5| <params>:
Expand Down
44 changes: 44 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 @@ -1459,6 +1459,50 @@ destructors_for_temps.cpp:
# 77| v77_6(void) = AliasedUse : ~m83_10
# 77| v77_7(void) = ExitFunction :

# 87| void temp_test10(int)
# 87| Block 0
# 87| v87_1(void) = EnterFunction :
# 87| m87_2(unknown) = AliasedDefinition :
# 87| m87_3(unknown) = InitializeNonLocal :
# 87| m87_4(unknown) = Chi : total:m87_2, partial:m87_3
# 87| r87_5(glval<int>) = VariableAddress[i] :
# 87| m87_6(int) = InitializeParameter[i] : &:r87_5
#-----| Goto -> Block 1

# 88| Block 1
# 88| m88_1(ClassWithDestructor2) = Phi : from 2:m91_14
# 88| m88_2(unknown) = Phi : from 0:~m87_4, from 2:~m91_10
# 88| r88_3(glval<int>) = VariableAddress[i] :
# 88| r88_4(int) = Load[i] : &:r88_3, m87_6
# 88| r88_5(int) = Constant[10] :
# 88| r88_6(bool) = CompareLT : r88_4, r88_5
# 88| v88_7(void) = ConditionalBranch : r88_6
#-----| False -> Block 3
#-----| True -> Block 2

# 91| Block 2
# 91| r91_1(glval<ClassWithDestructor2>) = VariableAddress[#temp91:9] :
# 91| r91_2(glval<unknown>) = FunctionAddress[make] :
# 91| r91_3(ClassWithDestructor2) = Call[make] : func:r91_2
# 91| m91_4(unknown) = ^CallSideEffect : ~m88_2
# 91| m91_5(unknown) = Chi : total:m88_2, partial:m91_4
# 91| r91_6(glval<ClassWithDestructor2>) = CopyValue : r91_1
# 91| r91_7(glval<unknown>) = FunctionAddress[~ClassWithDestructor2] :
# 91| v91_8(void) = Call[~ClassWithDestructor2] : func:r91_7, this:r91_6
# 91| m91_9(unknown) = ^CallSideEffect : ~m91_5
# 91| m91_10(unknown) = Chi : total:m91_5, partial:m91_9
# 91| v91_11(void) = ^IndirectReadSideEffect[-1] : &:r91_6, m88_1
# 91| m91_12(ClassWithDestructor2) = ^IndirectMayWriteSideEffect[-1] : &:r91_6
# 91| m91_13(ClassWithDestructor2) = Chi : total:m88_1, partial:m91_12
# 91| m91_14(ClassWithDestructor2) = Store[#temp91:9] : &:r91_1, r91_3
#-----| Goto (back edge) -> Block 1

# 93| Block 3
# 93| v93_1(void) = NoOp :
# 87| v87_7(void) = ReturnVoid :
# 87| v87_8(void) = AliasedUse : ~m88_2
# 87| v87_9(void) = ExitFunction :

ir.c:
# 7| void MyCoordsTest(int)
# 7| Block 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ missingOperand
unexpectedOperand
duplicateOperand
missingPhiOperand
| destructors_for_temps.cpp:88:11:88:11 | Phi: i | Instruction 'Phi: i' is missing an operand for predecessor block 'EnterFunction: temp_test10' in function '$@'. | destructors_for_temps.cpp:87:6:87:16 | void temp_test10(int) | void temp_test10(int) |
missingOperandType
| 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) |
| destructors_for_temps.cpp:83:5:83: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() |
Expand Down
9 changes: 9 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 @@ -82,3 +82,12 @@ void temp_test9() {
// a memory. The same problem happens in `temp_test5`.
make();
}


void temp_test10(int i) {
while(i < 10) {
// Here we get a `missingPhiOperand` inconsistency error for the same reason
// that we're getting a `missingOperandType` in `temp_test9`.
make();
}
}
29 changes: 29 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 @@ -1304,6 +1304,35 @@
| destructors_for_temps.cpp:83:5:83:10 | SideEffect | ~m83_5 |
| destructors_for_temps.cpp:83:5:83:10 | SideEffect | ~m? |
| destructors_for_temps.cpp:83:5:83:10 | Unary | r83_1 |
| destructors_for_temps.cpp:87:6:87:16 | ChiPartial | partial:m87_3 |
| destructors_for_temps.cpp:87:6:87:16 | ChiTotal | total:m87_2 |
| destructors_for_temps.cpp:87:6:87:16 | SideEffect | ~m88_2 |
| destructors_for_temps.cpp:87:22:87:22 | Address | &:r87_5 |
| destructors_for_temps.cpp:88:11:88:11 | Address | &:r88_3 |
| destructors_for_temps.cpp:88:11:88:11 | Left | r88_4 |
| destructors_for_temps.cpp:88:11:88:11 | Load | m87_6 |
| destructors_for_temps.cpp:88:11:88:11 | Phi | from 0:~m87_4 |
| destructors_for_temps.cpp:88:11:88:11 | Phi | from 2:m91_14 |
| destructors_for_temps.cpp:88:11:88:11 | Phi | from 2:~m91_10 |
| destructors_for_temps.cpp:88:11:88:16 | Condition | r88_6 |
| destructors_for_temps.cpp:88:15:88:16 | Right | r88_5 |
| destructors_for_temps.cpp:91:9:91:12 | CallTarget | func:r91_2 |
| destructors_for_temps.cpp:91:9:91:12 | ChiPartial | partial:m91_4 |
| destructors_for_temps.cpp:91:9:91:12 | ChiTotal | total:m88_2 |
| destructors_for_temps.cpp:91:9:91:12 | SideEffect | ~m88_2 |
| destructors_for_temps.cpp:91:9:91:12 | StoreValue | r91_3 |
| destructors_for_temps.cpp:91:9:91:14 | Address | &:r91_1 |
| destructors_for_temps.cpp:91:9:91:14 | Address | &:r91_6 |
| destructors_for_temps.cpp:91:9:91:14 | Address | &:r91_6 |
| destructors_for_temps.cpp:91:9:91:14 | Arg(this) | this:r91_6 |
| destructors_for_temps.cpp:91:9:91:14 | CallTarget | func:r91_7 |
| destructors_for_temps.cpp:91:9:91:14 | ChiPartial | partial:m91_9 |
| destructors_for_temps.cpp:91:9:91:14 | ChiPartial | partial:m91_12 |
| destructors_for_temps.cpp:91:9:91:14 | ChiTotal | total:m88_1 |
| destructors_for_temps.cpp:91:9:91:14 | ChiTotal | total:m91_5 |
| destructors_for_temps.cpp:91:9:91:14 | SideEffect | m88_1 |
| destructors_for_temps.cpp:91:9:91:14 | SideEffect | ~m91_5 |
| destructors_for_temps.cpp:91:9:91:14 | Unary | r91_1 |
| 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
38 changes: 38 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 @@ -1327,6 +1327,44 @@ destructors_for_temps.cpp:
# 77| v77_5(void) = AliasedUse : ~m?
# 77| v77_6(void) = ExitFunction :

# 87| void temp_test10(int)
# 87| Block 0
# 87| v87_1(void) = EnterFunction :
# 87| mu87_2(unknown) = AliasedDefinition :
# 87| mu87_3(unknown) = InitializeNonLocal :
# 87| r87_4(glval<int>) = VariableAddress[i] :
# 87| mu87_5(int) = InitializeParameter[i] : &:r87_4
#-----| Goto -> Block 1

# 88| Block 1
# 88| r88_1(glval<int>) = VariableAddress[i] :
# 88| r88_2(int) = Load[i] : &:r88_1, ~m?
# 88| r88_3(int) = Constant[10] :
# 88| r88_4(bool) = CompareLT : r88_2, r88_3
# 88| v88_5(void) = ConditionalBranch : r88_4
#-----| False -> Block 3
#-----| True -> Block 2

# 91| Block 2
# 91| r91_1(glval<ClassWithDestructor2>) = VariableAddress[#temp91:9] :
# 91| r91_2(glval<unknown>) = FunctionAddress[make] :
# 91| r91_3(ClassWithDestructor2) = Call[make] : func:r91_2
# 91| mu91_4(unknown) = ^CallSideEffect : ~m?
# 91| r91_5(glval<ClassWithDestructor2>) = CopyValue : r91_1
# 91| r91_6(glval<unknown>) = FunctionAddress[~ClassWithDestructor2] :
# 91| v91_7(void) = Call[~ClassWithDestructor2] : func:r91_6, this:r91_5
# 91| mu91_8(unknown) = ^CallSideEffect : ~m?
# 91| v91_9(void) = ^IndirectReadSideEffect[-1] : &:r91_5, ~m?
# 91| mu91_10(ClassWithDestructor2) = ^IndirectMayWriteSideEffect[-1] : &:r91_5
# 91| mu91_11(ClassWithDestructor2) = Store[#temp91:9] : &:r91_1, r91_3
#-----| Goto (back edge) -> Block 1

# 93| Block 3
# 93| v93_1(void) = NoOp :
# 87| v87_6(void) = ReturnVoid :
# 87| v87_7(void) = AliasedUse : ~m?
# 87| v87_8(void) = ExitFunction :

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

0 comments on commit 50c6b3b

Please sign in to comment.