Class GuardedExpr
A guarded expression.
A guarded expression is an access or a call that is reached only when another
expression, e
, has a certain abstract value, where e
contains a sub
expression that is structurally equal to this expression.
For example, the property call x.Field.Property
on line 3 is guarded in
string M(C x) {
if (x.Field.Property != null)
return x.Field.Property.ToString();
return "";
}
There is no guarantee, in general, that the two structurally equal
expressions will evaluate to the same value at run-time. For instance,
in the following example, the null-guard on stack
on line 2 is an actual
guard, whereas the null-guard on stack.Pop()
on line 4 is not (invoking
Pop()
twice on a stack does not yield the same result):
string M(Stack<object> stack) {
if (stack == null)
return "";
if (stack.Pop() != null) // stack is not null
return stack.Pop().ToString(); // stack.Pop() might be null
return "";
}
However, in case one of the expressions accesses an SSA definition in its left-most qualifier, then so must the other (accessing the same SSA definition).
Import path
import semmle.code.csharp.controlflow.Guards
Direct supertypes
Indirect supertypes
Known direct subtypes
Predicates
getAGuard | Gets an expression that guards this expression. That is, this expression is only reached when the returned expression has abstract value |
isGuardedBy | Holds if this expression is guarded by expression |
mustHaveValue | Holds if this expression must have abstract value |
Inherited predicates
controlsBlock | Holds if basic block | from ControlFlowElement |
fromLibrary | Holds if this element is from an assembly. | from Element |
fromSource | Holds if this element is from source code. | from Element |
getAChild | Gets a child of this element, if any. | from Element |
getAChildExpr | Gets a child expression of this element, if any. | from ExprOrStmtParent |
getAChildStmt | Gets a child statement of this element, if any. | from ExprOrStmtParent |
getAControlFlowEntryNode | Gets a first control flow node executed within this element. | from ControlFlowElement |
getAControlFlowExitNode | Gets a potential last control flow node executed within this element. | from ControlFlowElement |
getAControlFlowNode | Gets a control flow node for this element. That is, a node in the control flow graph that corresponds to this element. | from ControlFlowElement |
getALocation | Gets a location of this element, including sources and assemblies. | from Expr |
getAPrimaryQlClass | Gets the name of a primary CodeQL class to which this element belongs. | from Element |
getAReachableElement | Gets an element that is reachable from this element. | from ControlFlowElement |
getAnSsaQualifier | Gets a (non-trivial) SSA definition corresponding to the longest qualifier chain of this expression, if any. | from AccessOrCallExpr |
getAnnotatedType | Gets the annotated type of this expression. | from Expr |
getAssembly | Gets the assembly that this element was compiled into. | from ControlFlowElement |
getChild | Gets the | from ExprOrStmtParent |
getChildExpr | Gets the | from ExprOrStmtParent |
getChildStmt | Gets the | from ExprOrStmtParent |
getEnclosingCallable | Gets the enclosing callable of this expression, if any. | from Expr |
getEnclosingStmt | Gets the enclosing statement of this expression, if any. | from Expr |
getExplicitArgumentName | Gets the explicit parameter name used to pass this expression as an argument for, if any. For example, if this expression is | from Expr |
getFile | Gets the file containing this element. | from Element |
getIndex | Gets the index of this element among its parent’s other children (zero-based). | from Element |
getLocation | Gets the location of this element. Where an element has locations in source and assemblies, choose the source location. If there are multiple assembly locations, choose only one. | from Element |
getNumberOfChildren | Gets the number of children of this element. | from Element |
getParent | Gets the parent of this expression. This is for example the element that uses the result of this expression. | from Expr |
getPrimaryQlClasses | Gets a comma-separated list of the names of the primary CodeQL classes to which this element belongs. | from Element |
getTarget | Gets the target of this expression. | from AccessOrCallExpr |
getType | Gets the type of this expression. | from Expr |
getValue | Gets the value of this expression, if any | from Expr |
hasMaybeNullFlowState | Holds if the nullable flow state of this expression may be null. | from Expr |
hasNotNullFlowState | Holds if the nullable flow state of this expression is not null. | from Expr |
hasValue | Holds if this expression has a value. | from Expr |
isImplicit | Holds if this expression is generated by the compiler and does not appear explicitly in the source code. | from Expr |
isLive | Holds if this element is live, that is this element can be reached from the entry point of its enclosing callable. | from ControlFlowElement |
reachableFrom | Holds if the current element is reachable from | from ControlFlowElement |
stripCasts | Gets an expression that is the result of stripping (recursively) all implicit and explicit casts from this expression, if any. For example, the result is | from Expr |
stripImplicitCasts | Gets an expression that is the result of stripping (recursively) all implicit casts from this expression, if any. | from Expr |
toString | Gets a textual representation of this element. | from Element |
toStringWithTypes | Gets the full textual representation of this element, including type information. | from Element |