Skip to content

Commit 2424017

Browse files
authored
Merge pull request github#2023 from ian-semmle/agglit
Approved by jbj
2 parents 67ae00f + 142e1cb commit 2424017

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

cpp/ql/src/semmle/code/cpp/exprs/Literal.qll

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ class HexLiteral extends Literal {
132132
* A C/C++ aggregate literal.
133133
*/
134134
class AggregateLiteral extends Expr, @aggregateliteral {
135-
// if this is turned into a Literal we need to change mayBeImpure
136135
override string getCanonicalQLClass() { result = "AggregateLiteral" }
137136

138137
/**
@@ -145,6 +144,10 @@ class AggregateLiteral extends Expr, @aggregateliteral {
145144
result = this.(ClassAggregateLiteral).getFieldExpr(f)
146145
}
147146

147+
override predicate mayBeImpure() { this.getAChild().mayBeImpure() }
148+
149+
override predicate mayBeGloballyImpure() { this.getAChild().mayBeGloballyImpure() }
150+
148151
/** Gets a textual representation of this aggregate literal. */
149152
override string toString() { result = "{...}" }
150153
}

cpp/ql/test/library-tests/sideEffects/exprs/exprs.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
void f1(int p) {
2+
int f1(int p) {
33
int i;
44

55
for (
@@ -11,3 +11,20 @@ void f1(int p) {
1111

1212
return p;
1313
}
14+
15+
int global_int;
16+
17+
int f2(void) {
18+
global_int = 3;
19+
return 1;
20+
}
21+
22+
int f3(void) {
23+
return 2;
24+
}
25+
26+
void f4(void) {
27+
int is0[3] = { 3, 4, 5 };
28+
int is1[3] = { 3, f2(), 5 };
29+
int is2[3] = { 3, f3(), 5 };
30+
}

cpp/ql/test/library-tests/sideEffects/exprs/exprs.expected

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,26 @@
1010
| exprs.c:9:3:9:5 | ++ ... | | mayBeImpure | |
1111
| exprs.c:9:5:9:5 | p | isPure | | |
1212
| exprs.c:12:12:12:12 | p | isPure | | |
13+
| exprs.c:18:5:18:14 | global_int | isPure | | |
14+
| exprs.c:18:5:18:18 | ... = ... | | mayBeImpure | mayBeGloballyImpure |
15+
| exprs.c:18:18:18:18 | 3 | isPure | | |
16+
| exprs.c:19:12:19:12 | 1 | isPure | | |
17+
| exprs.c:23:12:23:12 | 2 | isPure | | |
18+
| exprs.c:27:13:27:13 | 3 | isPure | | |
19+
| exprs.c:27:17:27:28 | {...} | isPure | | |
20+
| exprs.c:27:20:27:20 | 3 | isPure | | |
21+
| exprs.c:27:23:27:23 | 4 | isPure | | |
22+
| exprs.c:27:26:27:26 | 5 | isPure | | |
23+
| exprs.c:28:13:28:13 | 3 | isPure | | |
24+
| exprs.c:28:17:28:31 | {...} | | mayBeImpure | mayBeGloballyImpure |
25+
| exprs.c:28:20:28:20 | 3 | isPure | | |
26+
| exprs.c:28:23:28:24 | call to f2 | | mayBeImpure | mayBeGloballyImpure |
27+
| exprs.c:28:29:28:29 | 5 | isPure | | |
28+
| exprs.c:29:13:29:13 | 3 | isPure | | |
29+
| exprs.c:29:17:29:31 | {...} | isPure | | |
30+
| exprs.c:29:20:29:20 | 3 | isPure | | |
31+
| exprs.c:29:23:29:24 | call to f3 | isPure | | |
32+
| exprs.c:29:29:29:29 | 5 | isPure | | |
1333
| exprs.cpp:7:10:7:16 | (...) | isPure | | |
1434
| exprs.cpp:7:10:7:16 | (reference to) | isPure | | |
1535
| exprs.cpp:7:11:7:15 | * ... | isPure | | |

0 commit comments

Comments
 (0)