Skip to content

Commit 339c890

Browse files
authored
Merge pull request #15681 from jketema/destructors6b
C++: Add IR test where the for loop should call destructors at the end of its body
2 parents e13d6cd + 11dc467 commit 339c890

File tree

5 files changed

+788
-380
lines changed

5 files changed

+788
-380
lines changed

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

Lines changed: 197 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -16754,12 +16754,12 @@ ir.cpp:
1675416754
# 2159| Value = [CStyleCast] 98
1675516755
# 2159| ValueCategory = prvalue
1675616756
# 2160| getThen(): [ReturnStmt] return ...
16757-
# 2167| getImplicitDestructorCall(0): [DestructorCall] call to ~ClassWithDestructor
16758-
# 2167| Type = [VoidType] void
16759-
# 2167| ValueCategory = prvalue
16760-
# 2167| getQualifier(): [VariableAccess] x
16761-
# 2167| Type = [Class] ClassWithDestructor
16762-
# 2167| ValueCategory = lvalue
16757+
# 2172| getImplicitDestructorCall(0): [DestructorCall] call to ~ClassWithDestructor
16758+
# 2172| Type = [VoidType] void
16759+
# 2172| ValueCategory = prvalue
16760+
# 2172| getQualifier(): [VariableAccess] x
16761+
# 2172| Type = [Class] ClassWithDestructor
16762+
# 2172| ValueCategory = lvalue
1676316763
# 2157| getUpdate().getFullyConverted(): [ReferenceDereferenceExpr] (reference dereference)
1676416764
# 2157| Type = [NestedStruct] iterator
1676516765
# 2157| ValueCategory = lvalue
@@ -16867,112 +16867,235 @@ ir.cpp:
1686716867
# 2164| Value = [Literal] 1
1686816868
# 2164| ValueCategory = prvalue
1686916869
# 2165| getThen(): [ReturnStmt] return ...
16870-
# 2167| getImplicitDestructorCall(0): [DestructorCall] call to ~ClassWithDestructor
16871-
# 2167| Type = [VoidType] void
16872-
# 2167| ValueCategory = prvalue
16873-
# 2167| getQualifier(): [VariableAccess] x
16874-
# 2167| Type = [Class] ClassWithDestructor
16875-
# 2167| ValueCategory = lvalue
16870+
# 2172| getImplicitDestructorCall(0): [DestructorCall] call to ~ClassWithDestructor
16871+
# 2172| Type = [VoidType] void
16872+
# 2172| ValueCategory = prvalue
16873+
# 2172| getQualifier(): [VariableAccess] x
16874+
# 2172| Type = [Class] ClassWithDestructor
16875+
# 2172| ValueCategory = lvalue
1687616876
# 2163| getUpdate().getFullyConverted(): [ReferenceDereferenceExpr] (reference dereference)
1687716877
# 2163| Type = [NestedStruct] iterator
1687816878
# 2163| ValueCategory = lvalue
16879-
# 2167| getStmt(8): [ReturnStmt] return ...
16880-
# 2167| getImplicitDestructorCall(0): [DestructorCall] call to ~ClassWithDestructor
16881-
# 2167| Type = [VoidType] void
16882-
# 2167| ValueCategory = prvalue
16883-
# 2167| getQualifier(): [VariableAccess] x
16884-
# 2167| Type = [Class] ClassWithDestructor
16885-
# 2167| ValueCategory = lvalue
16886-
# 2169| [TopLevelFunction] void static_variable_with_destructor_1()
16887-
# 2169| <params>:
16888-
# 2169| getEntryPoint(): [BlockStmt] { ... }
16889-
# 2170| getStmt(0): [DeclStmt] declaration
16890-
# 2170| getDeclarationEntry(0): [VariableDeclarationEntry] definition of a
16891-
# 2170| Type = [Class] ClassWithDestructor
16892-
# 2170| getVariable().getInitializer(): [Initializer] initializer for a
16893-
# 2170| getExpr(): [ConstructorCall] call to ClassWithDestructor
16894-
# 2170| Type = [VoidType] void
16895-
# 2170| ValueCategory = prvalue
16896-
# 2171| getStmt(1): [DeclStmt] declaration
16897-
# 2171| getDeclarationEntry(0): [VariableDeclarationEntry] definition of b
16898-
# 2171| Type = [Class] ClassWithDestructor
16899-
#-----| getVariable().getInitializer(): [Initializer] initializer for b
16900-
#-----| getExpr(): [ConstructorCall] call to ClassWithDestructor
16901-
#-----| Type = [VoidType] void
16902-
#-----| ValueCategory = prvalue
16903-
# 2172| getStmt(2): [ReturnStmt] return ...
16879+
# 2168| getStmt(8): [RangeBasedForStmt] for(...:...) ...
16880+
# 2168| getInitialization(): [DeclStmt] declaration
16881+
# 2168| getDeclarationEntry(0): [VariableDeclarationEntry] definition of ys
16882+
# 2168| Type = [ClassTemplateInstantiation,Struct] vector<ClassWithDestructor>
16883+
# 2168| getVariable().getInitializer(): [Initializer] initializer for ys
16884+
# 2168| getExpr(): [ConstructorCall] call to vector
16885+
# 2168| Type = [VoidType] void
16886+
# 2168| ValueCategory = prvalue
16887+
# 2168| getArgument(0): [VariableAccess] x
16888+
# 2168| Type = [Class] ClassWithDestructor
16889+
# 2168| ValueCategory = prvalue(load)
16890+
# 2168| getArgument(0).getFullyConverted(): [TemporaryObjectExpr] temporary object
16891+
# 2168| Type = [Class] ClassWithDestructor
16892+
# 2168| ValueCategory = lvalue
16893+
# 2168| getChild(1): [DeclStmt] declaration
16894+
# 2168| getDeclarationEntry(0): [VariableDeclarationEntry] declaration of (__range)
16895+
# 2168| Type = [LValueReferenceType] vector<ClassWithDestructor> &
16896+
#-----| getVariable().getInitializer(): [Initializer] initializer for (__range)
16897+
# 2168| getExpr(): [VariableAccess] ys
16898+
# 2168| Type = [ClassTemplateInstantiation,Struct] vector<ClassWithDestructor>
16899+
# 2168| ValueCategory = lvalue
16900+
# 2168| getExpr().getFullyConverted(): [ReferenceToExpr] (reference to)
16901+
# 2168| Type = [LValueReferenceType] vector<ClassWithDestructor> &
16902+
# 2168| ValueCategory = prvalue
16903+
# 2168| getBeginEndDeclaration(): [DeclStmt] declaration
16904+
# 2168| getDeclarationEntry(0): [VariableDeclarationEntry] declaration of (__begin)
16905+
# 2168| Type = [NestedStruct] iterator
16906+
#-----| getVariable().getInitializer(): [Initializer] initializer for (__begin)
16907+
# 2168| getExpr(): [FunctionCall] call to begin
16908+
# 2168| Type = [NestedStruct] iterator
16909+
# 2168| ValueCategory = prvalue
16910+
# 2168| getQualifier(): [VariableAccess] (__range)
16911+
# 2168| Type = [LValueReferenceType] vector<ClassWithDestructor> &
16912+
# 2168| ValueCategory = prvalue(load)
16913+
#-----| getQualifier().getFullyConverted(): [CStyleCast] (const vector<ClassWithDestructor>)...
16914+
#-----| Conversion = [GlvalueConversion] glvalue conversion
16915+
#-----| Type = [SpecifiedType] const vector<ClassWithDestructor>
16916+
#-----| ValueCategory = lvalue
16917+
#-----| getExpr(): [ReferenceDereferenceExpr] (reference dereference)
16918+
#-----| Type = [ClassTemplateInstantiation,Struct] vector<ClassWithDestructor>
16919+
#-----| ValueCategory = lvalue
16920+
# 2168| getDeclarationEntry(1): [VariableDeclarationEntry] declaration of (__end)
16921+
# 2168| Type = [NestedStruct] iterator
16922+
#-----| getVariable().getInitializer(): [Initializer] initializer for (__end)
16923+
# 2168| getExpr(): [FunctionCall] call to end
16924+
# 2168| Type = [NestedStruct] iterator
16925+
# 2168| ValueCategory = prvalue
16926+
# 2168| getQualifier(): [VariableAccess] (__range)
16927+
# 2168| Type = [LValueReferenceType] vector<ClassWithDestructor> &
16928+
# 2168| ValueCategory = prvalue(load)
16929+
#-----| getQualifier().getFullyConverted(): [CStyleCast] (const vector<ClassWithDestructor>)...
16930+
#-----| Conversion = [GlvalueConversion] glvalue conversion
16931+
#-----| Type = [SpecifiedType] const vector<ClassWithDestructor>
16932+
#-----| ValueCategory = lvalue
16933+
#-----| getExpr(): [ReferenceDereferenceExpr] (reference dereference)
16934+
#-----| Type = [ClassTemplateInstantiation,Struct] vector<ClassWithDestructor>
16935+
#-----| ValueCategory = lvalue
16936+
# 2168| getCondition(): [FunctionCall] call to operator!=
16937+
# 2168| Type = [BoolType] bool
16938+
# 2168| ValueCategory = prvalue
16939+
# 2168| getQualifier(): [VariableAccess] (__begin)
16940+
# 2168| Type = [NestedStruct] iterator
16941+
# 2168| ValueCategory = lvalue
16942+
# 2168| getArgument(0): [VariableAccess] (__end)
16943+
# 2168| Type = [NestedStruct] iterator
16944+
# 2168| ValueCategory = prvalue(load)
16945+
#-----| getQualifier().getFullyConverted(): [CStyleCast] (const iterator)...
16946+
#-----| Conversion = [GlvalueConversion] glvalue conversion
16947+
#-----| Type = [SpecifiedType] const iterator
16948+
#-----| ValueCategory = lvalue
16949+
# 2168| getUpdate(): [FunctionCall] call to operator++
16950+
# 2168| Type = [LValueReferenceType] iterator &
16951+
# 2168| ValueCategory = prvalue
16952+
# 2168| getQualifier(): [VariableAccess] (__begin)
16953+
# 2168| Type = [NestedStruct] iterator
16954+
# 2168| ValueCategory = lvalue
16955+
# 2168| getChild(5): [DeclStmt] declaration
16956+
# 2168| getDeclarationEntry(0): [VariableDeclarationEntry] definition of y
16957+
# 2168| Type = [Class] ClassWithDestructor
16958+
# 2168| getVariable().getInitializer(): [Initializer] initializer for y
16959+
# 2168| getExpr(): [OverloadedPointerDereferenceExpr] call to operator*
16960+
# 2168| Type = [LValueReferenceType] ClassWithDestructor &
16961+
# 2168| ValueCategory = prvalue
16962+
# 2168| getQualifier(): [VariableAccess] (__begin)
16963+
# 2168| Type = [NestedStruct] iterator
16964+
# 2168| ValueCategory = lvalue
16965+
#-----| getQualifier().getFullyConverted(): [CStyleCast] (const iterator)...
16966+
#-----| Conversion = [GlvalueConversion] glvalue conversion
16967+
#-----| Type = [SpecifiedType] const iterator
16968+
#-----| ValueCategory = lvalue
16969+
# 2168| getExpr().getFullyConverted(): [ReferenceDereferenceExpr] (reference dereference)
16970+
# 2168| Type = [Class] ClassWithDestructor
16971+
# 2168| ValueCategory = prvalue(load)
16972+
# 2168| getStmt(): [BlockStmt] { ... }
16973+
# 2169| getStmt(0): [DeclStmt] declaration
16974+
# 2169| getDeclarationEntry(0): [VariableDeclarationEntry] definition of z1
16975+
# 2169| Type = [Class] ClassWithDestructor
16976+
# 2169| getVariable().getInitializer(): [Initializer] initializer for z1
16977+
# 2169| getExpr(): [ConstructorCall] call to ClassWithDestructor
16978+
# 2169| Type = [VoidType] void
16979+
# 2169| ValueCategory = prvalue
16980+
# 2170| getStmt(1): [DeclStmt] declaration
16981+
# 2170| getDeclarationEntry(0): [VariableDeclarationEntry] definition of z2
16982+
# 2170| Type = [Class] ClassWithDestructor
16983+
# 2170| getVariable().getInitializer(): [Initializer] initializer for z2
16984+
# 2170| getExpr(): [ConstructorCall] call to ClassWithDestructor
16985+
# 2170| Type = [VoidType] void
16986+
# 2170| ValueCategory = prvalue
16987+
# 2171| getImplicitDestructorCall(0): [DestructorCall] call to ~ClassWithDestructor
16988+
# 2171| Type = [VoidType] void
16989+
# 2171| ValueCategory = prvalue
16990+
# 2171| getQualifier(): [VariableAccess] z2
16991+
# 2171| Type = [Class] ClassWithDestructor
16992+
# 2171| ValueCategory = lvalue
16993+
# 2171| getImplicitDestructorCall(1): [DestructorCall] call to ~ClassWithDestructor
16994+
# 2171| Type = [VoidType] void
16995+
# 2171| ValueCategory = prvalue
16996+
# 2171| getQualifier(): [VariableAccess] z1
16997+
# 2171| Type = [Class] ClassWithDestructor
16998+
# 2171| ValueCategory = lvalue
16999+
# 2168| getUpdate().getFullyConverted(): [ReferenceDereferenceExpr] (reference dereference)
17000+
# 2168| Type = [NestedStruct] iterator
17001+
# 2168| ValueCategory = lvalue
17002+
# 2172| getStmt(9): [ReturnStmt] return ...
1690417003
# 2172| getImplicitDestructorCall(0): [DestructorCall] call to ~ClassWithDestructor
1690517004
# 2172| Type = [VoidType] void
1690617005
# 2172| ValueCategory = prvalue
16907-
# 2172| getQualifier(): [VariableAccess] a
17006+
# 2172| getQualifier(): [VariableAccess] x
1690817007
# 2172| Type = [Class] ClassWithDestructor
1690917008
# 2172| ValueCategory = lvalue
16910-
# 2174| [TopLevelFunction] void static_variable_with_destructor_2()
17009+
# 2174| [TopLevelFunction] void static_variable_with_destructor_1()
1691117010
# 2174| <params>:
1691217011
# 2174| getEntryPoint(): [BlockStmt] { ... }
1691317012
# 2175| getStmt(0): [DeclStmt] declaration
1691417013
# 2175| getDeclarationEntry(0): [VariableDeclarationEntry] definition of a
1691517014
# 2175| Type = [Class] ClassWithDestructor
16916-
#-----| getVariable().getInitializer(): [Initializer] initializer for a
16917-
#-----| getExpr(): [ConstructorCall] call to ClassWithDestructor
16918-
#-----| Type = [VoidType] void
16919-
#-----| ValueCategory = prvalue
17015+
# 2175| getVariable().getInitializer(): [Initializer] initializer for a
17016+
# 2175| getExpr(): [ConstructorCall] call to ClassWithDestructor
17017+
# 2175| Type = [VoidType] void
17018+
# 2175| ValueCategory = prvalue
1692017019
# 2176| getStmt(1): [DeclStmt] declaration
1692117020
# 2176| getDeclarationEntry(0): [VariableDeclarationEntry] definition of b
1692217021
# 2176| Type = [Class] ClassWithDestructor
16923-
# 2176| getVariable().getInitializer(): [Initializer] initializer for b
16924-
# 2176| getExpr(): [ConstructorCall] call to ClassWithDestructor
16925-
# 2176| Type = [VoidType] void
16926-
# 2176| ValueCategory = prvalue
17022+
#-----| getVariable().getInitializer(): [Initializer] initializer for b
17023+
#-----| getExpr(): [ConstructorCall] call to ClassWithDestructor
17024+
#-----| Type = [VoidType] void
17025+
#-----| ValueCategory = prvalue
1692717026
# 2177| getStmt(2): [ReturnStmt] return ...
1692817027
# 2177| getImplicitDestructorCall(0): [DestructorCall] call to ~ClassWithDestructor
1692917028
# 2177| Type = [VoidType] void
1693017029
# 2177| ValueCategory = prvalue
16931-
# 2177| getQualifier(): [VariableAccess] b
17030+
# 2177| getQualifier(): [VariableAccess] a
1693217031
# 2177| Type = [Class] ClassWithDestructor
1693317032
# 2177| ValueCategory = lvalue
16934-
# 2179| [TopLevelFunction] void static_variable_with_destructor_3()
17033+
# 2179| [TopLevelFunction] void static_variable_with_destructor_2()
1693517034
# 2179| <params>:
1693617035
# 2179| getEntryPoint(): [BlockStmt] { ... }
1693717036
# 2180| getStmt(0): [DeclStmt] declaration
1693817037
# 2180| getDeclarationEntry(0): [VariableDeclarationEntry] definition of a
1693917038
# 2180| Type = [Class] ClassWithDestructor
16940-
# 2180| getVariable().getInitializer(): [Initializer] initializer for a
16941-
# 2180| getExpr(): [ConstructorCall] call to ClassWithDestructor
16942-
# 2180| Type = [VoidType] void
16943-
# 2180| ValueCategory = prvalue
17039+
#-----| getVariable().getInitializer(): [Initializer] initializer for a
17040+
#-----| getExpr(): [ConstructorCall] call to ClassWithDestructor
17041+
#-----| Type = [VoidType] void
17042+
#-----| ValueCategory = prvalue
1694417043
# 2181| getStmt(1): [DeclStmt] declaration
1694517044
# 2181| getDeclarationEntry(0): [VariableDeclarationEntry] definition of b
1694617045
# 2181| Type = [Class] ClassWithDestructor
1694717046
# 2181| getVariable().getInitializer(): [Initializer] initializer for b
1694817047
# 2181| getExpr(): [ConstructorCall] call to ClassWithDestructor
1694917048
# 2181| Type = [VoidType] void
1695017049
# 2181| ValueCategory = prvalue
16951-
# 2182| getStmt(2): [DeclStmt] declaration
16952-
# 2182| getDeclarationEntry(0): [VariableDeclarationEntry] definition of c
16953-
# 2182| Type = [Class] ClassWithDestructor
17050+
# 2182| getStmt(2): [ReturnStmt] return ...
17051+
# 2182| getImplicitDestructorCall(0): [DestructorCall] call to ~ClassWithDestructor
17052+
# 2182| Type = [VoidType] void
17053+
# 2182| ValueCategory = prvalue
17054+
# 2182| getQualifier(): [VariableAccess] b
17055+
# 2182| Type = [Class] ClassWithDestructor
17056+
# 2182| ValueCategory = lvalue
17057+
# 2184| [TopLevelFunction] void static_variable_with_destructor_3()
17058+
# 2184| <params>:
17059+
# 2184| getEntryPoint(): [BlockStmt] { ... }
17060+
# 2185| getStmt(0): [DeclStmt] declaration
17061+
# 2185| getDeclarationEntry(0): [VariableDeclarationEntry] definition of a
17062+
# 2185| Type = [Class] ClassWithDestructor
17063+
# 2185| getVariable().getInitializer(): [Initializer] initializer for a
17064+
# 2185| getExpr(): [ConstructorCall] call to ClassWithDestructor
17065+
# 2185| Type = [VoidType] void
17066+
# 2185| ValueCategory = prvalue
17067+
# 2186| getStmt(1): [DeclStmt] declaration
17068+
# 2186| getDeclarationEntry(0): [VariableDeclarationEntry] definition of b
17069+
# 2186| Type = [Class] ClassWithDestructor
17070+
# 2186| getVariable().getInitializer(): [Initializer] initializer for b
17071+
# 2186| getExpr(): [ConstructorCall] call to ClassWithDestructor
17072+
# 2186| Type = [VoidType] void
17073+
# 2186| ValueCategory = prvalue
17074+
# 2187| getStmt(2): [DeclStmt] declaration
17075+
# 2187| getDeclarationEntry(0): [VariableDeclarationEntry] definition of c
17076+
# 2187| Type = [Class] ClassWithDestructor
1695417077
#-----| getVariable().getInitializer(): [Initializer] initializer for c
1695517078
#-----| getExpr(): [ConstructorCall] call to ClassWithDestructor
1695617079
#-----| Type = [VoidType] void
1695717080
#-----| ValueCategory = prvalue
16958-
# 2183| getStmt(3): [ReturnStmt] return ...
16959-
# 2183| getImplicitDestructorCall(0): [DestructorCall] call to ~ClassWithDestructor
16960-
# 2183| Type = [VoidType] void
16961-
# 2183| ValueCategory = prvalue
16962-
# 2183| getQualifier(): [VariableAccess] b
16963-
# 2183| Type = [Class] ClassWithDestructor
16964-
# 2183| ValueCategory = lvalue
16965-
# 2183| getImplicitDestructorCall(1): [DestructorCall] call to ~ClassWithDestructor
16966-
# 2183| Type = [VoidType] void
16967-
# 2183| ValueCategory = prvalue
16968-
# 2183| getQualifier(): [VariableAccess] a
16969-
# 2183| Type = [Class] ClassWithDestructor
16970-
# 2183| ValueCategory = lvalue
16971-
# 2185| [GlobalVariable] ClassWithDestructor global_class_with_destructor
16972-
# 2185| getInitializer(): [Initializer] initializer for global_class_with_destructor
16973-
# 2185| getExpr(): [ConstructorCall] call to ClassWithDestructor
16974-
# 2185| Type = [VoidType] void
16975-
# 2185| ValueCategory = prvalue
17081+
# 2188| getStmt(3): [ReturnStmt] return ...
17082+
# 2188| getImplicitDestructorCall(0): [DestructorCall] call to ~ClassWithDestructor
17083+
# 2188| Type = [VoidType] void
17084+
# 2188| ValueCategory = prvalue
17085+
# 2188| getQualifier(): [VariableAccess] b
17086+
# 2188| Type = [Class] ClassWithDestructor
17087+
# 2188| ValueCategory = lvalue
17088+
# 2188| getImplicitDestructorCall(1): [DestructorCall] call to ~ClassWithDestructor
17089+
# 2188| Type = [VoidType] void
17090+
# 2188| ValueCategory = prvalue
17091+
# 2188| getQualifier(): [VariableAccess] a
17092+
# 2188| Type = [Class] ClassWithDestructor
17093+
# 2188| ValueCategory = lvalue
17094+
# 2190| [GlobalVariable] ClassWithDestructor global_class_with_destructor
17095+
# 2190| getInitializer(): [Initializer] initializer for global_class_with_destructor
17096+
# 2190| getExpr(): [ConstructorCall] call to ClassWithDestructor
17097+
# 2190| Type = [VoidType] void
17098+
# 2190| ValueCategory = prvalue
1697617099
perf-regression.cpp:
1697717100
# 4| [CopyAssignmentOperator] Big& Big::operator=(Big const&)
1697817101
# 4| <params>:

0 commit comments

Comments
 (0)