Skip to content

Commit d13ea0b

Browse files
authored
Merge pull request #15817 from github/rdmarsh2/suppress-expr-destructors
C++: Suppress implicit destructors on expr in preparation for destructors on temporaries
2 parents 350dab4 + 6972f9b commit d13ea0b

File tree

6 files changed

+37
-56
lines changed

6 files changed

+37
-56
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ private predicate ignoreExprAndDescendants(Expr expr) {
9696
exists(BuiltInVarArgsStart vaStartExpr |
9797
vaStartExpr.getLastNamedParameter().getFullyConverted() = expr
9898
)
99+
or
100+
// suppress destructors of temporary variables until proper support is added for them.
101+
exists(Expr parent | parent.getAnImplicitDestructorCall() = expr)
99102
}
100103

101104
/**
@@ -744,9 +747,13 @@ newtype TTranslatedElement =
744747
// The declaration/initialization part of a `ConditionDeclExpr`
745748
TTranslatedConditionDecl(ConditionDeclExpr expr) { not ignoreExpr(expr) } or
746749
// The side effects of a `Call`
747-
TTranslatedCallSideEffects(CallOrAllocationExpr expr) { not ignoreSideEffects(expr) } or
750+
TTranslatedCallSideEffects(CallOrAllocationExpr expr) {
751+
not ignoreExpr(expr) and
752+
not ignoreSideEffects(expr)
753+
} or
748754
// The non-argument-specific side effect of a `Call`
749755
TTranslatedCallSideEffect(Expr expr, SideEffectOpcode opcode) {
756+
not ignoreExpr(expr) and
750757
not ignoreSideEffects(expr) and
751758
opcode = getCallSideEffectOpcode(expr)
752759
} or
@@ -764,6 +771,7 @@ newtype TTranslatedElement =
764771
// Constructor calls lack a qualifier (`this`) expression, so we need to handle the side effects
765772
// on `*this` without an `Expr`.
766773
TTranslatedStructorQualifierSideEffect(Call call, SideEffectOpcode opcode) {
774+
not ignoreExpr(call) and
767775
not ignoreSideEffects(call) and
768776
call instanceof ConstructorCall and
769777
opcode = getASideEffectOpcode(call, -1)

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

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -97,19 +97,6 @@ abstract class TranslatedExpr extends TranslatedElement {
9797
)
9898
}
9999

100-
final override predicate hasAnImplicitDestructorCall() {
101-
exists(expr.getAnImplicitDestructorCall())
102-
}
103-
104-
final override int getFirstDestructorCallIndex() {
105-
not this.handlesDestructorsExplicitly() and
106-
(
107-
result = max(int childId | exists(this.getChildInternal(childId))) + 1
108-
or
109-
not exists(this.getChildInternal(_)) and result = 0
110-
)
111-
}
112-
113100
final override Locatable getAst() { result = expr }
114101

115102
final override Declaration getFunction() { result = getEnclosingDeclaration(expr) }

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

Lines changed: 28 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -12779,7 +12779,7 @@ ir.cpp:
1277912779
# 2215| r2215_1(glval<bool>) = VariableAddress[b] :
1278012780
# 2215| r2215_2(bool) = Load[b] : &:r2215_1, ~m?
1278112781
# 2215| v2215_3(void) = ConditionalBranch : r2215_2
12782-
#-----| False -> Block 5
12782+
#-----| False -> Block 4
1278312783
#-----| True -> Block 3
1278412784

1278512785
# 2212| Block 1
@@ -12796,44 +12796,35 @@ ir.cpp:
1279612796
# 2216| r2216_3(char *) = Convert : r2216_2
1279712797
# 2216| mu2216_4(char *) = Store[#throw2216:7] : &:r2216_1, r2216_3
1279812798
# 2216| v2216_5(void) = ThrowValue : &:r2216_1, ~m?
12799-
#-----| Exception -> Block 6
12799+
#-----| Exception -> Block 5
1280012800

12801-
# 2219| Block 4
12802-
# 2219| r2219_1(glval<String>) = VariableAddress[s] :
12801+
# 2218| Block 4
12802+
# 2218| r2218_1(glval<String>) = VariableAddress[s2] :
12803+
# 2218| mu2218_2(String) = Uninitialized[s2] : &:r2218_1
12804+
# 2218| r2218_3(glval<unknown>) = FunctionAddress[String] :
12805+
# 2218| v2218_4(void) = Call[String] : func:r2218_3, this:r2218_1
12806+
# 2218| mu2218_5(unknown) = ^CallSideEffect : ~m?
12807+
# 2218| mu2218_6(String) = ^IndirectMayWriteSideEffect[-1] : &:r2218_1
12808+
# 2219| r2219_1(glval<String>) = VariableAddress[s2] :
1280312809
# 2219| r2219_2(glval<unknown>) = FunctionAddress[~String] :
1280412810
# 2219| v2219_3(void) = Call[~String] : func:r2219_2, this:r2219_1
1280512811
# 2219| mu2219_4(unknown) = ^CallSideEffect : ~m?
1280612812
# 2219| v2219_5(void) = ^IndirectReadSideEffect[-1] : &:r2219_1, ~m?
1280712813
# 2219| mu2219_6(String) = ^IndirectMayWriteSideEffect[-1] : &:r2219_1
12808-
#-----| Goto -> Block 5
12809-
12810-
# 2218| Block 5
12811-
# 2218| r2218_1(glval<String>) = VariableAddress[s2] :
12812-
# 2218| mu2218_2(String) = Uninitialized[s2] : &:r2218_1
12813-
# 2218| r2218_3(glval<unknown>) = FunctionAddress[String] :
12814-
# 2218| v2218_4(void) = Call[String] : func:r2218_3, this:r2218_1
12815-
# 2218| mu2218_5(unknown) = ^CallSideEffect : ~m?
12816-
# 2218| mu2218_6(String) = ^IndirectMayWriteSideEffect[-1] : &:r2218_1
12817-
# 2219| r2219_7(glval<String>) = VariableAddress[s2] :
12818-
# 2219| r2219_8(glval<unknown>) = FunctionAddress[~String] :
12819-
# 2219| v2219_9(void) = Call[~String] : func:r2219_8, this:r2219_7
12820-
# 2219| mu2219_10(unknown) = ^CallSideEffect : ~m?
12821-
# 2219| v2219_11(void) = ^IndirectReadSideEffect[-1] : &:r2219_7, ~m?
12822-
# 2219| mu2219_12(String) = ^IndirectMayWriteSideEffect[-1] : &:r2219_7
12823-
# 2219| r2219_13(glval<String>) = VariableAddress[s] :
12824-
# 2219| r2219_14(glval<unknown>) = FunctionAddress[~String] :
12825-
# 2219| v2219_15(void) = Call[~String] : func:r2219_14, this:r2219_13
12826-
# 2219| mu2219_16(unknown) = ^CallSideEffect : ~m?
12827-
# 2219| v2219_17(void) = ^IndirectReadSideEffect[-1] : &:r2219_13, ~m?
12828-
# 2219| mu2219_18(String) = ^IndirectMayWriteSideEffect[-1] : &:r2219_13
12829-
#-----| Goto -> Block 11
12814+
# 2219| r2219_7(glval<String>) = VariableAddress[s] :
12815+
# 2219| r2219_8(glval<unknown>) = FunctionAddress[~String] :
12816+
# 2219| v2219_9(void) = Call[~String] : func:r2219_8, this:r2219_7
12817+
# 2219| mu2219_10(unknown) = ^CallSideEffect : ~m?
12818+
# 2219| v2219_11(void) = ^IndirectReadSideEffect[-1] : &:r2219_7, ~m?
12819+
# 2219| mu2219_12(String) = ^IndirectMayWriteSideEffect[-1] : &:r2219_7
12820+
#-----| Goto -> Block 10
1283012821

12831-
# 2220| Block 6
12822+
# 2220| Block 5
1283212823
# 2220| v2220_1(void) = CatchByType[const char *] :
12833-
#-----| Exception -> Block 8
12834-
#-----| Goto -> Block 7
12824+
#-----| Exception -> Block 7
12825+
#-----| Goto -> Block 6
1283512826

12836-
# 2220| Block 7
12827+
# 2220| Block 6
1283712828
# 2220| r2220_2(glval<char *>) = VariableAddress[s] :
1283812829
# 2220| mu2220_3(char *) = InitializeParameter[s] : &:r2220_2
1283912830
# 2220| r2220_4(char *) = Load[s] : &:r2220_2, ~m?
@@ -12850,25 +12841,25 @@ ir.cpp:
1285012841
# 2221| v2221_10(void) = ThrowValue : &:r2221_1, ~m?
1285112842
#-----| Exception -> Block 2
1285212843

12853-
# 2223| Block 8
12844+
# 2223| Block 7
1285412845
# 2223| v2223_1(void) = CatchByType[const String &] :
12855-
#-----| Exception -> Block 10
12856-
#-----| Goto -> Block 9
12846+
#-----| Exception -> Block 9
12847+
#-----| Goto -> Block 8
1285712848

12858-
# 2223| Block 9
12849+
# 2223| Block 8
1285912850
# 2223| r2223_2(glval<String &>) = VariableAddress[e] :
1286012851
# 2223| mu2223_3(String &) = InitializeParameter[e] : &:r2223_2
1286112852
# 2223| r2223_4(String &) = Load[e] : &:r2223_2, ~m?
1286212853
# 2223| mu2223_5(unknown) = InitializeIndirection[e] : &:r2223_4
1286312854
# 2223| v2223_6(void) = NoOp :
12864-
#-----| Goto -> Block 11
12855+
#-----| Goto -> Block 10
1286512856

12866-
# 2225| Block 10
12857+
# 2225| Block 9
1286712858
# 2225| v2225_1(void) = CatchAny :
1286812859
# 2226| v2226_1(void) = ReThrow :
1286912860
#-----| Exception -> Block 2
1287012861

12871-
# 2228| Block 11
12862+
# 2228| Block 10
1287212863
# 2228| v2228_1(void) = NoOp :
1287312864
# 2212| v2212_9(void) = ReturnVoid :
1287412865
#-----| Goto -> Block 1

cpp/ql/test/library-tests/syntax-zoo/aliased_ssa_consistency.expected

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ sideEffectWithoutPrimary
99
instructionWithoutSuccessor
1010
| ms_try_mix.cpp:35:13:35:19 | ThrowValue: throw ... | Instruction 'ThrowValue: throw ...' has no successors in function '$@'. | ms_try_mix.cpp:29:6:29:19 | void ms_finally_mix(int) | void ms_finally_mix(int) |
1111
| ms_try_mix.cpp:53:5:53:11 | ThrowValue: throw ... | Instruction 'ThrowValue: throw ...' has no successors in function '$@'. | ms_try_mix.cpp:49:6:49:28 | void ms_empty_finally_at_end() | void ms_empty_finally_at_end() |
12-
| statements.cpp:25:5:25:9 | ReThrow: re-throw exception | Instruction 'ReThrow: re-throw exception ' has no successors in function '$@'. | statements.cpp:21:6:21:16 | void early_throw(int) | void early_throw(int) |
1312
| stmt_expr.cpp:27:5:27:15 | Store: ... = ... | Instruction 'Store: ... = ...' has no successors in function '$@'. | stmt_expr.cpp:21:13:21:13 | void stmtexpr::g(int) | void stmtexpr::g(int) |
1413
ambiguousSuccessors
1514
unexplainedLoop

cpp/ql/test/library-tests/syntax-zoo/raw_consistency.expected

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ sideEffectWithoutPrimary
1010
instructionWithoutSuccessor
1111
| ms_try_mix.cpp:35:13:35:19 | ThrowValue: throw ... | Instruction 'ThrowValue: throw ...' has no successors in function '$@'. | ms_try_mix.cpp:29:6:29:19 | void ms_finally_mix(int) | void ms_finally_mix(int) |
1212
| ms_try_mix.cpp:53:5:53:11 | ThrowValue: throw ... | Instruction 'ThrowValue: throw ...' has no successors in function '$@'. | ms_try_mix.cpp:49:6:49:28 | void ms_empty_finally_at_end() | void ms_empty_finally_at_end() |
13-
| statements.cpp:25:5:25:9 | ReThrow: re-throw exception | Instruction 'ReThrow: re-throw exception ' has no successors in function '$@'. | statements.cpp:21:6:21:16 | void early_throw(int) | void early_throw(int) |
14-
| statements.cpp:26:3:26:3 | IndirectMayWriteSideEffect: inner | Instruction 'IndirectMayWriteSideEffect: inner' has no successors in function '$@'. | statements.cpp:21:6:21:16 | void early_throw(int) | void early_throw(int) |
15-
| statements.cpp:28:1:28:1 | IndirectMayWriteSideEffect: before | Instruction 'IndirectMayWriteSideEffect: before' has no successors in function '$@'. | statements.cpp:21:6:21:16 | void early_throw(int) | void early_throw(int) |
1613
| stmt_expr.cpp:27:5:27:15 | Store: ... = ... | Instruction 'Store: ... = ...' has no successors in function '$@'. | stmt_expr.cpp:21:13:21:13 | void stmtexpr::g(int) | void stmtexpr::g(int) |
1714
| stmt_expr.cpp:29:11:32:11 | CopyValue: (statement expression) | Instruction 'CopyValue: (statement expression)' has no successors in function '$@'. | stmt_expr.cpp:21:13:21:13 | void stmtexpr::g(int) | void stmtexpr::g(int) |
1815
| stmt_in_type.cpp:5:53:5:53 | Constant: 1 | Instruction 'Constant: 1' has no successors in function '$@'. | stmt_in_type.cpp:2:6:2:12 | void cpp_fun() | void cpp_fun() |

cpp/ql/test/library-tests/syntax-zoo/unaliased_ssa_consistency.expected

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ sideEffectWithoutPrimary
99
instructionWithoutSuccessor
1010
| ms_try_mix.cpp:35:13:35:19 | ThrowValue: throw ... | Instruction 'ThrowValue: throw ...' has no successors in function '$@'. | ms_try_mix.cpp:29:6:29:19 | void ms_finally_mix(int) | void ms_finally_mix(int) |
1111
| ms_try_mix.cpp:53:5:53:11 | ThrowValue: throw ... | Instruction 'ThrowValue: throw ...' has no successors in function '$@'. | ms_try_mix.cpp:49:6:49:28 | void ms_empty_finally_at_end() | void ms_empty_finally_at_end() |
12-
| statements.cpp:25:5:25:9 | ReThrow: re-throw exception | Instruction 'ReThrow: re-throw exception ' has no successors in function '$@'. | statements.cpp:21:6:21:16 | void early_throw(int) | void early_throw(int) |
1312
| stmt_expr.cpp:27:5:27:15 | Store: ... = ... | Instruction 'Store: ... = ...' has no successors in function '$@'. | stmt_expr.cpp:21:13:21:13 | void stmtexpr::g(int) | void stmtexpr::g(int) |
1413
ambiguousSuccessors
1514
unexplainedLoop

0 commit comments

Comments
 (0)