Skip to content

Commit d0a77a8

Browse files
committed
C++: Support repeated initializers in dbscheme.
1 parent 2b9daed commit d0a77a8

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

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)