Skip to content

Commit e1b9d9f

Browse files
authored
Merge pull request #19787 from MathiasVP/add-cpp-exception-edges-out-of-calls
C++: Add exception edges out of calls inside `try` statements
2 parents ac533ea + 9f3569b commit e1b9d9f

File tree

6 files changed

+1307
-1028
lines changed

6 files changed

+1307
-1028
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ private import semmle.code.cpp.ir.implementation.internal.OperandTag
44
private import semmle.code.cpp.ir.internal.CppType
55
private import semmle.code.cpp.models.interfaces.SideEffect
66
private import semmle.code.cpp.models.interfaces.Throwing
7+
private import semmle.code.cpp.models.interfaces.NonThrowing
78
private import InstructionTag
89
private import SideEffects
910
private import TranslatedElement
@@ -366,6 +367,10 @@ class TranslatedFunctionCall extends TranslatedCallExpr, TranslatedDirectCall {
366367
or
367368
exists(MicrosoftTryStmt tryStmt | tryStmt.getStmt() = expr.getEnclosingStmt().getParent*()) and
368369
e instanceof SehExceptionEdge
370+
or
371+
not expr.getTarget() instanceof NonCppThrowingFunction and
372+
exists(TryStmt tryStmt | tryStmt.getStmt() = expr.getEnclosingStmt().getParent*()) and
373+
e instanceof CppExceptionEdge
369374
}
370375

371376
final override predicate mustThrowException(ExceptionEdge e) {

cpp/ql/test/library-tests/controlflow/guards-ir/tests.expected

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,6 @@ astGuardsControl
448448
| test.cpp:31:7:31:13 | ... == ... | false | 34 | 34 |
449449
| test.cpp:31:7:31:13 | ... == ... | true | 30 | 30 |
450450
| test.cpp:31:7:31:13 | ... == ... | true | 31 | 32 |
451-
| test.cpp:42:13:42:20 | call to getABool | false | 53 | 53 |
452451
| test.cpp:42:13:42:20 | call to getABool | true | 43 | 45 |
453452
astGuardsEnsure
454453
| test.c:7:9:7:13 | ... > ... | test.c:7:9:7:9 | x | < | test.c:7:13:7:13 | 0 | 1 | 10 | 11 |
@@ -893,8 +892,6 @@ astGuardsEnsure_const
893892
| test.cpp:31:7:31:13 | ... == ... | test.cpp:31:7:31:13 | ... == ... | == | 1 | 30 | 30 |
894893
| test.cpp:31:7:31:13 | ... == ... | test.cpp:31:7:31:13 | ... == ... | == | 1 | 31 | 32 |
895894
| test.cpp:42:13:42:20 | call to getABool | test.cpp:42:13:42:20 | call to getABool | != | 0 | 43 | 45 |
896-
| test.cpp:42:13:42:20 | call to getABool | test.cpp:42:13:42:20 | call to getABool | != | 1 | 53 | 53 |
897-
| test.cpp:42:13:42:20 | call to getABool | test.cpp:42:13:42:20 | call to getABool | == | 0 | 53 | 53 |
898895
| test.cpp:42:13:42:20 | call to getABool | test.cpp:42:13:42:20 | call to getABool | == | 1 | 43 | 45 |
899896
irGuards
900897
| test.c:7:9:7:13 | CompareGT: ... > ... |
@@ -1301,8 +1298,8 @@ irGuardsControl
13011298
| test.cpp:31:7:31:13 | CompareEQ: ... == ... | false | 34 | 34 |
13021299
| test.cpp:31:7:31:13 | CompareEQ: ... == ... | true | 30 | 30 |
13031300
| test.cpp:31:7:31:13 | CompareEQ: ... == ... | true | 32 | 32 |
1304-
| test.cpp:42:13:42:20 | Call: call to getABool | false | 53 | 53 |
13051301
| test.cpp:42:13:42:20 | Call: call to getABool | true | 44 | 44 |
1302+
| test.cpp:42:13:42:20 | Call: call to getABool | true | 45 | 45 |
13061303
irGuardsEnsure
13071304
| test.c:7:9:7:13 | CompareGT: ... > ... | test.c:7:9:7:9 | Load: x | < | test.c:7:13:7:13 | Constant: 0 | 1 | 11 | 11 |
13081305
| test.c:7:9:7:13 | CompareGT: ... > ... | test.c:7:9:7:9 | Load: x | >= | test.c:7:13:7:13 | Constant: 0 | 1 | 8 | 8 |
@@ -1781,6 +1778,6 @@ irGuardsEnsure_const
17811778
| test.cpp:31:7:31:13 | CompareEQ: ... == ... | test.cpp:31:7:31:13 | CompareEQ: ... == ... | == | 1 | 30 | 30 |
17821779
| test.cpp:31:7:31:13 | CompareEQ: ... == ... | test.cpp:31:7:31:13 | CompareEQ: ... == ... | == | 1 | 32 | 32 |
17831780
| test.cpp:42:13:42:20 | Call: call to getABool | test.cpp:42:13:42:20 | Call: call to getABool | != | 0 | 44 | 44 |
1784-
| test.cpp:42:13:42:20 | Call: call to getABool | test.cpp:42:13:42:20 | Call: call to getABool | != | 1 | 53 | 53 |
1785-
| test.cpp:42:13:42:20 | Call: call to getABool | test.cpp:42:13:42:20 | Call: call to getABool | == | 0 | 53 | 53 |
1781+
| test.cpp:42:13:42:20 | Call: call to getABool | test.cpp:42:13:42:20 | Call: call to getABool | != | 0 | 45 | 45 |
17861782
| test.cpp:42:13:42:20 | Call: call to getABool | test.cpp:42:13:42:20 | Call: call to getABool | == | 1 | 44 | 44 |
1783+
| test.cpp:42:13:42:20 | Call: call to getABool | test.cpp:42:13:42:20 | Call: call to getABool | == | 1 | 45 | 45 |

cpp/ql/test/library-tests/controlflow/guards/GuardsControl.expected

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@
104104
| test.cpp:31:7:31:13 | ... == ... | false | 34 | 34 |
105105
| test.cpp:31:7:31:13 | ... == ... | true | 30 | 30 |
106106
| test.cpp:31:7:31:13 | ... == ... | true | 31 | 32 |
107-
| test.cpp:42:13:42:20 | call to getABool | false | 53 | 53 |
108107
| test.cpp:42:13:42:20 | call to getABool | true | 43 | 45 |
109108
| test.cpp:61:10:61:10 | i | Case[0] | 62 | 64 |
110109
| test.cpp:61:10:61:10 | i | Case[1] | 65 | 66 |

cpp/ql/test/library-tests/controlflow/guards/GuardsEnsure.expected

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -635,8 +635,6 @@ unary
635635
| test.cpp:31:7:31:13 | ... == ... | test.cpp:31:7:31:13 | ... == ... | == | 1 | 30 | 30 |
636636
| test.cpp:31:7:31:13 | ... == ... | test.cpp:31:7:31:13 | ... == ... | == | 1 | 31 | 32 |
637637
| test.cpp:42:13:42:20 | call to getABool | test.cpp:42:13:42:20 | call to getABool | != | 0 | 43 | 45 |
638-
| test.cpp:42:13:42:20 | call to getABool | test.cpp:42:13:42:20 | call to getABool | != | 1 | 53 | 53 |
639-
| test.cpp:42:13:42:20 | call to getABool | test.cpp:42:13:42:20 | call to getABool | == | 0 | 53 | 53 |
640638
| test.cpp:42:13:42:20 | call to getABool | test.cpp:42:13:42:20 | call to getABool | == | 1 | 43 | 45 |
641639
| test.cpp:61:10:61:10 | i | test.cpp:61:10:61:10 | i | == | 0 | 62 | 64 |
642640
| test.cpp:61:10:61:10 | i | test.cpp:61:10:61:10 | i | == | 1 | 65 | 66 |

0 commit comments

Comments
 (0)