Skip to content

Commit 6cd5223

Browse files
authored
Merge pull request #11913 from jketema/test-fixes
C++: Some minor test fixes
2 parents 5a82012 + ee19c3d commit 6cd5223

File tree

9 files changed

+89
-83
lines changed

9 files changed

+89
-83
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()

cpp/ql/test/library-tests/syntax-zoo/allocators.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
struct Foo
1+
struct Allocators
22
{
3-
Foo(int x, int y) : m_x(x), m_y(y) {}
4-
~Foo() {m_x = m_y = 0;}
3+
Allocators(int x, int y) : m_x(x), m_y(y) {}
4+
~Allocators() {m_x = m_y = 0;}
55

66
// NB: In Microsoft mode, size_t is predeclared.
77
static void* operator new(size_t sz, int z, int w) { return nullptr; }
@@ -13,7 +13,7 @@ struct Foo
1313

1414
int main()
1515
{
16-
auto foo = new(11, 22) Foo(33, 44);
16+
auto foo = new(11, 22) Allocators(33, 44);
1717
delete foo;
1818
}
1919

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
struct Foo {
2-
~Foo();
1+
struct ArrayDelete {
2+
~ArrayDelete();
33
};
44

55
void f() {
6-
delete[] (Foo*)nullptr;
6+
delete[] (ArrayDelete*)nullptr;
77
}

cpp/ql/test/library-tests/syntax-zoo/dataflow-consistency.expected

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ argHasPostUpdate
7474
| ir.cpp:625:5:625:5 | s | ArgumentNode is missing PostUpdateNode. |
7575
postWithInFlow
7676
| VacuousDestructorCall.cpp:10:22:10:22 | i [inner post update] | PostUpdateNode should not be the target of local flow. |
77-
| allocators.cpp:4:11:4:13 | m_x [post update] | PostUpdateNode should not be the target of local flow. |
78-
| allocators.cpp:4:17:4:19 | m_y [post update] | PostUpdateNode should not be the target of local flow. |
77+
| allocators.cpp:4:18:4:20 | m_x [post update] | PostUpdateNode should not be the target of local flow. |
78+
| allocators.cpp:4:24:4:26 | m_y [post update] | PostUpdateNode should not be the target of local flow. |
7979
| assignexpr.cpp:9:4:9:4 | i [post update] | PostUpdateNode should not be the target of local flow. |
8080
| builtin.c:34:23:34:31 | staticint [inner post update] | PostUpdateNode should not be the target of local flow. |
8181
| builtin.c:39:37:39:45 | carry_out [inner post update] | PostUpdateNode should not be the target of local flow. |

cpp/ql/test/library-tests/syntax-zoo/dataflow-ir-consistency.expected

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1483,17 +1483,17 @@ postWithInFlow
14831483
| aggregateinitializer.c:3:6:3:6 | VariableAddress [post update] | PostUpdateNode should not be the target of local flow. |
14841484
| aggregateinitializer.c:3:11:3:27 | PointerAdd [post update] | PostUpdateNode should not be the target of local flow. |
14851485
| aggregateinitializer.c:3:11:3:27 | PointerAdd [post update] | PostUpdateNode should not be the target of local flow. |
1486-
| allocators.cpp:3:23:3:28 | FieldAddress [post update] | PostUpdateNode should not be the target of local flow. |
1487-
| allocators.cpp:3:31:3:36 | FieldAddress [post update] | PostUpdateNode should not be the target of local flow. |
1488-
| allocators.cpp:4:11:4:13 | VariableAddress [post update] | PostUpdateNode should not be the target of local flow. |
1489-
| allocators.cpp:4:11:4:13 | m_x [post update] | PostUpdateNode should not be the target of local flow. |
1490-
| allocators.cpp:4:17:4:19 | VariableAddress [post update] | PostUpdateNode should not be the target of local flow. |
1491-
| allocators.cpp:4:17:4:19 | m_y [post update] | PostUpdateNode should not be the target of local flow. |
1486+
| allocators.cpp:3:30:3:35 | FieldAddress [post update] | PostUpdateNode should not be the target of local flow. |
1487+
| allocators.cpp:3:38:3:43 | FieldAddress [post update] | PostUpdateNode should not be the target of local flow. |
1488+
| allocators.cpp:4:18:4:20 | VariableAddress [post update] | PostUpdateNode should not be the target of local flow. |
1489+
| allocators.cpp:4:18:4:20 | m_x [post update] | PostUpdateNode should not be the target of local flow. |
1490+
| allocators.cpp:4:24:4:26 | VariableAddress [post update] | PostUpdateNode should not be the target of local flow. |
1491+
| allocators.cpp:4:24:4:26 | m_y [post update] | PostUpdateNode should not be the target of local flow. |
14921492
| allocators.cpp:7:56:7:70 | VariableAddress [post update] | PostUpdateNode should not be the target of local flow. |
14931493
| allocators.cpp:16:8:16:10 | VariableAddress [post update] | PostUpdateNode should not be the target of local flow. |
1494-
| allocators.cpp:16:14:16:36 | Call [post update] | PostUpdateNode should not be the target of local flow. |
1495-
| allocators.cpp:16:14:16:36 | new [post update] | PostUpdateNode should not be the target of local flow. |
1496-
| allocators.cpp:16:14:16:36 | new [post update] | PostUpdateNode should not be the target of local flow. |
1494+
| allocators.cpp:16:14:16:43 | Call [post update] | PostUpdateNode should not be the target of local flow. |
1495+
| allocators.cpp:16:14:16:43 | new [post update] | PostUpdateNode should not be the target of local flow. |
1496+
| allocators.cpp:16:14:16:43 | new [post update] | PostUpdateNode should not be the target of local flow. |
14971497
| allocators.cpp:18:1:18:1 | VariableAddress [post update] | PostUpdateNode should not be the target of local flow. |
14981498
| assignexpr.cpp:9:4:9:4 | i [post update] | PostUpdateNode should not be the target of local flow. |
14991499
| bad_asts.cpp:10:7:10:23 | VariableAddress [post update] | PostUpdateNode should not be the target of local flow. |

0 commit comments

Comments
 (0)