Skip to content

Commit

Permalink
changing isSEH to isSeh to match conventions.
Browse files Browse the repository at this point in the history
  • Loading branch information
bdrodes committed Oct 24, 2024
1 parent 9dc776e commit 3f01e4d
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 65 deletions.
14 changes: 7 additions & 7 deletions cpp/ql/lib/semmle/code/cpp/ir/implementation/EdgeKind.qll
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ private newtype TEdgeKind =
TGotoEdge() or // Single successor (including fall-through)
TTrueEdge() or // 'true' edge of conditional branch
TFalseEdge() or // 'false' edge of conditional branch
TExceptionEdge(Boolean isSEH) or // Thrown exception, true for SEH exceptions, false otherwise
TExceptionEdge(Boolean isSeh) or // Thrown exception, true for SEH exceptions, false otherwise
TDefaultEdge() or // 'default' label of switch
TCaseEdge(string minValue, string maxValue) {
// Case label of switch
Expand Down Expand Up @@ -55,17 +55,17 @@ class FalseEdge extends EdgeKind, TFalseEdge {
* instruction's evaluation throws an exception.
*/
class ExceptionEdge extends EdgeKind, TExceptionEdge {
boolean isSEH; //true for Structured Exception Handling, false for C++ exceptions
boolean isSeh; //true for Structured Exception Handling, false for C++ exceptions

ExceptionEdge() { this = TExceptionEdge(isSEH) }
ExceptionEdge() { this = TExceptionEdge(isSeh) }

/**
* Holds if the exception is a Structured Exception Handling (SEH) exception.
*/
final predicate isSEH() { isSEH = true }
final predicate isSeh() { isSeh = true }

final override string toString() {
if isSEH = true then result = "SEH Exception" else result = "C++ Exception"
if isSeh = true then result = "SEH Exception" else result = "C++ Exception"
}
}

Expand Down Expand Up @@ -134,9 +134,9 @@ module EdgeKind {

/**
* Gets the instance of the `ExceptionEdge` class.
* `isSEH` is true if the exception is an SEH exception, and false for a C++ edge.
* `isSeh` is true if the exception is an SEH exception, and false for a C++ edge.
*/
ExceptionEdge exceptionEdge(boolean isSEH) { result = TExceptionEdge(isSEH) }
ExceptionEdge exceptionEdge(boolean isSeh) { result = TExceptionEdge(isSeh) }

/**
* Gets the single instance of the `DefaultEdge` class.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,28 +85,28 @@ abstract class TranslatedCall extends TranslatedExpr {
this.getEnclosingFunction().getFunction() = instr.getEnclosingFunction()
)
else
exists(boolean isSEH | kind = exceptionEdge(isSEH) |
exists(boolean isSeh | kind = exceptionEdge(isSeh) |
// Call throw behavior is resolved from most restricted to least restricted in order
// if there are conflicting throwing specificaitons for a function.
// Enumerating all scenarios to be explicit.
(
// If the call is known to never throw, regardless of other defined throwing behavior,
// do not generate any exception edges, only an ordinary successor
if this.(TranslatedCallExpr).neverRaiseException(isSEH)
if this.(TranslatedCallExpr).neverRaiseException(isSeh)
then result = this.getParent().getChildSuccessor(this, any(GotoEdge edge))
else
// If the call is known to always throw, regardless of other defined throwing behavior,
// only generate an exception edge.
if this.(TranslatedCallExpr).alwaysRaiseException(isSEH)
if this.(TranslatedCallExpr).alwaysRaiseException(isSeh)
then
result = this.getParent().getExceptionSuccessorInstruction(any(GotoEdge edge), isSEH)
result = this.getParent().getExceptionSuccessorInstruction(any(GotoEdge edge), isSeh)
else
if this.(TranslatedCallExpr).mayRaiseException(isSEH)
if this.(TranslatedCallExpr).mayRaiseException(isSeh)
then (
// if the call is known to conditionally throw, generate both an exception edge and an
// ordinary successor
result =
this.getParent().getExceptionSuccessorInstruction(any(GotoEdge edge), isSEH)
this.getParent().getExceptionSuccessorInstruction(any(GotoEdge edge), isSeh)
or
result = this.getParent().getChildSuccessor(this, kind)
) else
Expand Down Expand Up @@ -145,23 +145,23 @@ abstract class TranslatedCall extends TranslatedExpr {
* and `neverRaiseException` may conflict (e.g., all hold for a given target).
* Conflicting results are resolved during IR generation.
*/
abstract predicate alwaysRaiseException(boolean isSEH);
abstract predicate alwaysRaiseException(boolean isSeh);

/**
* The call target is known to conditionally raise an exception.
* Note that `alwaysRaiseException`, `mayRaiseException`,
* and `neverRaiseException` may conflict (e.g., all hold for a given target).
* Conflicting results are resolved during IR generation.
*/
abstract predicate mayRaiseException(boolean isSEH);
abstract predicate mayRaiseException(boolean isSeh);

/**
* The call target is known to never raise an exception.
* Note that `alwaysRaiseException`, `mayRaiseException`,
* and `neverRaiseException` may conflict (e.g., all hold for a given target).
* Conflicting results are resolved during IR generation.
*/

Check warning

Code scanning / CodeQL

Predicate QLDoc style. Warning

The QLDoc for a predicate without a result should start with 'Holds'.
abstract predicate neverRaiseException(boolean isSEH);
abstract predicate neverRaiseException(boolean isSeh);

/**
* Gets the result type of the call.
Expand Down Expand Up @@ -362,27 +362,27 @@ abstract class TranslatedCallExpr extends TranslatedNonConstantExpr, TranslatedC
tag = CallTargetTag() and result = expr.getTarget()
}

override predicate alwaysRaiseException(boolean isSEH) {
override predicate alwaysRaiseException(boolean isSeh) {
exists(ThrowingFunction f | f = expr.getTarget() |
f.alwaysRaisesException() and f.isSEH() and isSEH = true
f.alwaysRaisesException() and f.isSeh() and isSeh = true
or
f.alwaysRaisesException() and f.isCxx() and isSEH = false
f.alwaysRaisesException() and f.isCxx() and isSeh = false
)
}

override predicate mayRaiseException(boolean isSEH) {
override predicate mayRaiseException(boolean isSeh) {
exists(ThrowingFunction f | f = expr.getTarget() |
f.mayRaiseException() and f.isSEH() and isSEH = true
f.mayRaiseException() and f.isSeh() and isSeh = true
or
f.mayRaiseException() and f.isCxx() and isSEH = false
f.mayRaiseException() and f.isCxx() and isSeh = false
)
}

override predicate neverRaiseException(boolean isSEH) {
override predicate neverRaiseException(boolean isSeh) {
exists(NonThrowingFunction f | f = expr.getTarget() |
f.isSEH() and isSEH = true
f.isSeh() and isSeh = true
or
f.isCxx() and isSEH = false
f.isCxx() and isSeh = false
)
}
}
Expand All @@ -397,41 +397,41 @@ class TranslatedExprCall extends TranslatedCallExpr {
result = getTranslatedExpr(expr.getExpr().getFullyConverted())
}

override predicate alwaysRaiseException(boolean isSEH) {
override predicate alwaysRaiseException(boolean isSeh) {
// We assume that a call to a function pointer will not throw a CXX exception.
// This is not sound in general, but this will greatly reduce the number of
// exceptional edges.
// For SEH exceptions, use the defined ThrowingFunction behavior and
// if no throwing function is found, assume a conditional SEH exception
// see `mayRaiseException`
exists(ThrowingFunction f | f = expr.getTarget() |
f.alwaysRaisesException() and f.isSEH() and isSEH = true
f.alwaysRaisesException() and f.isSeh() and isSeh = true
)
}

override predicate mayRaiseException(boolean isSEH) {
override predicate mayRaiseException(boolean isSeh) {
// We assume that a call to a function pointer will not throw a CXX exception.
// This is not sound in general, but this will greatly reduce the number of
// exceptional edges.
// For SEH exceptions, use the defined ThrowingFunction behavior.
// ASSUMPTION: if no ThrowingFunction is found for the given call, assume a conditional SEH exception
// on the call.
exists(ThrowingFunction f | f = expr.getTarget() |
f.mayRaiseException() and f.isSEH() and isSEH = true
f.mayRaiseException() and f.isSeh() and isSeh = true
)
or
not exists(ThrowingFunction f | f = expr.getTarget() and f.isSEH()) and
isSEH = true
not exists(ThrowingFunction f | f = expr.getTarget() and f.isSeh()) and
isSeh = true
}

override predicate neverRaiseException(boolean isSEH) {
override predicate neverRaiseException(boolean isSeh) {
// We assume that a call to a function pointer will not throw a CXX exception.
// This is not sound in general, but this will greatly reduce the number of
// exceptional edges.
// For SEH exceptions, use the defined ThrowingFunction behavior and
// if no throwing function is found, assume a conditional SEH exception
// see `mayRaiseException`
exists(NonThrowingFunction f | f = expr.getTarget() | f.isSEH() and isSEH = true)
exists(NonThrowingFunction f | f = expr.getTarget() | f.isSeh() and isSeh = true)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1105,12 +1105,12 @@ abstract class TranslatedElement extends TTranslatedElement {
* nearest enclosing `try`, or the `Unwind` instruction for the function if
* there is no enclosing `try`. The successor edge kind is specified by `kind`.
*
* `isSEH` is true if the exception is a structured exception, false if otherwise.
* `isSeh` is true if the exception is a structured exception, false if otherwise.
* The boolean value can be extracted from `ExceptionEdge` from the exception
* edge triggering the call to this function.
*/
Instruction getExceptionSuccessorInstruction(EdgeKind kind, boolean isSEH) {
result = this.getParent().getExceptionSuccessorInstruction(kind, isSEH)
Instruction getExceptionSuccessorInstruction(EdgeKind kind, boolean isSeh) {
result = this.getParent().getExceptionSuccessorInstruction(kind, isSeh)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ class TranslatedLoad extends TranslatedValueCategoryAdjustment, TTranslatedLoad
or
// All load instructions could throw an SEH exception
result = this.getParent().getExceptionSuccessorInstruction(any(GotoEdge e), true) and
kind.(ExceptionEdge).isSEH()
kind.(ExceptionEdge).isSeh()
)
}

Expand Down Expand Up @@ -1095,7 +1095,7 @@ class TranslatedStructuredBindingVariableAccess extends TranslatedNonConstantExp
or
// All load instructions could throw an SEH exception
result = this.getParent().getExceptionSuccessorInstruction(any(GotoEdge e), true) and
kind.(ExceptionEdge).isSEH()
kind.(ExceptionEdge).isSeh()
)
}

Expand Down Expand Up @@ -1916,7 +1916,7 @@ class TranslatedBlockAssignExpr extends TranslatedNonConstantExpr {
or
// All load instructions could throw an SEH exception
result = this.getParent().getExceptionSuccessorInstruction(any(GotoEdge e), true) and
kind.(ExceptionEdge).isSEH()
kind.(ExceptionEdge).isSeh()
)
or
tag = AssignmentStoreTag() and
Expand Down Expand Up @@ -2393,16 +2393,16 @@ class TranslatedAllocatorCall extends TTranslatedAllocatorCall, TranslatedDirect
result = getTranslatedExpr(expr.getAllocatorCall().getArgument(index).getFullyConverted())
}

final override predicate mayRaiseException(boolean isSEH) {
final override predicate mayRaiseException(boolean isSeh) {
// We assume that a call to `new` or `new[]` will never throw. This is not
// sound in general, but this will greatly reduce the number of exceptional
// edges.
none()
}

final override predicate alwaysRaiseException(boolean isSEH) { none() }
final override predicate alwaysRaiseException(boolean isSeh) { none() }

final override predicate neverRaiseException(boolean isSEH) { none() }
final override predicate neverRaiseException(boolean isSeh) { none() }
}

TranslatedAllocatorCall getTranslatedAllocatorCall(NewOrNewArrayExpr newExpr) {
Expand Down Expand Up @@ -2468,16 +2468,16 @@ class TranslatedDeleteOrDeleteArrayExpr extends TranslatedNonConstantExpr, Trans
result = getTranslatedExpr(expr.getExprWithReuse().getFullyConverted())
}

final override predicate mayRaiseException(boolean isSEH) {
final override predicate mayRaiseException(boolean isSeh) {
// We assume that a call to `delete` or `delete[]` will never throw. This is not
// sound in general, but this will greatly reduce the number of exceptional
// edges.
none()
}

final override predicate alwaysRaiseException(boolean isSEH) { none() }
final override predicate alwaysRaiseException(boolean isSeh) { none() }

final override predicate neverRaiseException(boolean isSEH) { none() }
final override predicate neverRaiseException(boolean isSeh) { none() }
}

TranslatedDeleteOrDeleteArrayExpr getTranslatedDeleteOrDeleteArray(DeleteOrDeleteArrayExpr newExpr) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,10 @@ class TranslatedFunction extends TranslatedRootElement, TTranslatedFunction {
)
}

final override Instruction getExceptionSuccessorInstruction(EdgeKind kind, boolean isSEH) {
final override Instruction getExceptionSuccessorInstruction(EdgeKind kind, boolean isSeh) {
// only unwind for C++ exceptions since SEH exceptions are too verbose
// and would generate unwind for all functions.
isSEH = false and
isSeh = false and
result = this.getInstruction(UnwindTag()) and
kind instanceof GotoEdge
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ class TranslatedSimpleDirectInitialization extends TranslatedDirectInitializatio
or
// All store instructions could throw an SEH exception
result = this.getParent().getExceptionSuccessorInstruction(any(GotoEdge e), true) and
kind.(ExceptionEdge).isSEH()
kind.(ExceptionEdge).isSeh()
)
}

Expand Down Expand Up @@ -369,7 +369,7 @@ class TranslatedStringLiteralInitialization extends TranslatedDirectInitializati
or
// All store instructions could throw an SEH exception
result = this.getParent().getExceptionSuccessorInstruction(any(GotoEdge e), true) and
kind.(ExceptionEdge).isSEH()
kind.(ExceptionEdge).isSeh()
)
or
if this.zeroInitRange(_, _)
Expand Down Expand Up @@ -666,7 +666,7 @@ class TranslatedFieldValueInitialization extends TranslatedFieldInitialization,
or
// All store instructions could throw an SEH exception
result = this.getParent().getExceptionSuccessorInstruction(any(GotoEdge e), true) and
kind.(ExceptionEdge).isSEH()
kind.(ExceptionEdge).isSeh()
)
}

Expand Down Expand Up @@ -872,7 +872,7 @@ class TranslatedElementValueInitialization extends TranslatedElementInitializati
or
// All store instructions could throw an SEH exception
result = this.getParent().getExceptionSuccessorInstruction(any(GotoEdge e), true) and
kind.(ExceptionEdge).isSEH()
kind.(ExceptionEdge).isSeh()
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,10 @@ class TranslatedMicrosoftTryExceptHandler extends TranslatedElement,

final override Function getFunction() { result = tryExcept.getEnclosingFunction() }

override Instruction getExceptionSuccessorInstruction(EdgeKind kind, boolean isSEH) {
override Instruction getExceptionSuccessorInstruction(EdgeKind kind, boolean isSeh) {
// A throw from within a `__except` block flows to the handler for the parent of
// the `__try`.
result = this.getParent().getParent().getExceptionSuccessorInstruction(kind, isSEH)
result = this.getParent().getParent().getExceptionSuccessorInstruction(kind, isSeh)
}
}

Expand Down Expand Up @@ -282,10 +282,10 @@ class TranslatedMicrosoftTryFinallyHandler extends TranslatedElement,
result = getTranslatedStmt(tryFinally.getFinally())
}

override Instruction getExceptionSuccessorInstruction(EdgeKind kind, boolean isSEH) {
override Instruction getExceptionSuccessorInstruction(EdgeKind kind, boolean isSeh) {
// A throw from within a `__finally` block flows to the handler for the parent of
// the `__try`.
result = this.getParent().getParent().getExceptionSuccessorInstruction(kind, isSEH)
result = this.getParent().getParent().getExceptionSuccessorInstruction(kind, isSeh)
}
}

Expand Down Expand Up @@ -734,25 +734,25 @@ class TranslatedTryStmt extends TranslatedStmt {
// of the `try`, because the exception successor of the `try` itself is
// the first catch clause.
handler = this.getHandler(stmt.getNumberOfCatchClauses() - 1) and
exists(boolean isSEH |
stmt instanceof MicrosoftTryStmt and isSEH = true
exists(boolean isSeh |
stmt instanceof MicrosoftTryStmt and isSeh = true
or
stmt instanceof TryStmt and isSEH = false
stmt instanceof TryStmt and isSeh = false
|
result = this.getParent().getExceptionSuccessorInstruction(kind, isSEH)
result = this.getParent().getExceptionSuccessorInstruction(kind, isSeh)
)
}

final override Instruction getExceptionSuccessorInstruction(EdgeKind kind, boolean isSEH) {
final override Instruction getExceptionSuccessorInstruction(EdgeKind kind, boolean isSeh) {
// SEH exceptions are only handled for SEH try statements and
// C++ exceptions for C++ try statements.
// I.e., we are assuming there isn't a mix and match between SEH and C++ exceptions.
// They are either all SEH or all C++ within a single try block depending on the
// try type (TryStmt vs MicrosoftTryStmt).
(
stmt instanceof TryStmt and isSEH = false
stmt instanceof TryStmt and isSeh = false
or
stmt instanceof MicrosoftTryStmt and isSEH = true
stmt instanceof MicrosoftTryStmt and isSeh = true
) and
(
result = this.getHandler(0).getFirstInstruction(kind)
Expand Down Expand Up @@ -839,10 +839,10 @@ abstract class TranslatedHandler extends TranslatedStmt {
child = this.getBlock() and result = this.getParent().getChildSuccessor(this, kind)
}

override Instruction getExceptionSuccessorInstruction(EdgeKind kind, boolean isSEH) {
override Instruction getExceptionSuccessorInstruction(EdgeKind kind, boolean isSeh) {
// A throw from within a `catch` block flows to the handler for the parent of
// the `try`.
result = this.getParent().getParent().getExceptionSuccessorInstruction(kind, isSEH)
result = this.getParent().getParent().getExceptionSuccessorInstruction(kind, isSeh)
}

TranslatedStmt getBlock() { result = getTranslatedStmt(stmt.getBlock()) }
Expand Down
Loading

0 comments on commit 3f01e4d

Please sign in to comment.