Skip to content

Commit 57fc3fb

Browse files
committed
Switching from isSeh bools to sublcassed ExceptionEdge.
1 parent defa869 commit 57fc3fb

File tree

4 files changed

+44
-9
lines changed

4 files changed

+44
-9
lines changed

cpp/ql/lib/semmle/code/cpp/ir/implementation/EdgeKind.qll

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ private newtype TEdgeKind =
88
TGotoEdge() or // Single successor (including fall-through)
99
TTrueEdge() or // 'true' edge of conditional branch
1010
TFalseEdge() or // 'false' edge of conditional branch
11-
TExceptionEdge() or // Thrown exception
11+
TCppExceptionEdge() or // Thrown C++ exception
12+
TSehExceptionEdge() or // Thrown C++ exception
1213
TDefaultEdge() or // 'default' label of switch
1314
TCaseEdge(string minValue, string maxValue) {
1415
// Case label of switch
@@ -51,12 +52,33 @@ class FalseEdge extends EdgeKindImpl, TFalseEdge {
5152
final override string toString() { result = "False" }
5253
}
5354

55+
abstract private class ExceptionEdgeImpl extends EdgeKindImpl { }
56+
5457
/**
5558
* An "exception" edge, representing the successor of an instruction when that
5659
* instruction's evaluation throws an exception.
60+
*
61+
* Exception edges are expclitly sublcassed to
62+
* `CppExceptionEdge` and `SehExceptionEdge` only.
63+
* Further sublcasses, if required, should be added privately
64+
* here for IR efficiency.
65+
*/
66+
final class ExceptionEdge = ExceptionEdgeImpl;
67+
68+
/**
69+
* An "exception" edge, representing the successor of an instruction when that
70+
* instruction's evaluation throws an exception for C++ exceptions
5771
*/
58-
class ExceptionEdge extends EdgeKindImpl, TExceptionEdge {
59-
final override string toString() { result = "Exception" }
72+
class CppExceptionEdge extends ExceptionEdgeImpl, TCppExceptionEdge {
73+
final override string toString() { result = "C++ Exception" }
74+
}
75+
76+
/**
77+
* An "exception" edge, representing the successor of an instruction when that
78+
* instruction's evaluation throws an exception for SEH exceptions
79+
*/
80+
class SehExceptionEdge extends ExceptionEdgeImpl, TSehExceptionEdge {
81+
final override string toString() { result = "SEH Exception" }
6082
}
6183

6284
/**
@@ -123,9 +145,22 @@ module EdgeKind {
123145
FalseEdge falseEdge() { result = TFalseEdge() }
124146

125147
/**
126-
* Gets the single instance of the `ExceptionEdge` class.
148+
* Gets an instance of the `CppExceptionEdge` class.
149+
*/
150+
CppExceptionEdge cppExceptionEdge() { result = TCppExceptionEdge() }
151+
152+
/**
153+
* Gets an instance of the `SehExceptionEdge` class.
127154
*/
128-
ExceptionEdge exceptionEdge() { result = TExceptionEdge() }
155+
SehExceptionEdge sehExceptionEdge() { result = TSehExceptionEdge() }
156+
157+
/**
158+
* Gets an instance of the `ExceptionEdge` class.
159+
*/
160+
ExceptionEdge exceptionEdge() {
161+
result = cppExceptionEdge() or
162+
result = sehExceptionEdge()
163+
}
129164

130165
/**
131166
* Gets the single instance of the `DefaultEdge` class.

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
@@ -88,7 +88,7 @@ abstract class TranslatedCall extends TranslatedExpr {
8888
result = this.getParent().getChildSuccessor(this, kind)
8989
or
9090
this.mayThrowException() and
91-
kind = EdgeKind::exceptionEdge(false) and
91+
kind instanceof CppExceptionEdge and
9292
result = this.getParent().getExceptionSuccessorInstruction(any(GotoEdge edge))
9393
)
9494
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3039,7 +3039,7 @@ class TranslatedDestructorsAfterThrow extends TranslatedElement, TTranslatedDest
30393039
or
30403040
// And otherwise, exit this element with an exceptional edge
30413041
not exists(this.getChild(id + 1)) and
3042-
kind = EdgeKind::exceptionEdge(false) and
3042+
kind instanceof CppExceptionEdge and
30433043
result = this.getParent().getExceptionSuccessorInstruction(any(GotoEdge edge))
30443044
)
30453045
}
@@ -3078,7 +3078,7 @@ abstract class TranslatedThrowExpr extends TranslatedNonConstantExpr {
30783078
result = this.getDestructors().getFirstInstruction(kind)
30793079
or
30803080
not exists(this.getDestructors()) and
3081-
kind = EdgeKind::exceptionEdge(false) and
3081+
kind instanceof CppExceptionEdge and
30823082
result = this.getParent().getExceptionSuccessorInstruction(any(GotoEdge edge))
30833083
)
30843084
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -932,7 +932,7 @@ class TranslatedCatchByTypeHandler extends TranslatedHandler {
932932
kind instanceof GotoEdge and
933933
result = this.getParameter().getFirstInstruction(kind)
934934
or
935-
kind = EdgeKind::exceptionEdge(false) and
935+
kind instanceof CppExceptionEdge and
936936
if exists(this.getDestructors())
937937
then result = this.getDestructors().getFirstInstruction(any(GotoEdge edge))
938938
else result = this.getParent().(TranslatedTryStmt).getNextHandler(this, any(GotoEdge edge))

0 commit comments

Comments
 (0)