Skip to content

Commit e2a43ee

Browse files
committed
C++ IR: Tests with ErrorExpr
1 parent 46d7792 commit e2a43ee

File tree

6 files changed

+62
-1
lines changed

6 files changed

+62
-1
lines changed

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,31 @@ bad_asts.cpp:
190190
# 27| Type = const Point &
191191
# 27| ValueCategory = prvalue(load)
192192
# 28| 1: return ...
193+
# 30| void Bad::errorExpr()
194+
# 30| params:
195+
# 30| body: { ... }
196+
# 31| 0: ExprStmt
197+
#-----| 0: <error expr>
198+
#-----| Type = error
199+
#-----| ValueCategory = prvalue(load)
200+
# 32| 1: declaration
201+
# 32| 0: definition of x
202+
# 32| Type = int
203+
# 32| init: initializer for x
204+
# 32| expr: <error expr>
205+
# 32| Type = error
206+
# 32| ValueCategory = prvalue
207+
# 33| 2: ExprStmt
208+
# 33| 0: ... = ...
209+
# 33| Type = int
210+
# 33| ValueCategory = lvalue
211+
# 33| 0: x
212+
# 33| Type = int
213+
# 33| ValueCategory = lvalue
214+
#-----| 1: <error expr>
215+
#-----| Type = error
216+
#-----| ValueCategory = prvalue(load)
217+
# 34| 3: return ...
193218
clang.cpp:
194219
# 5| int* globalIntAddress()
195220
# 5| params:

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ duplicateOperand
44
missingPhiOperand
55
missingOperandType
66
instructionWithoutSuccessor
7+
| bad_asts.cpp:30:8:30:16 | UnmodeledDefinition: errorExpr |
78
ambiguousSuccessors
89
unexplainedLoop
910
unnecessaryPhiInstruction

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// semmle-extractor-options: -std=c++17
1+
// semmle-extractor-options: -std=c++17 --expect_errors
22

33
// Test cases that illustrate known bad ASTs that we have to work around in IR generation.
44
namespace Bad {
@@ -26,4 +26,10 @@ namespace Bad {
2626
void CallCopyConstructor(const Point& a) {
2727
Point b = a; // Copy constructor contains literal expressions with no values.
2828
}
29+
30+
void errorExpr() {
31+
0 = 1;
32+
int x = 0[0];
33+
x = 1[1];
34+
}
2935
}

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,28 @@ bad_asts.cpp:
4848
# 26| v0_13(void) = UnmodeledUse : mu*
4949
# 26| v0_14(void) = ExitFunction :
5050

51+
# 30| void Bad::errorExpr()
52+
# 30| Block 0
53+
# 30| v0_0(void) = EnterFunction :
54+
# 30| mu0_1(unknown) = AliasedDefinition :
55+
# 30| mu0_2(unknown) = UnmodeledDefinition :
56+
57+
#-----| Block 1
58+
#-----| r1_0(error) = Load : ~mu0_2
59+
# 33| r1_1(glval<int>) = VariableAddress[x] :
60+
# 33| mu1_2(int) = Store : &:r1_1, r1_0
61+
# 34| v1_3(void) = NoOp :
62+
# 30| v1_4(void) = ReturnVoid :
63+
# 30| v1_5(void) = UnmodeledUse : mu*
64+
# 30| v1_6(void) = ExitFunction :
65+
66+
#-----| Block 2
67+
#-----| r2_0(error) = Load : ~mu0_2
68+
# 32| r2_1(glval<int>) = VariableAddress[x] :
69+
70+
# 32| Block 3
71+
# 32| mu3_0(int) = Store : &:r2_1
72+
5173
clang.cpp:
5274
# 5| int* globalIntAddress()
5375
# 5| Block 0

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
missingOperand
2+
| bad_asts.cpp:32:12:32:16 | Store: <error expr> | Instruction 'Store' is missing an expected operand with tag 'StoreValue' in function '$@'. | bad_asts.cpp:30:8:30:16 | IR: errorExpr | void Bad::errorExpr() |
3+
| file://:0:0:0:0 | Load: <error expr> | Instruction 'Load' is missing an expected operand with tag 'Address' in function '$@'. | bad_asts.cpp:30:8:30:16 | IR: errorExpr | void Bad::errorExpr() |
4+
| file://:0:0:0:0 | Load: <error expr> | Instruction 'Load' is missing an expected operand with tag 'Address' in function '$@'. | bad_asts.cpp:30:8:30:16 | IR: errorExpr | void Bad::errorExpr() |
25
unexpectedOperand
36
duplicateOperand
47
missingPhiOperand
58
missingOperandType
69
instructionWithoutSuccessor
10+
| bad_asts.cpp:30:8:30:16 | UnmodeledDefinition: errorExpr |
11+
| bad_asts.cpp:32:9:32:9 | VariableAddress: definition of x |
12+
| bad_asts.cpp:32:12:32:16 | Store: <error expr> |
713
ambiguousSuccessors
814
unexplainedLoop
915
unnecessaryPhiInstruction

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ duplicateOperand
44
missingPhiOperand
55
missingOperandType
66
instructionWithoutSuccessor
7+
| bad_asts.cpp:30:8:30:16 | UnmodeledDefinition: errorExpr |
78
ambiguousSuccessors
89
unexplainedLoop
910
unnecessaryPhiInstruction

0 commit comments

Comments
 (0)