Skip to content

Commit caf0f28

Browse files
committed
Add IR test for data member structured bindings
1 parent ec2567b commit caf0f28

File tree

4 files changed

+569
-0
lines changed

4 files changed

+569
-0
lines changed

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

Lines changed: 291 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11574,6 +11574,297 @@ ir.cpp:
1157411574
# 1478| Type = [IntType] int
1157511575
# 1478| ValueCategory = prvalue(load)
1157611576
# 1480| getStmt(3): [ReturnStmt] return ...
11577+
# 1482| [CopyAssignmentOperator] StructuredBindingDataMemberStruct& StructuredBindingDataMemberStruct::operator=(StructuredBindingDataMemberStruct const&)
11578+
# 1482| <params>:
11579+
#-----| getParameter(0): [Parameter] (unnamed parameter 0)
11580+
#-----| Type = [LValueReferenceType] const StructuredBindingDataMemberStruct &
11581+
# 1482| [Constructor] void StructuredBindingDataMemberStruct::StructuredBindingDataMemberStruct()
11582+
# 1482| <params>:
11583+
# 1482| <initializations>:
11584+
# 1482| getInitializer(0): [ConstructorFieldInit] constructor init of field i
11585+
# 1482| Type = [IntType] int
11586+
# 1482| ValueCategory = prvalue
11587+
# 1482| getInitializer(1): [ConstructorFieldInit] constructor init of field d
11588+
# 1482| Type = [DoubleType] double
11589+
# 1482| ValueCategory = prvalue
11590+
# 1482| getInitializer(2): [ConstructorFieldInit] constructor init of field r
11591+
# 1482| Type = [LValueReferenceType] int &
11592+
# 1482| ValueCategory = prvalue
11593+
# 1482| getEntryPoint(): [BlockStmt] { ... }
11594+
# 1482| getStmt(0): [ReturnStmt] return ...
11595+
# 1482| [CopyConstructor] void StructuredBindingDataMemberStruct::StructuredBindingDataMemberStruct(StructuredBindingDataMemberStruct const&)
11596+
# 1482| <params>:
11597+
#-----| getParameter(0): [Parameter] (unnamed parameter 0)
11598+
#-----| Type = [LValueReferenceType] const StructuredBindingDataMemberStruct &
11599+
# 1482| <initializations>:
11600+
# 1482| getInitializer(0): [ConstructorFieldInit] constructor init of field i
11601+
# 1482| Type = [IntType] int
11602+
# 1482| ValueCategory = prvalue
11603+
# 1482| getExpr(): [Literal] Unknown literal
11604+
# 1482| Type = [IntType] int
11605+
# 1482| ValueCategory = prvalue
11606+
# 1482| getInitializer(1): [ConstructorFieldInit] constructor init of field d
11607+
# 1482| Type = [DoubleType] double
11608+
# 1482| ValueCategory = prvalue
11609+
# 1482| getExpr(): [Literal] Unknown literal
11610+
# 1482| Type = [DoubleType] double
11611+
# 1482| ValueCategory = prvalue
11612+
# 1482| getInitializer(2): [ConstructorFieldInit] constructor init of field b
11613+
# 1482| Type = [IntType] unsigned int
11614+
# 1482| ValueCategory = prvalue
11615+
# 1482| getExpr(): [Literal] Unknown literal
11616+
# 1482| Type = [IntType] unsigned int
11617+
# 1482| ValueCategory = prvalue
11618+
# 1482| getInitializer(3): [ConstructorFieldInit] constructor init of field r
11619+
# 1482| Type = [LValueReferenceType] int &
11620+
# 1482| ValueCategory = prvalue
11621+
# 1482| getExpr(): [Literal] Unknown literal
11622+
# 1482| Type = [LValueReferenceType] int &
11623+
# 1482| ValueCategory = prvalue
11624+
# 1482| getEntryPoint(): [BlockStmt] { ... }
11625+
# 1482| getStmt(0): [ReturnStmt] return ...
11626+
# 1482| [MoveConstructor] void StructuredBindingDataMemberStruct::StructuredBindingDataMemberStruct(StructuredBindingDataMemberStruct&&)
11627+
# 1482| <params>:
11628+
#-----| getParameter(0): [Parameter] (unnamed parameter 0)
11629+
#-----| Type = [RValueReferenceType] StructuredBindingDataMemberStruct &&
11630+
# 1489| [TopLevelFunction] void data_member_structured_binding()
11631+
# 1489| <params>:
11632+
# 1489| getEntryPoint(): [BlockStmt] { ... }
11633+
# 1490| getStmt(0): [DeclStmt] declaration
11634+
# 1490| getDeclarationEntry(0): [VariableDeclarationEntry] definition of s
11635+
# 1490| Type = [Struct] StructuredBindingDataMemberStruct
11636+
# 1490| getVariable().getInitializer(): [Initializer] initializer for s
11637+
# 1490| getExpr(): [ConstructorCall] call to StructuredBindingDataMemberStruct
11638+
# 1490| Type = [VoidType] void
11639+
# 1490| ValueCategory = prvalue
11640+
# 1492| getStmt(1): [BlockStmt] { ... }
11641+
# 1493| getStmt(0): [DeclStmt] declaration
11642+
# 1493| getDeclarationEntry(0): (no string representation)
11643+
# 1493| Type = [Struct] StructuredBindingDataMemberStruct
11644+
# 1493| getVariable().getInitializer(): [Initializer] initializer for (unnamed local variable)
11645+
# 1493| getExpr(): [VariableAccess] s
11646+
# 1493| Type = [Struct] StructuredBindingDataMemberStruct
11647+
# 1493| ValueCategory = prvalue(load)
11648+
# 1493| getDeclarationEntry(1): [VariableDeclarationEntry] definition of i
11649+
# 1493| Type = [IntType] int
11650+
#-----| getVariable().getInitializer(): [Initializer] initializer for i
11651+
# 1493| getExpr(): [ValueFieldAccess] i
11652+
# 1493| Type = [IntType] int
11653+
# 1493| ValueCategory = lvalue
11654+
# 1493| getQualifier(): [VariableAccess] (unnamed local variable)
11655+
# 1493| Type = [Struct] StructuredBindingDataMemberStruct
11656+
# 1493| ValueCategory = lvalue
11657+
# 1493| getDeclarationEntry(2): [VariableDeclarationEntry] definition of d
11658+
# 1493| Type = [DoubleType] double
11659+
#-----| getVariable().getInitializer(): [Initializer] initializer for d
11660+
# 1493| getExpr(): [ValueFieldAccess] d
11661+
# 1493| Type = [DoubleType] double
11662+
# 1493| ValueCategory = lvalue
11663+
# 1493| getQualifier(): [VariableAccess] (unnamed local variable)
11664+
# 1493| Type = [Struct] StructuredBindingDataMemberStruct
11665+
# 1493| ValueCategory = lvalue
11666+
# 1493| getDeclarationEntry(3): [VariableDeclarationEntry] definition of b
11667+
# 1493| Type = [IntType] unsigned int
11668+
#-----| getVariable().getInitializer(): [Initializer] initializer for b
11669+
# 1493| getExpr(): [ValueFieldAccess] b
11670+
# 1493| Type = [IntType] unsigned int
11671+
# 1493| ValueCategory = lvalue
11672+
# 1493| getQualifier(): [VariableAccess] (unnamed local variable)
11673+
# 1493| Type = [Struct] StructuredBindingDataMemberStruct
11674+
# 1493| ValueCategory = lvalue
11675+
# 1493| getDeclarationEntry(4): [VariableDeclarationEntry] definition of r
11676+
# 1493| Type = [IntType] int
11677+
#-----| getVariable().getInitializer(): [Initializer] initializer for r
11678+
# 1493| getExpr(): [ValueFieldAccess] r
11679+
# 1493| Type = [LValueReferenceType] int &
11680+
# 1493| ValueCategory = prvalue(load)
11681+
# 1493| getQualifier(): [VariableAccess] (unnamed local variable)
11682+
# 1493| Type = [Struct] StructuredBindingDataMemberStruct
11683+
# 1493| ValueCategory = lvalue
11684+
# 1493| getExpr().getFullyConverted(): [ReferenceDereferenceExpr] (reference dereference)
11685+
# 1493| Type = [IntType] int
11686+
# 1493| ValueCategory = lvalue
11687+
# 1494| getStmt(1): [ExprStmt] ExprStmt
11688+
# 1494| getExpr(): [AssignExpr] ... = ...
11689+
# 1494| Type = [DoubleType] double
11690+
# 1494| ValueCategory = lvalue
11691+
# 1494| getLValue(): [VariableAccess] d
11692+
# 1494| Type = [DoubleType] double
11693+
# 1494| ValueCategory = lvalue
11694+
# 1494| getRValue(): [Literal] 4.0
11695+
# 1494| Type = [DoubleType] double
11696+
# 1494| Value = [Literal] 4.0
11697+
# 1494| ValueCategory = prvalue
11698+
# 1495| getStmt(2): [DeclStmt] declaration
11699+
# 1495| getDeclarationEntry(0): [VariableDeclarationEntry] definition of rd
11700+
# 1495| Type = [LValueReferenceType] double &
11701+
# 1495| getVariable().getInitializer(): [Initializer] initializer for rd
11702+
# 1495| getExpr(): [VariableAccess] d
11703+
# 1495| Type = [DoubleType] double
11704+
# 1495| ValueCategory = lvalue
11705+
# 1495| getExpr().getFullyConverted(): [ReferenceToExpr] (reference to)
11706+
# 1495| Type = [LValueReferenceType] double &
11707+
# 1495| ValueCategory = prvalue
11708+
# 1496| getStmt(3): [DeclStmt] declaration
11709+
# 1496| getDeclarationEntry(0): [VariableDeclarationEntry] definition of v
11710+
# 1496| Type = [IntType] int
11711+
# 1496| getVariable().getInitializer(): [Initializer] initializer for v
11712+
# 1496| getExpr(): [VariableAccess] i
11713+
# 1496| Type = [IntType] int
11714+
# 1496| ValueCategory = prvalue(load)
11715+
# 1497| getStmt(4): [ExprStmt] ExprStmt
11716+
# 1497| getExpr(): [AssignExpr] ... = ...
11717+
# 1497| Type = [IntType] int
11718+
# 1497| ValueCategory = lvalue
11719+
# 1497| getLValue(): [VariableAccess] r
11720+
# 1497| Type = [IntType] int
11721+
# 1497| ValueCategory = lvalue
11722+
# 1497| getRValue(): [Literal] 5
11723+
# 1497| Type = [IntType] int
11724+
# 1497| Value = [Literal] 5
11725+
# 1497| ValueCategory = prvalue
11726+
# 1498| getStmt(5): [DeclStmt] declaration
11727+
# 1498| getDeclarationEntry(0): [VariableDeclarationEntry] definition of rr
11728+
# 1498| Type = [LValueReferenceType] int &
11729+
# 1498| getVariable().getInitializer(): [Initializer] initializer for rr
11730+
# 1498| getExpr(): [VariableAccess] r
11731+
# 1498| Type = [IntType] int
11732+
# 1498| ValueCategory = lvalue
11733+
# 1498| getExpr().getFullyConverted(): [ReferenceToExpr] (reference to)
11734+
# 1498| Type = [LValueReferenceType] int &
11735+
# 1498| ValueCategory = prvalue
11736+
# 1499| getStmt(6): [DeclStmt] declaration
11737+
# 1499| getDeclarationEntry(0): [VariableDeclarationEntry] definition of w
11738+
# 1499| Type = [IntType] int
11739+
# 1499| getVariable().getInitializer(): [Initializer] initializer for w
11740+
# 1499| getExpr(): [VariableAccess] r
11741+
# 1499| Type = [IntType] int
11742+
# 1499| ValueCategory = prvalue(load)
11743+
# 1502| getStmt(2): [BlockStmt] { ... }
11744+
# 1503| getStmt(0): [DeclStmt] declaration
11745+
# 1503| getDeclarationEntry(0): [VariableDeclarationEntry] definition of unnamed_local_variable
11746+
# 1503| Type = [Struct] StructuredBindingDataMemberStruct
11747+
# 1503| getVariable().getInitializer(): [Initializer] initializer for unnamed_local_variable
11748+
# 1503| getExpr(): [VariableAccess] s
11749+
# 1503| Type = [Struct] StructuredBindingDataMemberStruct
11750+
# 1503| ValueCategory = prvalue(load)
11751+
# 1504| getStmt(1): [DeclStmt] declaration
11752+
# 1504| getDeclarationEntry(0): [VariableDeclarationEntry] definition of i
11753+
# 1504| Type = [LValueReferenceType] int &
11754+
# 1504| getVariable().getInitializer(): [Initializer] initializer for i
11755+
# 1504| getExpr(): [ValueFieldAccess] i
11756+
# 1504| Type = [IntType] int
11757+
# 1504| ValueCategory = lvalue
11758+
# 1504| getQualifier(): [VariableAccess] unnamed_local_variable
11759+
# 1504| Type = [Struct] StructuredBindingDataMemberStruct
11760+
# 1504| ValueCategory = lvalue
11761+
# 1504| getExpr().getFullyConverted(): [ReferenceToExpr] (reference to)
11762+
# 1504| Type = [LValueReferenceType] int &
11763+
# 1504| ValueCategory = prvalue
11764+
# 1505| getStmt(2): [DeclStmt] declaration
11765+
# 1505| getDeclarationEntry(0): [VariableDeclarationEntry] definition of d
11766+
# 1505| Type = [LValueReferenceType] double &
11767+
# 1505| getVariable().getInitializer(): [Initializer] initializer for d
11768+
# 1505| getExpr(): [ValueFieldAccess] d
11769+
# 1505| Type = [DoubleType] double
11770+
# 1505| ValueCategory = lvalue
11771+
# 1505| getQualifier(): [VariableAccess] unnamed_local_variable
11772+
# 1505| Type = [Struct] StructuredBindingDataMemberStruct
11773+
# 1505| ValueCategory = lvalue
11774+
# 1505| getExpr().getFullyConverted(): [ReferenceToExpr] (reference to)
11775+
# 1505| Type = [LValueReferenceType] double &
11776+
# 1505| ValueCategory = prvalue
11777+
# 1507| getStmt(3): [DeclStmt] declaration
11778+
# 1507| getDeclarationEntry(0): [VariableDeclarationEntry] definition of r
11779+
# 1507| Type = [LValueReferenceType] int &
11780+
# 1507| getVariable().getInitializer(): [Initializer] initializer for r
11781+
# 1507| getExpr(): [ValueFieldAccess] r
11782+
# 1507| Type = [LValueReferenceType] int &
11783+
# 1507| ValueCategory = prvalue(load)
11784+
# 1507| getQualifier(): [VariableAccess] unnamed_local_variable
11785+
# 1507| Type = [Struct] StructuredBindingDataMemberStruct
11786+
# 1507| ValueCategory = lvalue
11787+
# 1507| getExpr().getFullyConverted(): [ReferenceToExpr] (reference to)
11788+
# 1507| Type = [LValueReferenceType] int &
11789+
# 1507| ValueCategory = prvalue
11790+
# 1507| getExpr(): [ReferenceDereferenceExpr] (reference dereference)
11791+
# 1507| Type = [IntType] int
11792+
# 1507| ValueCategory = lvalue
11793+
# 1508| getStmt(4): [ExprStmt] ExprStmt
11794+
# 1508| getExpr(): [AssignExpr] ... = ...
11795+
# 1508| Type = [DoubleType] double
11796+
# 1508| ValueCategory = lvalue
11797+
# 1508| getLValue(): [VariableAccess] d
11798+
# 1508| Type = [LValueReferenceType] double &
11799+
# 1508| ValueCategory = prvalue(load)
11800+
# 1508| getRValue(): [Literal] 4.0
11801+
# 1508| Type = [DoubleType] double
11802+
# 1508| Value = [Literal] 4.0
11803+
# 1508| ValueCategory = prvalue
11804+
# 1508| getLValue().getFullyConverted(): [ReferenceDereferenceExpr] (reference dereference)
11805+
# 1508| Type = [DoubleType] double
11806+
# 1508| ValueCategory = lvalue
11807+
# 1509| getStmt(5): [DeclStmt] declaration
11808+
# 1509| getDeclarationEntry(0): [VariableDeclarationEntry] definition of rd
11809+
# 1509| Type = [LValueReferenceType] double &
11810+
# 1509| getVariable().getInitializer(): [Initializer] initializer for rd
11811+
# 1509| getExpr(): [VariableAccess] d
11812+
# 1509| Type = [LValueReferenceType] double &
11813+
# 1509| ValueCategory = prvalue(load)
11814+
# 1509| getExpr().getFullyConverted(): [ReferenceToExpr] (reference to)
11815+
# 1509| Type = [LValueReferenceType] double &
11816+
# 1509| ValueCategory = prvalue
11817+
# 1509| getExpr(): [ReferenceDereferenceExpr] (reference dereference)
11818+
# 1509| Type = [DoubleType] double
11819+
# 1509| ValueCategory = lvalue
11820+
# 1510| getStmt(6): [DeclStmt] declaration
11821+
# 1510| getDeclarationEntry(0): [VariableDeclarationEntry] definition of v
11822+
# 1510| Type = [IntType] int
11823+
# 1510| getVariable().getInitializer(): [Initializer] initializer for v
11824+
# 1510| getExpr(): [VariableAccess] i
11825+
# 1510| Type = [LValueReferenceType] int &
11826+
# 1510| ValueCategory = prvalue(load)
11827+
# 1510| getExpr().getFullyConverted(): [ReferenceDereferenceExpr] (reference dereference)
11828+
# 1510| Type = [IntType] int
11829+
# 1510| ValueCategory = prvalue(load)
11830+
# 1511| getStmt(7): [ExprStmt] ExprStmt
11831+
# 1511| getExpr(): [AssignExpr] ... = ...
11832+
# 1511| Type = [IntType] int
11833+
# 1511| ValueCategory = lvalue
11834+
# 1511| getLValue(): [VariableAccess] r
11835+
# 1511| Type = [LValueReferenceType] int &
11836+
# 1511| ValueCategory = prvalue(load)
11837+
# 1511| getRValue(): [Literal] 5
11838+
# 1511| Type = [IntType] int
11839+
# 1511| Value = [Literal] 5
11840+
# 1511| ValueCategory = prvalue
11841+
# 1511| getLValue().getFullyConverted(): [ReferenceDereferenceExpr] (reference dereference)
11842+
# 1511| Type = [IntType] int
11843+
# 1511| ValueCategory = lvalue
11844+
# 1512| getStmt(8): [DeclStmt] declaration
11845+
# 1512| getDeclarationEntry(0): [VariableDeclarationEntry] definition of rr
11846+
# 1512| Type = [LValueReferenceType] int &
11847+
# 1512| getVariable().getInitializer(): [Initializer] initializer for rr
11848+
# 1512| getExpr(): [VariableAccess] r
11849+
# 1512| Type = [LValueReferenceType] int &
11850+
# 1512| ValueCategory = prvalue(load)
11851+
# 1512| getExpr().getFullyConverted(): [ReferenceToExpr] (reference to)
11852+
# 1512| Type = [LValueReferenceType] int &
11853+
# 1512| ValueCategory = prvalue
11854+
# 1512| getExpr(): [ReferenceDereferenceExpr] (reference dereference)
11855+
# 1512| Type = [IntType] int
11856+
# 1512| ValueCategory = lvalue
11857+
# 1513| getStmt(9): [DeclStmt] declaration
11858+
# 1513| getDeclarationEntry(0): [VariableDeclarationEntry] definition of w
11859+
# 1513| Type = [IntType] int
11860+
# 1513| getVariable().getInitializer(): [Initializer] initializer for w
11861+
# 1513| getExpr(): [VariableAccess] r
11862+
# 1513| Type = [LValueReferenceType] int &
11863+
# 1513| ValueCategory = prvalue(load)
11864+
# 1513| getExpr().getFullyConverted(): [ReferenceDereferenceExpr] (reference dereference)
11865+
# 1513| Type = [IntType] int
11866+
# 1513| ValueCategory = prvalue(load)
11867+
# 1515| getStmt(3): [ReturnStmt] return ...
1157711868
perf-regression.cpp:
1157811869
# 4| [CopyAssignmentOperator] Big& Big::operator=(Big const&)
1157911870
# 4| <params>:

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,4 +1479,39 @@ void array_structured_binding() {
14791479
}
14801480
}
14811481

1482+
struct StructuredBindingDataMemberStruct {
1483+
int i = 1;
1484+
double d = 2.0;
1485+
unsigned int b : 3;
1486+
int& r = i;
1487+
};
1488+
1489+
void data_member_structured_binding() {
1490+
StructuredBindingDataMemberStruct s;
1491+
// structured binding use
1492+
{
1493+
auto [i, d, b, r] = s;
1494+
d = 4.0;
1495+
double& rd = d;
1496+
int v = i;
1497+
r = 5;
1498+
int& rr = r;
1499+
int w = r;
1500+
}
1501+
// explicit reference version
1502+
{
1503+
auto unnamed_local_variable = s;
1504+
auto& i = unnamed_local_variable.i;
1505+
auto& d = unnamed_local_variable.d;
1506+
// no equivalent for b
1507+
auto& r = unnamed_local_variable.r;
1508+
d = 4.0;
1509+
double& rd = d;
1510+
int v = i;
1511+
r = 5;
1512+
int& rr = r;
1513+
int w = r;
1514+
}
1515+
}
1516+
14821517
// semmle-extractor-options: -std=c++17 --clang

0 commit comments

Comments
 (0)