-
Notifications
You must be signed in to change notification settings - Fork 1.9k
C#: Deprecate AbstractValue. #20737
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
C#: Deprecate AbstractValue. #20737
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| --- | ||
| category: deprecated | ||
| --- | ||
| * The class `AbstractValue` in the `Guards` library has been deprecated and replaced with the class `GuardValue`. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -227,7 +227,7 @@ | |
| e instanceof DereferenceableExpr and | ||
| ct.getAnArgument() = e and | ||
| ct.getAnArgument() = arg and | ||
| arg = any(NullValue nv | nv.isNonNull()).getAnExpr() and | ||
| nonNullValueImplied(arg) and | ||
| ck = ct.getComparisonKind() and | ||
| e != arg and | ||
| isNull = false and | ||
|
|
@@ -314,7 +314,7 @@ | |
| * In case `cfn` or `sub` access an SSA variable in their left-most qualifier, then | ||
| * so must the other (accessing the same SSA variable). | ||
| */ | ||
| predicate controlsNode(ControlFlow::Nodes::ElementNode cfn, AccessOrCallExpr sub, AbstractValue v) { | ||
| predicate controlsNode(ControlFlow::Nodes::ElementNode cfn, AccessOrCallExpr sub, GuardValue v) { | ||
| isGuardedByNode(cfn, this, sub, v) | ||
| } | ||
|
|
||
|
|
@@ -324,26 +324,31 @@ | |
| * Note: This predicate is inlined. | ||
| */ | ||
| pragma[inline] | ||
| predicate controlsNode(ControlFlow::Nodes::ElementNode cfn, AbstractValue v) { | ||
| predicate controlsNode(ControlFlow::Nodes::ElementNode cfn, GuardValue v) { | ||
| guardControls(this, cfn.getBasicBlock(), v) | ||
| } | ||
|
|
||
| /** | ||
| * Holds if basic block `bb` is guarded by this expression having value `v`. | ||
| */ | ||
| predicate controlsBasicBlock(BasicBlock bb, AbstractValue v) { guardControls(this, bb, v) } | ||
| predicate controlsBasicBlock(BasicBlock bb, GuardValue v) { guardControls(this, bb, v) } | ||
|
|
||
| /** | ||
| * Gets a valid value for this guard. For example, if this guard is a test, then | ||
| * it can have Boolean values `true` and `false`. | ||
| */ | ||
| deprecated AbstractValue getAValue() { isGuard(this, result) } | ||
| deprecated GuardValue getAValue() { isGuard(this, result) } | ||
| } | ||
|
|
||
| class AbstractValue = GuardValue; | ||
| /** DEPRECATED: Use `GuardValue` instead. */ | ||
| deprecated class AbstractValue = GuardValue; | ||
|
|
||
| /** Provides different types of `AbstractValues`s. */ | ||
| module AbstractValues { | ||
| /** | ||
| * DEPRECATED: Use `GuardValue` member predicates instead. | ||
| * | ||
| * Provides different types of `AbstractValues`s. | ||
| */ | ||
| deprecated module AbstractValues { | ||
| class BooleanValue extends AbstractValue { | ||
| BooleanValue() { exists(this.asBooleanValue()) } | ||
|
|
||
|
|
@@ -369,8 +374,7 @@ | |
| } | ||
| } | ||
|
|
||
| private import AbstractValues | ||
|
|
||
| // private import AbstractValues | ||
| /** Gets the value resulting from matching `null` against `pat`. */ | ||
| private boolean patternMatchesNull(PatternExpr pat) { | ||
| pat instanceof NullLiteral and result = true | ||
|
|
@@ -431,22 +435,22 @@ | |
| /** | ||
| * Gets an expression that tests via nullness whether this expression is `null`. | ||
| * | ||
| * If the returned expression evaluates to `null` (`v.isNull()`) or evaluates to | ||
| * non-`null` (`not v.isNull()`), then this expression is guaranteed to be `null` | ||
| * If the returned expression evaluates to `null` (`v.isNullValue()`) or evaluates to | ||
| * non-`null` (`not v.isNullValue()`), then this expression is guaranteed to be `null` | ||
|
||
| * if `isNull` is true, and non-`null` if `isNull` is false. | ||
| * | ||
| * For example, if `x` evaluates to `null` in `x ?? y` then `y` is evaluated, and | ||
| * `x` is guaranteed to be `null`. | ||
| */ | ||
| private Expr getANullnessNullCheck(NullValue v, boolean isNull) { | ||
| private Expr getANullnessNullCheck(GuardValue v, boolean isNull) { | ||
| exists(NullnessCompletion c | c.isValidFor(this) | | ||
| result = this and | ||
| if c.isNull() | ||
| then ( | ||
| v.isNull() and | ||
| v.isNullValue() and | ||
| isNull = true | ||
| ) else ( | ||
| v.isNonNull() and | ||
| v.isNonNullValue() and | ||
| isNull = false | ||
| ) | ||
| ) | ||
|
|
@@ -513,8 +517,8 @@ | |
| ) | ||
| } | ||
|
|
||
| private Expr getABooleanEmptinessCheck(BooleanValue v, boolean isEmpty) { | ||
| exists(boolean branch | branch = v.getValue() | | ||
| private Expr getABooleanEmptinessCheck(GuardValue v, boolean isEmpty) { | ||
| exists(boolean branch | branch = v.asBooleanValue() | | ||
| result = | ||
| any(ComparisonTest ct | | ||
| exists(boolean lowerBound | | ||
|
|
@@ -578,7 +582,7 @@ | |
| * For example, if the expression `x.Length != 0` evaluates to `true` then the | ||
| * expression `x` is guaranteed to be non-empty. | ||
| */ | ||
| Expr getAnEmptinessCheck(AbstractValue v, boolean isEmpty) { | ||
| Expr getAnEmptinessCheck(GuardValue v, boolean isEmpty) { | ||
| result = this.getABooleanEmptinessCheck(v, isEmpty) | ||
| } | ||
| } | ||
|
|
@@ -692,14 +696,14 @@ | |
| * left-most qualifier, then so must the other (accessing the same SSA | ||
| * variable). | ||
| */ | ||
| Guard getAGuard(Expr sub, AbstractValue v) { isGuardedByExpr(this, result, sub, v) } | ||
| Guard getAGuard(Expr sub, GuardValue v) { isGuardedByExpr(this, result, sub, v) } | ||
|
|
||
| /** | ||
| * Holds if this expression must have abstract value `v`. That is, this | ||
| * expression is guarded by a structurally equal expression having abstract | ||
| * value `v`. | ||
| */ | ||
| predicate mustHaveValue(AbstractValue v) { | ||
| predicate mustHaveValue(GuardValue v) { | ||
| exists(Guard g | g = this.getAGuard(g, v)) or ssaMustHaveValue(this, v) | ||
| } | ||
|
|
||
|
|
@@ -713,7 +717,7 @@ | |
| * variable). | ||
| */ | ||
| predicate isGuardedBy(Expr cond, Expr sub, boolean b) { | ||
| cond = this.getAGuard(sub, any(BooleanValue v | v.getValue() = b)) | ||
| cond = this.getAGuard(sub, any(GuardValue v | v.asBooleanValue() = b)) | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -738,7 +742,7 @@ | |
| class GuardedControlFlowNode extends ControlFlow::Nodes::ElementNode { | ||
| private Guard g; | ||
| private AccessOrCallExpr sub0; | ||
| private AbstractValue v0; | ||
| private GuardValue v0; | ||
|
|
||
| GuardedControlFlowNode() { g.controlsNode(this, sub0, v0) } | ||
|
|
||
|
|
@@ -753,7 +757,7 @@ | |
| * left-most qualifier, then so must the other (accessing the same SSA | ||
| * variable). | ||
| */ | ||
| Guard getAGuard(Expr sub, AbstractValue v) { | ||
| Guard getAGuard(Expr sub, GuardValue v) { | ||
| result = g and | ||
| sub = sub0 and | ||
| v = v0 | ||
|
|
@@ -764,7 +768,7 @@ | |
| * control flow node is guarded by a structurally equal expression having | ||
| * abstract value `v`. | ||
| */ | ||
| predicate mustHaveValue(AbstractValue v) { g = this.getAGuard(g, v) } | ||
| predicate mustHaveValue(GuardValue v) { g = this.getAGuard(g, v) } | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -788,7 +792,7 @@ | |
| class GuardedDataFlowNode extends DataFlow::ExprNode { | ||
| private Guard g; | ||
| private AccessOrCallExpr sub0; | ||
| private AbstractValue v0; | ||
| private GuardValue v0; | ||
|
|
||
| GuardedDataFlowNode() { | ||
| exists(ControlFlow::Nodes::ElementNode cfn | exists(this.getExprAtNode(cfn)) | | ||
|
|
@@ -807,7 +811,7 @@ | |
| * left-most qualifier, then so must the other (accessing the same SSA | ||
| * variable). | ||
| */ | ||
| Guard getAGuard(Expr sub, AbstractValue v) { | ||
| Guard getAGuard(Expr sub, GuardValue v) { | ||
| result = g and | ||
| sub = sub0 and | ||
| v = v0 | ||
|
|
@@ -818,17 +822,17 @@ | |
| * data flow node is guarded by a structurally equal expression having | ||
| * abstract value `v`. | ||
| */ | ||
| predicate mustHaveValue(AbstractValue v) { g = this.getAGuard(g, v) } | ||
| predicate mustHaveValue(GuardValue v) { g = this.getAGuard(g, v) } | ||
| } | ||
|
|
||
| /** An expression guarded by a `null` check. */ | ||
| class NullGuardedExpr extends GuardedExpr { | ||
| NullGuardedExpr() { this.mustHaveValue(any(NullValue v | v.isNonNull())) } | ||
| NullGuardedExpr() { this.mustHaveValue(any(GuardValue v | v.isNonNullValue())) } | ||
| } | ||
|
|
||
| /** A data flow node guarded by a `null` check. */ | ||
| class NullGuardedDataFlowNode extends GuardedDataFlowNode { | ||
| NullGuardedDataFlowNode() { this.mustHaveValue(any(NullValue v | v.isNonNull())) } | ||
| NullGuardedDataFlowNode() { this.mustHaveValue(any(GuardValue v | v.isNonNullValue())) } | ||
| } | ||
|
|
||
| /** INTERNAL: Do not use. */ | ||
|
|
@@ -931,7 +935,7 @@ | |
| bao.getAnOperand() = o and | ||
| // The other operand must be provably non-null in order | ||
| // for `only if` to hold | ||
| o = any(NullValue nv | nv.isNonNull()).getAnExpr() and | ||
| nonNullValueImplied(o) and | ||
| e != o | ||
| ) | ||
| } | ||
|
|
@@ -973,7 +977,7 @@ | |
| nonEmptyValue(def.getDefinition().getSource()) | ||
| } | ||
|
|
||
| deprecated predicate isGuard(Expr e, AbstractValue val) { | ||
| deprecated predicate isGuard(Expr e, GuardValue val) { | ||
| ( | ||
| e.getType() instanceof BoolType and | ||
| not e instanceof BoolLiteral and | ||
|
|
@@ -1207,7 +1211,7 @@ | |
| * Holds if basic block `bb` only is reached when guard `g` has abstract value `v`. | ||
| */ | ||
| cached | ||
| predicate guardControls(Guard g, BasicBlock bb, AbstractValue v) { | ||
| predicate guardControls(Guard g, BasicBlock bb, GuardValue v) { | ||
| g.(Guards::Guard).valueControls(bb, v) | ||
| } | ||
|
|
||
|
|
@@ -1220,7 +1224,7 @@ | |
| pragma[nomagic] | ||
| private predicate nodeIsGuardedBySameSubExpr0( | ||
| ControlFlow::Node guardedCfn, BasicBlock guardedBB, AccessOrCallExpr guarded, Guard g, | ||
| AccessOrCallExpr sub, AbstractValue v | ||
| AccessOrCallExpr sub, GuardValue v | ||
| ) { | ||
| Stages::GuardsStage::forceCachingInSameStage() and | ||
| guardedCfn = guarded.getAControlFlowNode() and | ||
|
|
@@ -1233,7 +1237,7 @@ | |
| pragma[nomagic] | ||
| private predicate nodeIsGuardedBySameSubExpr( | ||
| ControlFlow::Node guardedCfn, BasicBlock guardedBB, AccessOrCallExpr guarded, Guard g, | ||
| AccessOrCallExpr sub, AbstractValue v | ||
| AccessOrCallExpr sub, GuardValue v | ||
| ) { | ||
| nodeIsGuardedBySameSubExpr0(guardedCfn, guardedBB, guarded, g, sub, v) and | ||
| guardControlsSub(g, guardedBB, sub) | ||
|
|
@@ -1242,7 +1246,7 @@ | |
| pragma[nomagic] | ||
| private predicate nodeIsGuardedBySameSubExprSsaDef0( | ||
| ControlFlow::Node cfn, BasicBlock guardedBB, AccessOrCallExpr guarded, Guard g, | ||
| ControlFlow::Node subCfn, BasicBlock subCfnBB, AccessOrCallExpr sub, AbstractValue v, | ||
| ControlFlow::Node subCfn, BasicBlock subCfnBB, AccessOrCallExpr sub, GuardValue v, | ||
| Ssa::Definition def | ||
| ) { | ||
| nodeIsGuardedBySameSubExpr(cfn, guardedBB, guarded, g, sub, v) and | ||
|
|
@@ -1253,7 +1257,7 @@ | |
| pragma[nomagic] | ||
| private predicate nodeIsGuardedBySameSubExprSsaDef( | ||
| ControlFlow::Node guardedCfn, AccessOrCallExpr guarded, Guard g, ControlFlow::Node subCfn, | ||
| AccessOrCallExpr sub, AbstractValue v, Ssa::Definition def | ||
| AccessOrCallExpr sub, GuardValue v, Ssa::Definition def | ||
| ) { | ||
| exists(BasicBlock guardedBB, BasicBlock subCfnBB | | ||
| nodeIsGuardedBySameSubExprSsaDef0(guardedCfn, guardedBB, guarded, g, subCfn, subCfnBB, sub, | ||
|
|
@@ -1263,18 +1267,16 @@ | |
| } | ||
|
|
||
| pragma[noinline] | ||
| private predicate isGuardedByExpr0( | ||
Check warningCode scanning / CodeQL Candidate predicate not marked as `nomagic` Warning
Candidate predicate to
isGuardedByExpr Error loading related location Loading |
||
| AccessOrCallExpr guarded, Guard g, AccessOrCallExpr sub, AbstractValue v | ||
| AccessOrCallExpr guarded, Guard g, AccessOrCallExpr sub, GuardValue v | ||
| ) { | ||
| forex(ControlFlow::Node cfn | cfn = guarded.getAControlFlowNode() | | ||
| nodeIsGuardedBySameSubExpr(cfn, _, guarded, g, sub, v) | ||
| ) | ||
| } | ||
|
|
||
| cached | ||
| predicate isGuardedByExpr( | ||
| AccessOrCallExpr guarded, Guard g, AccessOrCallExpr sub, AbstractValue v | ||
| ) { | ||
| predicate isGuardedByExpr(AccessOrCallExpr guarded, Guard g, AccessOrCallExpr sub, GuardValue v) { | ||
| isGuardedByExpr0(guarded, g, sub, v) and | ||
| forall(ControlFlow::Node subCfn, Ssa::Definition def | | ||
| nodeIsGuardedBySameSubExprSsaDef(_, guarded, g, subCfn, sub, v, def) | ||
|
|
@@ -1285,7 +1287,7 @@ | |
|
|
||
| cached | ||
| predicate isGuardedByNode( | ||
| ControlFlow::Nodes::ElementNode guarded, Guard g, AccessOrCallExpr sub, AbstractValue v | ||
| ControlFlow::Nodes::ElementNode guarded, Guard g, AccessOrCallExpr sub, GuardValue v | ||
| ) { | ||
| nodeIsGuardedBySameSubExpr(guarded, _, _, g, sub, v) and | ||
| forall(ControlFlow::Node subCfn, Ssa::Definition def | | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove