Skip to content

Commit 8c87cb8

Browse files
authored
Merge pull request github#16342 from jketema/destructors-cleanup
C++: Don't emit destructor calls as part of 'TranslatedResultCopy' as this has already been done in some other 'TranslatedExpr'.
2 parents c9ce642 + 67fb866 commit 8c87cb8

File tree

4 files changed

+204
-199
lines changed

4 files changed

+204
-199
lines changed

cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/internal/TranslatedExpr.qll

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,11 @@ class TranslatedResultCopy extends TranslatedExpr, TTranslatedResultCopy {
538538
final override predicate producesExprResult() { any() }
539539

540540
private TranslatedCoreExpr getOperand() { result.getExpr() = expr }
541+
542+
override predicate handlesDestructorsExplicitly() {
543+
// The destructor calls will already have been generated by the translation of `expr`.
544+
any()
545+
}
541546
}
542547

543548
class TranslatedCommaExpr extends TranslatedNonConstantExpr {

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

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19565,12 +19565,6 @@ ir.cpp:
1956519565
# 2216| Type = [PlainCharType] char
1956619566
# 2216| Value = [CharLiteral] 97
1956719567
# 2216| ValueCategory = prvalue
19568-
# 2215| getImplicitDestructorCall(0): [DestructorCall] call to ~ClassWithDestructor
19569-
# 2215| Type = [VoidType] void
19570-
# 2215| ValueCategory = prvalue
19571-
# 2215| getQualifier(): [VariableAccess] y
19572-
# 2215| Type = [Class] ClassWithDestructor
19573-
# 2215| ValueCategory = lvalue
1957419568
# 2215| getImplicitDestructorCall(0): [DestructorCall] call to ~vector
1957519569
# 2215| Type = [VoidType] void
1957619570
# 2215| ValueCategory = prvalue
@@ -19580,6 +19574,12 @@ ir.cpp:
1958019574
# 2215| getUpdate().getFullyConverted(): [ReferenceDereferenceExpr] (reference dereference)
1958119575
# 2215| Type = [ClassTemplateInstantiation,Struct] iterator<random_access_iterator_tag, ClassWithDestructor, ptrdiff_t, ClassWithDestructor *, ClassWithDestructor &>
1958219576
# 2215| ValueCategory = lvalue
19577+
# 2215| getImplicitDestructorCall(0): [DestructorCall] call to ~ClassWithDestructor
19578+
# 2215| Type = [VoidType] void
19579+
# 2215| ValueCategory = prvalue
19580+
# 2215| getQualifier(): [VariableAccess] y
19581+
# 2215| Type = [Class] ClassWithDestructor
19582+
# 2215| ValueCategory = lvalue
1958319583
# 2218| getStmt(6): [RangeBasedForStmt] for(...:...) ...
1958419584
# 2218| getInitialization(): [DeclStmt] declaration
1958519585
# 2218| getDeclarationEntry(0): [VariableDeclarationEntry] definition of ys
@@ -19746,12 +19746,6 @@ ir.cpp:
1974619746
# 2233| getQualifier(): [VariableAccess] x
1974719747
# 2233| Type = [Class] ClassWithDestructor
1974819748
# 2233| ValueCategory = lvalue
19749-
# 2218| getImplicitDestructorCall(0): [DestructorCall] call to ~ClassWithDestructor
19750-
# 2218| Type = [VoidType] void
19751-
# 2218| ValueCategory = prvalue
19752-
# 2218| getQualifier(): [VariableAccess] y
19753-
# 2218| Type = [Class] ClassWithDestructor
19754-
# 2218| ValueCategory = lvalue
1975519749
# 2218| getImplicitDestructorCall(0): [DestructorCall] call to ~vector
1975619750
# 2218| Type = [VoidType] void
1975719751
# 2218| ValueCategory = prvalue
@@ -19761,6 +19755,12 @@ ir.cpp:
1976119755
# 2218| getUpdate().getFullyConverted(): [ReferenceDereferenceExpr] (reference dereference)
1976219756
# 2218| Type = [ClassTemplateInstantiation,Struct] iterator<random_access_iterator_tag, ClassWithDestructor, ptrdiff_t, ClassWithDestructor *, ClassWithDestructor &>
1976319757
# 2218| ValueCategory = lvalue
19758+
# 2218| getImplicitDestructorCall(0): [DestructorCall] call to ~ClassWithDestructor
19759+
# 2218| Type = [VoidType] void
19760+
# 2218| ValueCategory = prvalue
19761+
# 2218| getQualifier(): [VariableAccess] y
19762+
# 2218| Type = [Class] ClassWithDestructor
19763+
# 2218| ValueCategory = lvalue
1976419764
# 2224| getStmt(7): [RangeBasedForStmt] for(...:...) ...
1976519765
# 2224| getInitialization(): [DeclStmt] declaration
1976619766
# 2224| getDeclarationEntry(0): [VariableDeclarationEntry] definition of ys
@@ -20038,12 +20038,6 @@ ir.cpp:
2003820038
# 2232| getQualifier(): [VariableAccess] z1
2003920039
# 2232| Type = [Class] ClassWithDestructor
2004020040
# 2232| ValueCategory = lvalue
20041-
# 2229| getImplicitDestructorCall(2): [DestructorCall] call to ~ClassWithDestructor
20042-
# 2229| Type = [VoidType] void
20043-
# 2229| ValueCategory = prvalue
20044-
# 2229| getQualifier(): [VariableAccess] y
20045-
# 2229| Type = [Class] ClassWithDestructor
20046-
# 2229| ValueCategory = lvalue
2004720041
# 2229| getImplicitDestructorCall(0): [DestructorCall] call to ~vector
2004820042
# 2229| Type = [VoidType] void
2004920043
# 2229| ValueCategory = prvalue
@@ -20053,6 +20047,12 @@ ir.cpp:
2005320047
# 2229| getUpdate().getFullyConverted(): [ReferenceDereferenceExpr] (reference dereference)
2005420048
# 2229| Type = [ClassTemplateInstantiation,Struct] iterator<random_access_iterator_tag, ClassWithDestructor, ptrdiff_t, ClassWithDestructor *, ClassWithDestructor &>
2005520049
# 2229| ValueCategory = lvalue
20050+
# 2229| getImplicitDestructorCall(0): [DestructorCall] call to ~ClassWithDestructor
20051+
# 2229| Type = [VoidType] void
20052+
# 2229| ValueCategory = prvalue
20053+
# 2229| getQualifier(): [VariableAccess] y
20054+
# 2229| Type = [Class] ClassWithDestructor
20055+
# 2229| ValueCategory = lvalue
2005620056
# 2233| getStmt(9): [ReturnStmt] return ...
2005720057
# 2233| getImplicitDestructorCall(0): [DestructorCall] call to ~ClassWithDestructor
2005820058
# 2233| Type = [VoidType] void
@@ -20662,15 +20662,15 @@ ir.cpp:
2066220662
# 2309| getQualifier(): [VariableAccess] s2
2066320663
# 2309| Type = [Struct] String
2066420664
# 2309| ValueCategory = lvalue
20665-
# 2307| getImplicitDestructorCall(1): [DestructorCall] call to ~String
20665+
# 2307| getUpdate().getFullyConverted(): [ReferenceDereferenceExpr] (reference dereference)
20666+
# 2307| Type = [ClassTemplateInstantiation,Struct] iterator<random_access_iterator_tag, String, ptrdiff_t, String *, String &>
20667+
# 2307| ValueCategory = lvalue
20668+
# 2307| getImplicitDestructorCall(0): [DestructorCall] call to ~String
2066620669
# 2307| Type = [VoidType] void
2066720670
# 2307| ValueCategory = prvalue
2066820671
# 2307| getQualifier(): [VariableAccess] s
2066920672
# 2307| Type = [Struct] String
2067020673
# 2307| ValueCategory = lvalue
20671-
# 2307| getUpdate().getFullyConverted(): [ReferenceDereferenceExpr] (reference dereference)
20672-
# 2307| Type = [ClassTemplateInstantiation,Struct] iterator<random_access_iterator_tag, String, ptrdiff_t, String *, String &>
20673-
# 2307| ValueCategory = lvalue
2067420674
# 2311| getStmt(3): [ForStmt] for(...;...;...) ...
2067520675
# 2311| getInitialization(): [DeclStmt] declaration
2067620676
# 2311| getDeclarationEntry(0): [VariableDeclarationEntry] definition of s

0 commit comments

Comments
 (0)