Skip to content

Commit 1b2813d

Browse files
committed
C++: Also generate an SEH edge for calls in initializers
1 parent 815ae37 commit 1b2813d

File tree

4 files changed

+61
-20
lines changed

4 files changed

+61
-20
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ class TranslatedFunctionCall extends TranslatedCallExpr, TranslatedDirectCall {
364364
final override predicate mayThrowException(ExceptionEdge e) {
365365
this.mustThrowException(e)
366366
or
367-
exists(MicrosoftTryStmt tryStmt | tryStmt.getStmt().getAChild*() = expr) and
367+
exists(MicrosoftTryStmt tryStmt | tryStmt.getStmt() = expr.getEnclosingStmt().getParent*()) and
368368
e instanceof SehExceptionEdge
369369
}
370370

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

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39210,13 +39210,52 @@ try_except.c:
3921039210
# 49| r49_3(int) = Call[i] : func:r49_2
3921139211
# 49| m49_4(unknown) = ^CallSideEffect : ~m46_4
3921239212
# 49| m49_5(unknown) = Chi : total:m46_4, partial:m49_4
39213-
# 49| m49_6(int) = Store[y] : &:r49_1, r49_3
39214-
# 54| v54_1(void) = NoOp :
39215-
# 46| v46_7(void) = ReturnVoid :
39216-
# 46| v46_8(void) = AliasedUse : ~m49_5
39217-
# 46| v46_9(void) = ExitFunction :
39213+
#-----| Goto -> Block 1
39214+
#-----| SEH Exception -> Block 4
39215+
39216+
# 49| Block 1
39217+
# 49| m49_6(int) = Store[y] : &:r49_1, r49_3
39218+
#-----| Goto -> Block 6
39219+
39220+
# 51| Block 2
39221+
# 51| r51_1(int) = Constant[0] :
39222+
# 51| r51_2(bool) = CompareEQ : r51_7, r51_1
39223+
# 51| v51_3(void) = ConditionalBranch : r51_2
39224+
#-----| False -> Block 3
39225+
#-----| True -> Block 7
39226+
39227+
# 51| Block 3
39228+
# 51| r51_4(int) = Constant[1] :
39229+
# 51| r51_5(bool) = CompareEQ : r51_7, r51_4
39230+
# 51| v51_6(void) = ConditionalBranch : r51_5
39231+
#-----| False -> Block 7
39232+
#-----| True -> Block 5
39233+
39234+
# 51| Block 4
39235+
# 51| r51_7(int) = Constant[1] :
39236+
# 51| r51_8(int) = Constant[-1] :
39237+
# 51| r51_9(bool) = CompareEQ : r51_7, r51_8
39238+
# 51| v51_10(void) = ConditionalBranch : r51_9
39239+
#-----| False -> Block 2
39240+
#-----| True -> Block 7
39241+
39242+
# 52| Block 5
39243+
# 52| r52_1(glval<unknown>) = FunctionAddress[sink] :
39244+
# 52| r52_2(glval<int>) = VariableAddress[x] :
39245+
# 52| r52_3(int) = Load[x] : &:r52_2, m47_3
39246+
# 52| v52_4(void) = Call[sink] : func:r52_1, 0:r52_3
39247+
# 52| m52_5(unknown) = ^CallSideEffect : ~m49_5
39248+
# 52| m52_6(unknown) = Chi : total:m49_5, partial:m52_5
39249+
#-----| Goto -> Block 6
39250+
39251+
# 54| Block 6
39252+
# 54| m54_1(unknown) = Phi : from 1:~m49_5, from 5:~m52_6
39253+
# 54| v54_2(void) = NoOp :
39254+
# 46| v46_7(void) = ReturnVoid :
39255+
# 46| v46_8(void) = AliasedUse : ~m54_1
39256+
# 46| v46_9(void) = ExitFunction :
3921839257

39219-
# 46| Block 1
39258+
# 46| Block 7
3922039259
# 46| v46_10(void) = Unreached :
3922139260

3922239261
try_except.cpp:

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ lostReachability
2121
backEdgeCountMismatch
2222
useNotDominatedByDefinition
2323
| ir.cpp:1535:8:1535:8 | Unary | Operand 'Unary' is not dominated by its definition in function '$@'. | ir.cpp:1535:8:1535:8 | void StructuredBindingDataMemberStruct::StructuredBindingDataMemberStruct() | void StructuredBindingDataMemberStruct::StructuredBindingDataMemberStruct() |
24-
| try_except.c:51:13:51:13 | Left | Operand 'Left' is not dominated by its definition in function '$@'. | try_except.c:46:6:46:6 | void j(int) | void j(int) |
25-
| try_except.c:51:13:51:13 | Left | Operand 'Left' is not dominated by its definition in function '$@'. | try_except.c:46:6:46:6 | void j(int) | void j(int) |
2624
switchInstructionWithoutDefaultEdge
2725
notMarkedAsConflated
2826
wronglyMarkedAsConflated

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

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37484,8 +37484,8 @@ try_except.c:
3748437484
# 49| r49_2(glval<unknown>) = FunctionAddress[i] :
3748537485
# 49| r49_3(int) = Call[i] : func:r49_2
3748637486
# 49| mu49_4(unknown) = ^CallSideEffect : ~m?
37487-
# 49| mu49_5(int) = Store[y] : &:r49_1, r49_3
37488-
#-----| Goto -> Block 7
37487+
#-----| Goto -> Block 3
37488+
#-----| SEH Exception -> Block 6
3748937489

3749037490
# 46| Block 1
3749137491
# 46| v46_6(void) = AliasedUse : ~m?
@@ -37495,36 +37495,40 @@ try_except.c:
3749537495
# 46| v46_8(void) = Unwind :
3749637496
#-----| Goto -> Block 1
3749737497

37498-
# 51| Block 3
37498+
# 49| Block 3
37499+
# 49| mu49_5(int) = Store[y] : &:r49_1, r49_3
37500+
#-----| Goto -> Block 8
37501+
37502+
# 51| Block 4
3749937503
# 51| r51_1(int) = Constant[0] :
3750037504
# 51| r51_2(bool) = CompareEQ : r51_7, r51_1
3750137505
# 51| v51_3(void) = ConditionalBranch : r51_2
37502-
#-----| False -> Block 4
37506+
#-----| False -> Block 5
3750337507
#-----| True -> Block 2
3750437508

37505-
# 51| Block 4
37509+
# 51| Block 5
3750637510
# 51| r51_4(int) = Constant[1] :
3750737511
# 51| r51_5(bool) = CompareEQ : r51_7, r51_4
3750837512
# 51| v51_6(void) = ConditionalBranch : r51_5
37509-
#-----| True -> Block 6
37513+
#-----| True -> Block 7
3751037514

37511-
# 51| Block 5
37515+
# 51| Block 6
3751237516
# 51| r51_7(int) = Constant[1] :
3751337517
# 51| r51_8(int) = Constant[-1] :
3751437518
# 51| r51_9(bool) = CompareEQ : r51_7, r51_8
3751537519
# 51| v51_10(void) = ConditionalBranch : r51_9
37516-
#-----| False -> Block 3
37520+
#-----| False -> Block 4
3751737521
#-----| True -> Block 2
3751837522

37519-
# 52| Block 6
37523+
# 52| Block 7
3752037524
# 52| r52_1(glval<unknown>) = FunctionAddress[sink] :
3752137525
# 52| r52_2(glval<int>) = VariableAddress[x] :
3752237526
# 52| r52_3(int) = Load[x] : &:r52_2, ~m?
3752337527
# 52| v52_4(void) = Call[sink] : func:r52_1, 0:r52_3
3752437528
# 52| mu52_5(unknown) = ^CallSideEffect : ~m?
37525-
#-----| Goto -> Block 7
37529+
#-----| Goto -> Block 8
3752637530

37527-
# 54| Block 7
37531+
# 54| Block 8
3752837532
# 54| v54_1(void) = NoOp :
3752937533
# 46| v46_9(void) = ReturnVoid :
3753037534
#-----| Goto -> Block 1

0 commit comments

Comments
 (0)