mirror of
https://github.com/github/codeql.git
synced 2026-04-28 02:05:14 +02:00
Merge pull request #4182 from github/igfoo/cfg
C++: Remove some remnants of the extractor CFG
This commit is contained in:
@@ -65,7 +65,7 @@ class ControlFlowNode extends Locatable, ControlFlowNodeBase {
|
||||
* taken when this expression is true.
|
||||
*/
|
||||
ControlFlowNode getATrueSuccessor() {
|
||||
truecond_base(this, result) and
|
||||
qlCFGTrueSuccessor(this, result) and
|
||||
result = getASuccessor()
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ class ControlFlowNode extends Locatable, ControlFlowNodeBase {
|
||||
* taken when this expression is false.
|
||||
*/
|
||||
ControlFlowNode getAFalseSuccessor() {
|
||||
falsecond_base(this, result) and
|
||||
qlCFGFalseSuccessor(this, result) and
|
||||
result = getASuccessor()
|
||||
}
|
||||
|
||||
@@ -95,18 +95,20 @@ import ControlFlowGraphPublic
|
||||
class ControlFlowNodeBase extends ElementBase, @cfgnode { }
|
||||
|
||||
/**
|
||||
* DEPRECATED: Use `ControlFlowNode.getATrueSuccessor()` instead.
|
||||
* Holds when `n2` is a control-flow node such that the control-flow
|
||||
* edge `(n1, n2)` may be taken when `n1` is an expression that is true.
|
||||
*/
|
||||
predicate truecond_base(ControlFlowNodeBase n1, ControlFlowNodeBase n2) {
|
||||
deprecated predicate truecond_base(ControlFlowNodeBase n1, ControlFlowNodeBase n2) {
|
||||
qlCFGTrueSuccessor(n1, n2)
|
||||
}
|
||||
|
||||
/**
|
||||
* DEPRECATED: Use `ControlFlowNode.getAFalseSuccessor()` instead.
|
||||
* Holds when `n2` is a control-flow node such that the control-flow
|
||||
* edge `(n1, n2)` may be taken when `n1` is an expression that is false.
|
||||
*/
|
||||
predicate falsecond_base(ControlFlowNodeBase n1, ControlFlowNodeBase n2) {
|
||||
deprecated predicate falsecond_base(ControlFlowNodeBase n1, ControlFlowNodeBase n2) {
|
||||
qlCFGFalseSuccessor(n1, n2)
|
||||
}
|
||||
|
||||
@@ -134,7 +136,7 @@ abstract class AdditionalControlFlowEdge extends ControlFlowNodeBase {
|
||||
/**
|
||||
* Holds if there is a control-flow edge from `source` to `target` in either
|
||||
* the extractor-generated control-flow graph or in a subclass of
|
||||
* `AdditionalControlFlowEdge`. Use this relation instead of `successors`.
|
||||
* `AdditionalControlFlowEdge`. Use this relation instead of `qlCFGSuccessor`.
|
||||
*/
|
||||
predicate successors_extended(ControlFlowNodeBase source, ControlFlowNodeBase target) {
|
||||
qlCFGSuccessor(source, target)
|
||||
|
||||
@@ -1376,8 +1376,6 @@ private module Cached {
|
||||
/**
|
||||
* Holds if `n2` is a successor of `n1` in the CFG. This includes also
|
||||
* true-successors and false-successors.
|
||||
*
|
||||
* This corresponds to the old `successors` dbscheme relation.
|
||||
*/
|
||||
cached
|
||||
predicate qlCFGSuccessor(Node n1, Node n2) {
|
||||
@@ -1390,9 +1388,8 @@ private module Cached {
|
||||
}
|
||||
|
||||
/**
|
||||
* Holds if `n2` is a true-successor of `n1` in the CFG.
|
||||
*
|
||||
* This corresponds to the old `truecond` dbscheme relation.
|
||||
* Holds if `n2` is a control-flow node such that the control-flow
|
||||
* edge `(n1, n2)` may be taken when `n1` is an expression that is true.
|
||||
*/
|
||||
cached
|
||||
predicate qlCFGTrueSuccessor(Node n1, Node n2) {
|
||||
@@ -1401,9 +1398,8 @@ private module Cached {
|
||||
}
|
||||
|
||||
/**
|
||||
* Holds if `n2` is a false-successor of `n1` in the CFG.
|
||||
*
|
||||
* This corresponds to the old `falsecond` dbscheme relation.
|
||||
* Holds if `n2` is a control-flow node such that the control-flow
|
||||
* edge `(n1, n2)` may be taken when `n1` is an expression that is false.
|
||||
*/
|
||||
cached
|
||||
predicate qlCFGFalseSuccessor(Node n1, Node n2) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import cpp
|
||||
private import PrimitiveBasicBlocks
|
||||
private import semmle.code.cpp.controlflow.internal.CFG
|
||||
|
||||
private class Node = ControlFlowNodeBase;
|
||||
|
||||
@@ -153,8 +154,8 @@ private predicate nonAnalyzableFunction(Function f) {
|
||||
*/
|
||||
private predicate impossibleFalseEdge(Expr condition, Node succ) {
|
||||
conditionAlwaysTrue(condition) and
|
||||
falsecond_base(condition, succ) and
|
||||
not truecond_base(condition, succ)
|
||||
qlCFGFalseSuccessor(condition, succ) and
|
||||
not qlCFGTrueSuccessor(condition, succ)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -162,8 +163,8 @@ private predicate impossibleFalseEdge(Expr condition, Node succ) {
|
||||
*/
|
||||
private predicate impossibleTrueEdge(Expr condition, Node succ) {
|
||||
conditionAlwaysFalse(condition) and
|
||||
truecond_base(condition, succ) and
|
||||
not falsecond_base(condition, succ)
|
||||
qlCFGTrueSuccessor(condition, succ) and
|
||||
not qlCFGFalseSuccessor(condition, succ)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -863,9 +864,9 @@ library class ConditionEvaluator extends ExprEvaluator {
|
||||
ConditionEvaluator() { this = 0 }
|
||||
|
||||
override predicate interesting(Expr e) {
|
||||
falsecond_base(e, _)
|
||||
qlCFGFalseSuccessor(e, _)
|
||||
or
|
||||
truecond_base(e, _)
|
||||
qlCFGTrueSuccessor(e, _)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1935,20 +1935,6 @@ stmtparents(
|
||||
ishandler(unique int block: @stmt_block ref);
|
||||
|
||||
@cfgnode = @stmt | @expr | @function | @initialiser ;
|
||||
successors(
|
||||
int from: @cfgnode ref,
|
||||
int to: @cfgnode ref
|
||||
);
|
||||
|
||||
truecond(
|
||||
unique int from: @cfgnode ref,
|
||||
int to: @cfgnode ref
|
||||
);
|
||||
|
||||
falsecond(
|
||||
unique int from: @cfgnode ref,
|
||||
int to: @cfgnode ref
|
||||
);
|
||||
|
||||
stmt_decl_bind(
|
||||
int stmt: @stmt_decl ref,
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,148 +0,0 @@
|
||||
import cpp
|
||||
import semmle.code.cpp.controlflow.internal.CFG
|
||||
|
||||
class DestructorCallEnhanced extends DestructorCall {
|
||||
override string toString() {
|
||||
if exists(this.getQualifier().(VariableAccess).getTarget().getName())
|
||||
then
|
||||
result =
|
||||
"call to " + this.getQualifier().(VariableAccess).getTarget().getName() + "." +
|
||||
this.getTarget().getName()
|
||||
else result = super.toString()
|
||||
}
|
||||
}
|
||||
|
||||
predicate differentEdge(ControlFlowNode n1, ControlFlowNode n2, string msg) {
|
||||
successors(n1, n2) and
|
||||
not qlCFGSuccessor(n1, n2) and
|
||||
msg = "Standard edge, only from extractor"
|
||||
or
|
||||
not successors(n1, n2) and
|
||||
qlCFGSuccessor(n1, n2) and
|
||||
msg = "Standard edge, only from QL"
|
||||
or
|
||||
truecond_base(n1, n2) and
|
||||
not qlCFGTrueSuccessor(n1, n2) and
|
||||
msg = "True edge, only from extractor"
|
||||
or
|
||||
not truecond_base(n1, n2) and
|
||||
qlCFGTrueSuccessor(n1, n2) and
|
||||
msg = "True edge, only from QL"
|
||||
or
|
||||
falsecond_base(n1, n2) and
|
||||
not qlCFGFalseSuccessor(n1, n2) and
|
||||
msg = "False edge, only from extractor"
|
||||
or
|
||||
not falsecond_base(n1, n2) and
|
||||
qlCFGFalseSuccessor(n1, n2) and
|
||||
msg = "False edge, only from QL"
|
||||
}
|
||||
|
||||
predicate differentScope(Element e) {
|
||||
exists(ControlFlowNode n1 |
|
||||
getScopeElement(n1) = e and
|
||||
differentEdge(n1, _, _)
|
||||
)
|
||||
}
|
||||
|
||||
private predicate isInFunction(ControlFlowNode x, Function f) {
|
||||
f = x.getControlFlowScope()
|
||||
or
|
||||
exists(ControlFlowNode y |
|
||||
successors(unresolveElement(x), unresolveElement(y))
|
||||
or
|
||||
successors(unresolveElement(y), unresolveElement(x))
|
||||
|
|
||||
isInFunction(y, f)
|
||||
)
|
||||
}
|
||||
|
||||
Element getScopeElement(ControlFlowNode x) {
|
||||
isInFunction(x, result)
|
||||
or
|
||||
not isInFunction(x, _) and
|
||||
result = x.getFile()
|
||||
}
|
||||
|
||||
string getScopeName(ControlFlowNode x) {
|
||||
exists(Function scope | scope = getScopeElement(x) |
|
||||
differentScope(scope) and
|
||||
result =
|
||||
scope.getFile().getBaseName().splitAt(".", 0) + "__" +
|
||||
scope.getQualifiedName().replaceAll("::", "_")
|
||||
)
|
||||
or
|
||||
exists(File scope | scope = getScopeElement(x) |
|
||||
differentScope(scope) and
|
||||
result = scope.getBaseName()
|
||||
)
|
||||
}
|
||||
|
||||
module QLCFG {
|
||||
private predicate isNode(boolean isEdge, ControlFlowNode x, ControlFlowNode y, string label) {
|
||||
isEdge = false and x = y and label = x.toString()
|
||||
}
|
||||
|
||||
private predicate isSuccessor(boolean isEdge, ControlFlowNode x, ControlFlowNode y, string label) {
|
||||
exists(string truelabel, string falselabel |
|
||||
isEdge = true and
|
||||
qlCFGSuccessor(x, y) and
|
||||
(if qlCFGTrueSuccessor(x, y) then truelabel = "T" else truelabel = "") and
|
||||
(if qlCFGFalseSuccessor(x, y) then falselabel = "F" else falselabel = "") and
|
||||
label = truelabel + falselabel
|
||||
)
|
||||
}
|
||||
|
||||
predicate qltestGraph(
|
||||
Element scopeElement, string scopeString, boolean isEdge, ControlFlowNode x, ControlFlowNode y,
|
||||
string label
|
||||
) {
|
||||
scopeElement = getScopeElement(x) and
|
||||
scopeString = getScopeName(x) + "_ql" and
|
||||
(
|
||||
isNode(isEdge, x, y, label)
|
||||
or
|
||||
isSuccessor(isEdge, x, y, label)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
module ExtractorCFG {
|
||||
predicate isNode(boolean isEdge, ControlFlowNode x, ControlFlowNode y, string label) {
|
||||
isEdge = false and x = y and label = x.toString()
|
||||
}
|
||||
|
||||
predicate isSuccessor(boolean isEdge, ControlFlowNode x, ControlFlowNode y, string label) {
|
||||
exists(string truelabel, string falselabel |
|
||||
isEdge = true and
|
||||
successors(x, y) and
|
||||
(if truecond_base(x, y) then truelabel = "T" else truelabel = "") and
|
||||
(if falsecond_base(x, y) then falselabel = "F" else falselabel = "") and
|
||||
label = truelabel + falselabel
|
||||
)
|
||||
}
|
||||
|
||||
predicate qltestGraph(
|
||||
Element scopeElement, string scopeString, boolean isEdge, ControlFlowNode x, ControlFlowNode y,
|
||||
string label
|
||||
) {
|
||||
scopeElement = getScopeElement(x) and
|
||||
scopeString = getScopeName(x) + "_extractor" and
|
||||
(
|
||||
isNode(isEdge, x, y, label)
|
||||
or
|
||||
isSuccessor(isEdge, x, y, label)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
module AllCFG {
|
||||
predicate qltestGraph(
|
||||
Element scopeElement, string scopeString, boolean isEdge, ControlFlowNode x, ControlFlowNode y,
|
||||
string label
|
||||
) {
|
||||
QLCFG::qltestGraph(scopeElement, scopeString, isEdge, x, y, label)
|
||||
or
|
||||
ExtractorCFG::qltestGraph(scopeElement, scopeString, isEdge, x, y, label)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user