Skip to content

Commit 0aa39c0

Browse files
authored
Merge pull request github#12712 from github/sashabu/repeated-initializers
C++: Support repeated initializers in dbscheme.
2 parents 4d3fc02 + 1d9fc8a commit 0aa39c0

File tree

11 files changed

+12545
-3184
lines changed

11 files changed

+12545
-3184
lines changed

cpp/downgrades/19887dbd33327fb07d54251786e0cb2578539775/old.dbscheme

Lines changed: 2212 additions & 0 deletions
Large diffs are not rendered by default.

cpp/downgrades/19887dbd33327fb07d54251786e0cb2578539775/semmlecode.cpp.dbscheme

Lines changed: 2210 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
description: Revert support for repeated initializers, which are allowed in C with designated initializers.
2+
compatibility: full
3+
aggregate_field_init.rel: reorder aggregate_field_init.rel (int aggregate, int initializer, int field, int position) aggregate initializer field
4+
aggregate_array_init.rel: reorder aggregate_array_init.rel (int aggregate, int initializer, int element_index, int position) aggregate initializer element_index

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,8 @@ class ClassAggregateLiteral extends AggregateLiteral {
192192
*/
193193
Expr getFieldExpr(Field field) {
194194
field = classType.getAField() and
195-
aggregate_field_init(underlyingElement(this), unresolveElement(result), unresolveElement(field))
195+
aggregate_field_init(underlyingElement(this), unresolveElement(result), unresolveElement(field),
196+
_)
196197
}
197198

198199
/**
@@ -264,7 +265,7 @@ class ArrayOrVectorAggregateLiteral extends AggregateLiteral {
264265
* element `elementIndex`, if present.
265266
*/
266267
Expr getElementExpr(int elementIndex) {
267-
aggregate_array_init(underlyingElement(this), unresolveElement(result), elementIndex)
268+
aggregate_array_init(underlyingElement(this), unresolveElement(result), elementIndex, _)
268269
}
269270

270271
/**

cpp/ql/lib/semmlecode.cpp.dbscheme

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1820,24 +1820,26 @@ new_array_allocated_type(
18201820

18211821
/**
18221822
* The field being initialized by an initializer expression within an aggregate
1823-
* initializer for a class/struct/union.
1823+
* initializer for a class/struct/union. Position is used to sort repeated initializers.
18241824
*/
1825-
#keyset[aggregate, field]
1825+
#keyset[aggregate, position]
18261826
aggregate_field_init(
18271827
int aggregate: @aggregateliteral ref,
18281828
int initializer: @expr ref,
1829-
int field: @membervariable ref
1829+
int field: @membervariable ref,
1830+
int position: int ref
18301831
);
18311832

18321833
/**
18331834
* The index of the element being initialized by an initializer expression
1834-
* within an aggregate initializer for an array.
1835+
* within an aggregate initializer for an array. Position is used to sort repeated initializers.
18351836
*/
1836-
#keyset[aggregate, element_index]
1837+
#keyset[aggregate, position]
18371838
aggregate_array_init(
18381839
int aggregate: @aggregateliteral ref,
18391840
int initializer: @expr ref,
1840-
int element_index: int ref
1841+
int element_index: int ref,
1842+
int position: int ref
18411843
);
18421844

18431845
@ctorinit = @ctordirectinit

0 commit comments

Comments
 (0)