Skip to content

Commit ec2567b

Browse files
committed
Add IR test for array structured bindings
1 parent 7d55771 commit ec2567b

File tree

4 files changed

+368
-0
lines changed

4 files changed

+368
-0
lines changed

cpp/ql/test/library-tests/ir/ir/PrintAST.expected

Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11390,6 +11390,190 @@ ir.cpp:
1139011390
# 1458| Value = [Literal] 3
1139111391
# 1458| ValueCategory = prvalue
1139211392
# 1459| getStmt(1): [ReturnStmt] return ...
11393+
# 1462| [TopLevelFunction] void array_structured_binding()
11394+
# 1462| <params>:
11395+
# 1462| getEntryPoint(): [BlockStmt] { ... }
11396+
# 1463| getStmt(0): [DeclStmt] declaration
11397+
# 1463| getDeclarationEntry(0): [VariableDeclarationEntry] definition of xs
11398+
# 1463| Type = [ArrayType] int[2]
11399+
# 1463| getVariable().getInitializer(): [Initializer] initializer for xs
11400+
# 1463| getExpr(): [ArrayAggregateLiteral] {...}
11401+
# 1463| Type = [ArrayType] int[2]
11402+
# 1463| ValueCategory = prvalue
11403+
# 1463| getElementExpr(0): [Literal] 1
11404+
# 1463| Type = [IntType] int
11405+
# 1463| Value = [Literal] 1
11406+
# 1463| ValueCategory = prvalue
11407+
# 1463| getElementExpr(1): [Literal] 2
11408+
# 1463| Type = [IntType] int
11409+
# 1463| Value = [Literal] 2
11410+
# 1463| ValueCategory = prvalue
11411+
# 1465| getStmt(1): [BlockStmt] { ... }
11412+
# 1466| getStmt(0): [DeclStmt] declaration
11413+
# 1466| getDeclarationEntry(0): (no string representation)
11414+
# 1466| Type = [LValueReferenceType] int(&)[2]
11415+
# 1466| getVariable().getInitializer(): [Initializer] initializer for (unnamed local variable)
11416+
# 1466| getExpr(): [VariableAccess] xs
11417+
# 1466| Type = [ArrayType] int[2]
11418+
# 1466| ValueCategory = lvalue
11419+
# 1466| getExpr().getFullyConverted(): [ReferenceToExpr] (reference to)
11420+
# 1466| Type = [LValueReferenceType] int(&)[2]
11421+
# 1466| ValueCategory = prvalue
11422+
# 1466| getDeclarationEntry(1): [VariableDeclarationEntry] definition of x0
11423+
# 1466| Type = [IntType] int
11424+
#-----| getVariable().getInitializer(): [Initializer] initializer for x0
11425+
#-----| getExpr(): [ArrayExpr] access to array
11426+
#-----| Type = [IntType] int
11427+
#-----| ValueCategory = lvalue
11428+
#-----| getArrayBase(): [VariableAccess] (unnamed local variable)
11429+
#-----| Type = [LValueReferenceType] int(&)[2]
11430+
#-----| ValueCategory = prvalue(load)
11431+
#-----| getArrayOffset(): [Literal] 0
11432+
#-----| Type = [LongType] unsigned long
11433+
#-----| Value = [Literal] 0
11434+
#-----| ValueCategory = prvalue
11435+
#-----| getArrayBase().getFullyConverted(): [ArrayToPointerConversion] array to pointer conversion
11436+
#-----| Type = [IntPointerType] int *
11437+
#-----| ValueCategory = prvalue
11438+
#-----| getExpr(): [ReferenceDereferenceExpr] (reference dereference)
11439+
#-----| Type = [ArrayType] int[2]
11440+
#-----| ValueCategory = lvalue
11441+
# 1466| getDeclarationEntry(2): [VariableDeclarationEntry] definition of x1
11442+
# 1466| Type = [IntType] int
11443+
#-----| getVariable().getInitializer(): [Initializer] initializer for x1
11444+
#-----| getExpr(): [ArrayExpr] access to array
11445+
#-----| Type = [IntType] int
11446+
#-----| ValueCategory = lvalue
11447+
#-----| getArrayBase(): [VariableAccess] (unnamed local variable)
11448+
#-----| Type = [LValueReferenceType] int(&)[2]
11449+
#-----| ValueCategory = prvalue(load)
11450+
#-----| getArrayOffset(): [Literal] 1
11451+
#-----| Type = [LongType] unsigned long
11452+
#-----| Value = [Literal] 1
11453+
#-----| ValueCategory = prvalue
11454+
#-----| getArrayBase().getFullyConverted(): [ArrayToPointerConversion] array to pointer conversion
11455+
#-----| Type = [IntPointerType] int *
11456+
#-----| ValueCategory = prvalue
11457+
#-----| getExpr(): [ReferenceDereferenceExpr] (reference dereference)
11458+
#-----| Type = [ArrayType] int[2]
11459+
#-----| ValueCategory = lvalue
11460+
# 1467| getStmt(1): [ExprStmt] ExprStmt
11461+
# 1467| getExpr(): [AssignExpr] ... = ...
11462+
# 1467| Type = [IntType] int
11463+
# 1467| ValueCategory = lvalue
11464+
# 1467| getLValue(): [VariableAccess] x1
11465+
# 1467| Type = [IntType] int
11466+
# 1467| ValueCategory = lvalue
11467+
# 1467| getRValue(): [Literal] 3
11468+
# 1467| Type = [IntType] int
11469+
# 1467| Value = [Literal] 3
11470+
# 1467| ValueCategory = prvalue
11471+
# 1468| getStmt(2): [DeclStmt] declaration
11472+
# 1468| getDeclarationEntry(0): [VariableDeclarationEntry] definition of rx1
11473+
# 1468| Type = [LValueReferenceType] int &
11474+
# 1468| getVariable().getInitializer(): [Initializer] initializer for rx1
11475+
# 1468| getExpr(): [VariableAccess] x1
11476+
# 1468| Type = [IntType] int
11477+
# 1468| ValueCategory = lvalue
11478+
# 1468| getExpr().getFullyConverted(): [ReferenceToExpr] (reference to)
11479+
# 1468| Type = [LValueReferenceType] int &
11480+
# 1468| ValueCategory = prvalue
11481+
# 1469| getStmt(3): [DeclStmt] declaration
11482+
# 1469| getDeclarationEntry(0): [VariableDeclarationEntry] definition of x
11483+
# 1469| Type = [IntType] int
11484+
# 1469| getVariable().getInitializer(): [Initializer] initializer for x
11485+
# 1469| getExpr(): [VariableAccess] x1
11486+
# 1469| Type = [IntType] int
11487+
# 1469| ValueCategory = prvalue(load)
11488+
# 1472| getStmt(2): [BlockStmt] { ... }
11489+
# 1473| getStmt(0): [DeclStmt] declaration
11490+
# 1473| getDeclarationEntry(0): [VariableDeclarationEntry] definition of unnamed_local_variable
11491+
# 1473| Type = [LValueReferenceType] int(&)[2]
11492+
# 1473| getVariable().getInitializer(): [Initializer] initializer for unnamed_local_variable
11493+
# 1473| getExpr(): [VariableAccess] xs
11494+
# 1473| Type = [ArrayType] int[2]
11495+
# 1473| ValueCategory = lvalue
11496+
# 1473| getExpr().getFullyConverted(): [ReferenceToExpr] (reference to)
11497+
# 1473| Type = [LValueReferenceType] int(&)[2]
11498+
# 1473| ValueCategory = prvalue
11499+
# 1474| getStmt(1): [DeclStmt] declaration
11500+
# 1474| getDeclarationEntry(0): [VariableDeclarationEntry] definition of x0
11501+
# 1474| Type = [LValueReferenceType] int &
11502+
# 1474| getVariable().getInitializer(): [Initializer] initializer for x0
11503+
# 1474| getExpr(): [ArrayExpr] access to array
11504+
# 1474| Type = [IntType] int
11505+
# 1474| ValueCategory = lvalue
11506+
# 1474| getArrayBase(): [VariableAccess] xs
11507+
# 1474| Type = [ArrayType] int[2]
11508+
# 1474| ValueCategory = lvalue
11509+
# 1474| getArrayOffset(): [Literal] 0
11510+
# 1474| Type = [IntType] int
11511+
# 1474| Value = [Literal] 0
11512+
# 1474| ValueCategory = prvalue
11513+
# 1474| getArrayBase().getFullyConverted(): [ArrayToPointerConversion] array to pointer conversion
11514+
# 1474| Type = [IntPointerType] int *
11515+
# 1474| ValueCategory = prvalue
11516+
# 1474| getExpr().getFullyConverted(): [ReferenceToExpr] (reference to)
11517+
# 1474| Type = [LValueReferenceType] int &
11518+
# 1474| ValueCategory = prvalue
11519+
# 1475| getStmt(2): [DeclStmt] declaration
11520+
# 1475| getDeclarationEntry(0): [VariableDeclarationEntry] definition of x1
11521+
# 1475| Type = [LValueReferenceType] int &
11522+
# 1475| getVariable().getInitializer(): [Initializer] initializer for x1
11523+
# 1475| getExpr(): [ArrayExpr] access to array
11524+
# 1475| Type = [IntType] int
11525+
# 1475| ValueCategory = lvalue
11526+
# 1475| getArrayBase(): [VariableAccess] xs
11527+
# 1475| Type = [ArrayType] int[2]
11528+
# 1475| ValueCategory = lvalue
11529+
# 1475| getArrayOffset(): [Literal] 1
11530+
# 1475| Type = [IntType] int
11531+
# 1475| Value = [Literal] 1
11532+
# 1475| ValueCategory = prvalue
11533+
# 1475| getArrayBase().getFullyConverted(): [ArrayToPointerConversion] array to pointer conversion
11534+
# 1475| Type = [IntPointerType] int *
11535+
# 1475| ValueCategory = prvalue
11536+
# 1475| getExpr().getFullyConverted(): [ReferenceToExpr] (reference to)
11537+
# 1475| Type = [LValueReferenceType] int &
11538+
# 1475| ValueCategory = prvalue
11539+
# 1476| getStmt(3): [ExprStmt] ExprStmt
11540+
# 1476| getExpr(): [AssignExpr] ... = ...
11541+
# 1476| Type = [IntType] int
11542+
# 1476| ValueCategory = lvalue
11543+
# 1476| getLValue(): [VariableAccess] x1
11544+
# 1476| Type = [LValueReferenceType] int &
11545+
# 1476| ValueCategory = prvalue(load)
11546+
# 1476| getRValue(): [Literal] 3
11547+
# 1476| Type = [IntType] int
11548+
# 1476| Value = [Literal] 3
11549+
# 1476| ValueCategory = prvalue
11550+
# 1476| getLValue().getFullyConverted(): [ReferenceDereferenceExpr] (reference dereference)
11551+
# 1476| Type = [IntType] int
11552+
# 1476| ValueCategory = lvalue
11553+
# 1477| getStmt(4): [DeclStmt] declaration
11554+
# 1477| getDeclarationEntry(0): [VariableDeclarationEntry] definition of rx1
11555+
# 1477| Type = [LValueReferenceType] int &
11556+
# 1477| getVariable().getInitializer(): [Initializer] initializer for rx1
11557+
# 1477| getExpr(): [VariableAccess] x1
11558+
# 1477| Type = [LValueReferenceType] int &
11559+
# 1477| ValueCategory = prvalue(load)
11560+
# 1477| getExpr().getFullyConverted(): [ReferenceToExpr] (reference to)
11561+
# 1477| Type = [LValueReferenceType] int &
11562+
# 1477| ValueCategory = prvalue
11563+
# 1477| getExpr(): [ReferenceDereferenceExpr] (reference dereference)
11564+
# 1477| Type = [IntType] int
11565+
# 1477| ValueCategory = lvalue
11566+
# 1478| getStmt(5): [DeclStmt] declaration
11567+
# 1478| getDeclarationEntry(0): [VariableDeclarationEntry] definition of x
11568+
# 1478| Type = [IntType] int
11569+
# 1478| getVariable().getInitializer(): [Initializer] initializer for x
11570+
# 1478| getExpr(): [VariableAccess] x1
11571+
# 1478| Type = [LValueReferenceType] int &
11572+
# 1478| ValueCategory = prvalue(load)
11573+
# 1478| getExpr().getFullyConverted(): [ReferenceDereferenceExpr] (reference dereference)
11574+
# 1478| Type = [IntType] int
11575+
# 1478| ValueCategory = prvalue(load)
11576+
# 1480| getStmt(3): [ReturnStmt] return ...
1139311577
perf-regression.cpp:
1139411578
# 4| [CopyAssignmentOperator] Big& Big::operator=(Big const&)
1139511579
# 4| <params>:

cpp/ql/test/library-tests/ir/ir/ir.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1458,4 +1458,25 @@ struct Inheritance_Test_A : public Inheritance_Test_B {
14581458
y = 3;
14591459
}
14601460
};
1461+
1462+
void array_structured_binding() {
1463+
int xs[2] = {1, 2};
1464+
// structured binding use
1465+
{
1466+
auto& [x0, x1] = xs;
1467+
x1 = 3;
1468+
int &rx1 = x1;
1469+
int x = x1;
1470+
}
1471+
// explicit reference version
1472+
{
1473+
auto& unnamed_local_variable = xs;
1474+
auto& x0 = xs[0];
1475+
auto& x1 = xs[1];
1476+
x1 = 3;
1477+
int &rx1 = x1;
1478+
int x = x1;
1479+
}
1480+
}
1481+
14611482
// semmle-extractor-options: -std=c++17 --clang

cpp/ql/test/library-tests/ir/ir/operand_locations.expected

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,7 @@
632632
| file://:0:0:0:0 | Address | &:r0_1 |
633633
| file://:0:0:0:0 | Address | &:r0_1 |
634634
| file://:0:0:0:0 | Address | &:r0_1 |
635+
| file://:0:0:0:0 | Address | &:r0_1 |
635636
| file://:0:0:0:0 | Address | &:r0_2 |
636637
| file://:0:0:0:0 | Address | &:r0_3 |
637638
| file://:0:0:0:0 | Address | &:r0_3 |
@@ -653,6 +654,7 @@
653654
| file://:0:0:0:0 | Address | &:r0_8 |
654655
| file://:0:0:0:0 | Address | &:r0_8 |
655656
| file://:0:0:0:0 | Address | &:r0_8 |
657+
| file://:0:0:0:0 | Address | &:r0_8 |
656658
| file://:0:0:0:0 | Address | &:r0_9 |
657659
| file://:0:0:0:0 | Address | &:r0_9 |
658660
| file://:0:0:0:0 | Address | &:r0_10 |
@@ -682,14 +684,20 @@
682684
| file://:0:0:0:0 | ChiTotal | total:m763_8 |
683685
| file://:0:0:0:0 | ChiTotal | total:m1043_10 |
684686
| file://:0:0:0:0 | ChiTotal | total:m1240_4 |
687+
| file://:0:0:0:0 | Left | r0_4 |
688+
| file://:0:0:0:0 | Left | r0_11 |
685689
| file://:0:0:0:0 | Load | m0_2 |
686690
| file://:0:0:0:0 | Load | m0_2 |
687691
| file://:0:0:0:0 | Load | m0_2 |
688692
| file://:0:0:0:0 | Load | m0_2 |
689693
| file://:0:0:0:0 | Load | m745_6 |
690694
| file://:0:0:0:0 | Load | m754_6 |
691695
| file://:0:0:0:0 | Load | m763_6 |
696+
| file://:0:0:0:0 | Load | m1466_4 |
697+
| file://:0:0:0:0 | Load | m1466_4 |
692698
| file://:0:0:0:0 | Load | ~m1444_6 |
699+
| file://:0:0:0:0 | Right | r0_5 |
700+
| file://:0:0:0:0 | Right | r0_12 |
693701
| file://:0:0:0:0 | SideEffect | m0_4 |
694702
| file://:0:0:0:0 | SideEffect | m0_4 |
695703
| file://:0:0:0:0 | SideEffect | m0_4 |
@@ -716,10 +724,14 @@
716724
| file://:0:0:0:0 | StoreValue | r0_1 |
717725
| file://:0:0:0:0 | StoreValue | r0_1 |
718726
| file://:0:0:0:0 | StoreValue | r0_3 |
727+
| file://:0:0:0:0 | StoreValue | r0_6 |
728+
| file://:0:0:0:0 | StoreValue | r0_13 |
719729
| file://:0:0:0:0 | StoreValue | r0_13 |
720730
| file://:0:0:0:0 | StoreValue | r0_22 |
721731
| file://:0:0:0:0 | StoreValue | r0_22 |
722732
| file://:0:0:0:0 | Unary | r0_1 |
733+
| file://:0:0:0:0 | Unary | r0_2 |
734+
| file://:0:0:0:0 | Unary | r0_3 |
723735
| file://:0:0:0:0 | Unary | r0_5 |
724736
| file://:0:0:0:0 | Unary | r0_5 |
725737
| file://:0:0:0:0 | Unary | r0_6 |
@@ -730,6 +742,8 @@
730742
| file://:0:0:0:0 | Unary | r0_7 |
731743
| file://:0:0:0:0 | Unary | r0_8 |
732744
| file://:0:0:0:0 | Unary | r0_9 |
745+
| file://:0:0:0:0 | Unary | r0_9 |
746+
| file://:0:0:0:0 | Unary | r0_10 |
733747
| file://:0:0:0:0 | Unary | r0_10 |
734748
| file://:0:0:0:0 | Unary | r0_11 |
735749
| file://:0:0:0:0 | Unary | r0_12 |
@@ -6656,6 +6670,70 @@
66566670
| ir.cpp:1458:5:1458:9 | ChiPartial | partial:m1458_5 |
66576671
| ir.cpp:1458:5:1458:9 | ChiTotal | total:m1457_12 |
66586672
| ir.cpp:1458:9:1458:9 | StoreValue | r1458_1 |
6673+
| ir.cpp:1462:6:1462:29 | ChiPartial | partial:m1462_3 |
6674+
| ir.cpp:1462:6:1462:29 | ChiTotal | total:m1462_2 |
6675+
| ir.cpp:1462:6:1462:29 | SideEffect | m1462_3 |
6676+
| ir.cpp:1463:9:1463:10 | Address | &:r1463_1 |
6677+
| ir.cpp:1463:9:1463:10 | Left | r1463_1 |
6678+
| ir.cpp:1463:9:1463:10 | Left | r1463_1 |
6679+
| ir.cpp:1463:16:1463:22 | Address | &:r1463_4 |
6680+
| ir.cpp:1463:16:1463:22 | Address | &:r1463_9 |
6681+
| ir.cpp:1463:16:1463:22 | Right | r1463_3 |
6682+
| ir.cpp:1463:16:1463:22 | Right | r1463_8 |
6683+
| ir.cpp:1463:18:1463:18 | ChiPartial | partial:m1463_6 |
6684+
| ir.cpp:1463:18:1463:18 | ChiTotal | total:m1463_2 |
6685+
| ir.cpp:1463:18:1463:18 | StoreValue | r1463_5 |
6686+
| ir.cpp:1463:21:1463:21 | ChiPartial | partial:m1463_11 |
6687+
| ir.cpp:1463:21:1463:21 | ChiTotal | total:m1463_7 |
6688+
| ir.cpp:1463:21:1463:21 | StoreValue | r1463_10 |
6689+
| ir.cpp:1466:15:1466:15 | Address | &:r1466_1 |
6690+
| ir.cpp:1466:16:1466:16 | Address | &:r1466_5 |
6691+
| ir.cpp:1466:20:1466:20 | Address | &:r1466_6 |
6692+
| ir.cpp:1466:26:1466:27 | StoreValue | r1466_3 |
6693+
| ir.cpp:1466:26:1466:27 | Unary | r1466_2 |
6694+
| ir.cpp:1467:9:1467:10 | Address | &:r1467_2 |
6695+
| ir.cpp:1467:14:1467:14 | StoreValue | r1467_1 |
6696+
| ir.cpp:1468:14:1468:16 | Address | &:r1468_1 |
6697+
| ir.cpp:1468:20:1468:21 | StoreValue | r1468_3 |
6698+
| ir.cpp:1468:20:1468:21 | Unary | r1468_2 |
6699+
| ir.cpp:1469:13:1469:13 | Address | &:r1469_1 |
6700+
| ir.cpp:1469:17:1469:18 | Address | &:r1469_2 |
6701+
| ir.cpp:1469:17:1469:18 | Load | m1467_3 |
6702+
| ir.cpp:1469:17:1469:18 | StoreValue | r1469_3 |
6703+
| ir.cpp:1473:15:1473:36 | Address | &:r1473_1 |
6704+
| ir.cpp:1473:40:1473:41 | StoreValue | r1473_3 |
6705+
| ir.cpp:1473:40:1473:41 | Unary | r1473_2 |
6706+
| ir.cpp:1474:15:1474:16 | Address | &:r1474_1 |
6707+
| ir.cpp:1474:20:1474:21 | Left | r1474_3 |
6708+
| ir.cpp:1474:20:1474:21 | Unary | r1474_2 |
6709+
| ir.cpp:1474:20:1474:24 | StoreValue | r1474_6 |
6710+
| ir.cpp:1474:20:1474:24 | Unary | r1474_5 |
6711+
| ir.cpp:1474:23:1474:23 | Right | r1474_4 |
6712+
| ir.cpp:1475:15:1475:16 | Address | &:r1475_1 |
6713+
| ir.cpp:1475:20:1475:21 | Left | r1475_3 |
6714+
| ir.cpp:1475:20:1475:21 | Unary | r1475_2 |
6715+
| ir.cpp:1475:20:1475:24 | StoreValue | r1475_6 |
6716+
| ir.cpp:1475:20:1475:24 | Unary | r1475_5 |
6717+
| ir.cpp:1475:23:1475:23 | Right | r1475_4 |
6718+
| ir.cpp:1476:9:1476:10 | Address | &:r1476_2 |
6719+
| ir.cpp:1476:9:1476:10 | Address | &:r1476_4 |
6720+
| ir.cpp:1476:9:1476:10 | Load | m1475_7 |
6721+
| ir.cpp:1476:9:1476:10 | Unary | r1476_3 |
6722+
| ir.cpp:1476:9:1476:14 | ChiPartial | partial:m1476_5 |
6723+
| ir.cpp:1476:9:1476:14 | ChiTotal | total:m1463_12 |
6724+
| ir.cpp:1476:14:1476:14 | StoreValue | r1476_1 |
6725+
| ir.cpp:1477:14:1477:16 | Address | &:r1477_1 |
6726+
| ir.cpp:1477:20:1477:21 | Address | &:r1477_2 |
6727+
| ir.cpp:1477:20:1477:21 | Load | m1475_7 |
6728+
| ir.cpp:1477:20:1477:21 | StoreValue | r1477_5 |
6729+
| ir.cpp:1477:20:1477:21 | Unary | r1477_3 |
6730+
| ir.cpp:1477:20:1477:21 | Unary | r1477_4 |
6731+
| ir.cpp:1478:13:1478:13 | Address | &:r1478_1 |
6732+
| ir.cpp:1478:17:1478:18 | Address | &:r1478_2 |
6733+
| ir.cpp:1478:17:1478:18 | Address | &:r1478_3 |
6734+
| ir.cpp:1478:17:1478:18 | Load | m1475_7 |
6735+
| ir.cpp:1478:17:1478:18 | Load | m1476_5 |
6736+
| ir.cpp:1478:17:1478:18 | StoreValue | r1478_4 |
66596737
| perf-regression.cpp:6:3:6:5 | Address | &:r6_5 |
66606738
| perf-regression.cpp:6:3:6:5 | Address | &:r6_5 |
66616739
| perf-regression.cpp:6:3:6:5 | Address | &:r6_7 |

0 commit comments

Comments
 (0)