Skip to content

Commit e143870

Browse files
committed
CPP: Pavel's sketch implementation.
1 parent 2f36d81 commit e143870

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

cpp/ql/src/semmle/code/cpp/Variable.qll

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,14 @@ class Variable extends Declaration, @variable {
163163
predicate isCompilerGenerated() { compgenerated(underlyingElement(this)) }
164164
}
165165

166+
class ExtendedField extends Field {
167+
override Expr getAnAssignedValue() {
168+
exists(AggregateLiteral l |
169+
this.getDeclaringType() = l.getType() and result = l.getChild(this.getInitializationOrder())
170+
)
171+
}
172+
}
173+
166174
/**
167175
* A particular declaration or definition of a C/C++ variable.
168176
*/

cpp/ql/test/library-tests/variables/getanassignedvalue/getanassignedvalue.expected

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,18 @@
77
| test.cpp:10:10:10:11 | 13 | test.cpp:6:7:6:11 | ref_v |
88
| test.cpp:11:6:11:10 | ... + ... | test.cpp:4:6:4:6 | v |
99
| test.cpp:19:32:19:35 | 0.0 | test.cpp:19:27:19:28 | _y |
10-
| test.cpp:19:42:19:43 | _x | test.cpp:24:8:24:8 | x |
11-
| test.cpp:19:49:19:50 | _y | test.cpp:24:11:24:11 | y |
12-
| test.cpp:19:54:19:60 | 0.0 | test.cpp:24:14:24:14 | z |
1310
| test.cpp:35:16:35:25 | {...} | test.cpp:35:11:35:12 | v1 |
11+
| test.cpp:35:17:35:17 | 1 | test.cpp:31:6:31:8 | num |
12+
| test.cpp:35:20:35:24 | One | test.cpp:32:14:32:16 | str |
1413
| test.cpp:36:16:36:39 | {...} | test.cpp:36:11:36:12 | v2 |
14+
| test.cpp:36:24:36:24 | 2 | test.cpp:31:6:31:8 | num |
15+
| test.cpp:36:34:36:38 | Two | test.cpp:32:14:32:16 | str |
16+
| test.cpp:38:27:38:27 | 3 | test.cpp:31:6:31:8 | num |
17+
| test.cpp:38:30:38:36 | Three | test.cpp:32:14:32:16 | str |
1518
| test.cpp:48:16:48:28 | {...} | test.cpp:48:11:48:12 | v3 |
19+
| test.cpp:48:17:48:27 | {...} | test.cpp:45:12:45:14 | ms2 |
20+
| test.cpp:48:18:48:18 | 4 | test.cpp:31:6:31:8 | num |
21+
| test.cpp:48:21:48:26 | Four | test.cpp:32:14:32:16 | str |
1622
| test.cpp:52:19:52:27 | {...} | test.cpp:52:5:52:11 | myArray |
1723
| test.cpp:54:17:54:31 | {...} | test.cpp:54:6:54:11 | chars2 |
1824
| test.cpp:55:16:55:20 | abc | test.cpp:55:7:55:12 | chars3 |

cpp/ql/test/library-tests/variables/getanassignedvalue/test.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ struct myStruct1
3232
const char *str;
3333
};
3434

35-
myStruct1 v1 = {1, "One"}; // assigment to `v1`
36-
myStruct1 v2 = {.num = 2, .str = "Two"}; // assigment to `v2`
35+
myStruct1 v1 = {1, "One"}; // assigments to `v1`, `num`, `str`
36+
myStruct1 v2 = {.num = 2, .str = "Two"}; // assigments to `v2`, `num`, `str`
3737

38-
void test2(myStruct1 v = {3, "Three"}) // assignment to `v` (literal `{...}` has no location)
38+
void test2(myStruct1 v = {3, "Three"}) // assignments to `v` (literal `{...}` has no location), `num`, `str`
3939
{
4040
// ...
4141
}
@@ -45,7 +45,7 @@ struct myStruct2
4545
myStruct1 ms2;
4646
};
4747

48-
myStruct2 v3 = {{4, "Four"}}; // assigment to `v3`
48+
myStruct2 v3 = {{4, "Four"}}; // assigments to `v3`, `ms2`, `num`, `str`
4949

5050
// ---
5151

0 commit comments

Comments
 (0)