Skip to content

Commit 06767c6

Browse files
committed
C++: Split bad_asts.cpp IR test into two files
The statements from `errorExpr` - which does not parse correctly - affected the tuples that were being generated for the other code in `bad_asts.cpp` due to the way the front-end handles parse errors. This did not affect the test results, but was also not the intention of the test. Split off `errorExpr` into a separate file.
1 parent 951f636 commit 06767c6

File tree

5 files changed

+71
-65
lines changed

5 files changed

+71
-65
lines changed

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

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -207,34 +207,35 @@ bad_asts.cpp:
207207
# 27| Type = [SpecifiedType] const Point
208208
# 27| ValueCategory = lvalue
209209
# 28| getStmt(1): [ReturnStmt] return ...
210-
# 30| [TopLevelFunction] void Bad::errorExpr()
211-
# 30| <params>:
212-
# 30| getEntryPoint(): [BlockStmt] { ... }
213-
# 31| getStmt(0): [DeclStmt] declaration
214-
# 31| getDeclarationEntry(0): [VariableDeclarationEntry] definition of intref
215-
# 31| Type = [LValueReferenceType] int &
216-
# 31| getVariable().getInitializer(): [Initializer] initializer for intref
217-
# 31| getExpr(): [ErrorExpr] <error expr>
218-
# 31| Type = [ErroneousType] error
219-
# 31| ValueCategory = prvalue
220-
# 32| getStmt(1): [DeclStmt] declaration
221-
# 32| getDeclarationEntry(0): [VariableDeclarationEntry] definition of x
222-
# 32| Type = [IntType] int
223-
# 32| getVariable().getInitializer(): [Initializer] initializer for x
224-
# 32| getExpr(): [ErrorExpr] <error expr>
225-
# 32| Type = [ErroneousType] error
226-
# 32| ValueCategory = prvalue
227-
# 33| getStmt(2): [ExprStmt] ExprStmt
228-
# 33| getExpr(): [AssignExpr] ... = ...
229-
# 33| Type = [IntType] int
230-
# 33| ValueCategory = lvalue
231-
# 33| getLValue(): [VariableAccess] x
232-
# 33| Type = [IntType] int
233-
# 33| ValueCategory = lvalue
234-
# 33| getRValue(): [ErrorExpr] <error expr>
235-
# 33| Type = [ErroneousType] error
236-
# 33| ValueCategory = prvalue(load)
237-
# 34| getStmt(3): [ReturnStmt] return ...
210+
bad_stmts.cpp:
211+
# 5| [TopLevelFunction] void Bad::errorExpr()
212+
# 5| <params>:
213+
# 5| getEntryPoint(): [BlockStmt] { ... }
214+
# 6| getStmt(0): [DeclStmt] declaration
215+
# 6| getDeclarationEntry(0): [VariableDeclarationEntry] definition of intref
216+
# 6| Type = [LValueReferenceType] int &
217+
# 6| getVariable().getInitializer(): [Initializer] initializer for intref
218+
# 6| getExpr(): [ErrorExpr] <error expr>
219+
# 6| Type = [ErroneousType] error
220+
# 6| ValueCategory = prvalue
221+
# 7| getStmt(1): [DeclStmt] declaration
222+
# 7| getDeclarationEntry(0): [VariableDeclarationEntry] definition of x
223+
# 7| Type = [IntType] int
224+
# 7| getVariable().getInitializer(): [Initializer] initializer for x
225+
# 7| getExpr(): [ErrorExpr] <error expr>
226+
# 7| Type = [ErroneousType] error
227+
# 7| ValueCategory = prvalue
228+
# 8| getStmt(2): [ExprStmt] ExprStmt
229+
# 8| getExpr(): [AssignExpr] ... = ...
230+
# 8| Type = [IntType] int
231+
# 8| ValueCategory = lvalue
232+
# 8| getLValue(): [VariableAccess] x
233+
# 8| Type = [IntType] int
234+
# 8| ValueCategory = lvalue
235+
# 8| getRValue(): [ErrorExpr] <error expr>
236+
# 8| Type = [ErroneousType] error
237+
# 8| ValueCategory = prvalue(load)
238+
# 9| getStmt(3): [ReturnStmt] return ...
238239
clang.cpp:
239240
# 5| [TopLevelFunction] int* globalIntAddress()
240241
# 5| <params>:

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

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

33
// Test cases that illustrate known bad ASTs that we have to work around in IR generation.
44
namespace Bad {
@@ -26,10 +26,4 @@ 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-
int &intref = 0;
32-
int x = 0[0];
33-
x = 1[1];
34-
}
3529
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// semmle-extractor-options: -std=c++17 --expect_errors
2+
3+
// Test cases that illustrate known bad ASTs that we have to work around in IR generation.
4+
namespace Bad {
5+
void errorExpr() {
6+
int &intref = 0;
7+
int x = 0[0];
8+
x = 1[1];
9+
}
10+
}

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,17 @@
9898
| bad_asts.cpp:27:15:27:15 | StoreValue | r27_6 |
9999
| bad_asts.cpp:27:15:27:15 | Unary | r27_3 |
100100
| bad_asts.cpp:27:15:27:15 | Unary | r27_4 |
101-
| bad_asts.cpp:30:8:30:16 | ChiPartial | partial:m30_3 |
102-
| bad_asts.cpp:30:8:30:16 | ChiTotal | total:m30_2 |
103-
| bad_asts.cpp:30:8:30:16 | SideEffect | m30_3 |
104-
| bad_asts.cpp:31:10:31:15 | Address | &:r31_1 |
105-
| bad_asts.cpp:31:18:31:19 | StoreValue | r31_2 |
106-
| bad_asts.cpp:32:9:32:9 | Address | &:r32_1 |
107-
| bad_asts.cpp:32:12:32:16 | StoreValue | r32_2 |
108-
| bad_asts.cpp:33:5:33:5 | Address | &:r33_3 |
109-
| bad_asts.cpp:33:5:33:12 | Address | &:r33_1 |
110-
| bad_asts.cpp:33:5:33:12 | Load | ~m30_4 |
111-
| bad_asts.cpp:33:5:33:12 | StoreValue | r33_2 |
101+
| bad_stmts.cpp:5:8:5:16 | ChiPartial | partial:m5_3 |
102+
| bad_stmts.cpp:5:8:5:16 | ChiTotal | total:m5_2 |
103+
| bad_stmts.cpp:5:8:5:16 | SideEffect | m5_3 |
104+
| bad_stmts.cpp:6:10:6:15 | Address | &:r6_1 |
105+
| bad_stmts.cpp:6:18:6:19 | StoreValue | r6_2 |
106+
| bad_stmts.cpp:7:9:7:9 | Address | &:r7_1 |
107+
| bad_stmts.cpp:7:12:7:16 | StoreValue | r7_2 |
108+
| bad_stmts.cpp:8:5:8:5 | Address | &:r8_3 |
109+
| bad_stmts.cpp:8:5:8:12 | Address | &:r8_1 |
110+
| bad_stmts.cpp:8:5:8:12 | Load | ~m5_4 |
111+
| bad_stmts.cpp:8:5:8:12 | StoreValue | r8_2 |
112112
| clang.cpp:5:6:5:21 | Address | &:r5_5 |
113113
| clang.cpp:5:6:5:21 | ChiPartial | partial:m5_3 |
114114
| clang.cpp:5:6:5:21 | ChiTotal | total:m5_2 |

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

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -120,25 +120,26 @@ bad_asts.cpp:
120120
# 26| v26_10(void) = AliasedUse : ~m?
121121
# 26| v26_11(void) = ExitFunction :
122122

123-
# 30| void Bad::errorExpr()
124-
# 30| Block 0
125-
# 30| v30_1(void) = EnterFunction :
126-
# 30| mu30_2(unknown) = AliasedDefinition :
127-
# 30| mu30_3(unknown) = InitializeNonLocal :
128-
# 31| r31_1(glval<int &>) = VariableAddress[intref] :
129-
# 31| r31_2(error) = Error :
130-
# 31| mu31_3(int &) = Store[intref] : &:r31_1, r31_2
131-
# 32| r32_1(glval<int>) = VariableAddress[x] :
132-
# 32| r32_2(error) = Error :
133-
# 32| mu32_3(int) = Store[x] : &:r32_1, r32_2
134-
# 33| r33_1(glval<error>) = Error :
135-
# 33| r33_2(error) = Load[?] : &:r33_1, ~m?
136-
# 33| r33_3(glval<int>) = VariableAddress[x] :
137-
# 33| mu33_4(int) = Store[x] : &:r33_3, r33_2
138-
# 34| v34_1(void) = NoOp :
139-
# 30| v30_4(void) = ReturnVoid :
140-
# 30| v30_5(void) = AliasedUse : ~m?
141-
# 30| v30_6(void) = ExitFunction :
123+
bad_stmts.cpp:
124+
# 5| void Bad::errorExpr()
125+
# 5| Block 0
126+
# 5| v5_1(void) = EnterFunction :
127+
# 5| mu5_2(unknown) = AliasedDefinition :
128+
# 5| mu5_3(unknown) = InitializeNonLocal :
129+
# 6| r6_1(glval<int &>) = VariableAddress[intref] :
130+
# 6| r6_2(error) = Error :
131+
# 6| mu6_3(int &) = Store[intref] : &:r6_1, r6_2
132+
# 7| r7_1(glval<int>) = VariableAddress[x] :
133+
# 7| r7_2(error) = Error :
134+
# 7| mu7_3(int) = Store[x] : &:r7_1, r7_2
135+
# 8| r8_1(glval<error>) = Error :
136+
# 8| r8_2(error) = Load[?] : &:r8_1, ~m?
137+
# 8| r8_3(glval<int>) = VariableAddress[x] :
138+
# 8| mu8_4(int) = Store[x] : &:r8_3, r8_2
139+
# 9| v9_1(void) = NoOp :
140+
# 5| v5_4(void) = ReturnVoid :
141+
# 5| v5_5(void) = AliasedUse : ~m?
142+
# 5| v5_6(void) = ExitFunction :
142143

143144
clang.cpp:
144145
# 5| int* globalIntAddress()

0 commit comments

Comments
 (0)