Skip to content

Commit fbbd57b

Browse files
committed
C++: Suppress epxr destructors in preparation for temporaries
1 parent 28e1e3a commit fbbd57b

File tree

2 files changed

+37
-38
lines changed

2 files changed

+37
-38
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/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

0 commit comments

Comments
 (0)