C++: Rename Block -> BlockStmt

This commit is contained in:
Jonas Jensen
2020-09-07 16:48:29 +02:00
parent 22b3b0a5f1
commit ab90f06ddf
49 changed files with 375 additions and 368 deletions

View File

@@ -20,6 +20,7 @@ The following changes in version 1.26 affect C/C++ analysis in all applications.
## Changes to libraries ## Changes to libraries
* The QL class `Block`, denoting the `{ ... }` statement, is renamed to `BlockStmt`.
* The models library now models many taint flows through `std::array`, `std::vector`, `std::deque`, `std::list` and `std::forward_list`. * The models library now models many taint flows through `std::array`, `std::vector`, `std::deque`, `std::list` and `std::forward_list`.
* The models library now models many more taint flows through `std::string`. * The models library now models many more taint flows through `std::string`.
* The `SimpleRangeAnalysis` library now supports multiplications of the form * The `SimpleRangeAnalysis` library now supports multiplications of the form

View File

@@ -9,6 +9,6 @@
import cpp import cpp
from Block blk from BlockStmt blk
where blk.getNumStmt() = 0 where blk.getNumStmt() = 0
select blk select blk

View File

@@ -13,5 +13,5 @@
import cpp import cpp
from IfStmt i from IfStmt i
where i.getThen().(Block).getNumStmt() = 0 where i.getThen().(BlockStmt).getNumStmt() = 0
select i select i

View File

@@ -8,6 +8,6 @@
import cpp import cpp
from Block b from BlockStmt b
where b.getNumStmt() = 1 where b.getNumStmt() = 1
select b select b

View File

@@ -14,7 +14,7 @@ import cpp
class ComplexStmt extends Stmt { class ComplexStmt extends Stmt {
ComplexStmt() { ComplexStmt() {
exists(Block body | exists(BlockStmt body |
body = this.(Loop).getStmt() or body = this.(Loop).getStmt() or
body = this.(SwitchStmt).getStmt() body = this.(SwitchStmt).getStmt()
| |
@@ -24,7 +24,7 @@ class ComplexStmt extends Stmt {
} }
} }
from Block b, int n, ComplexStmt complexStmt from BlockStmt b, int n, ComplexStmt complexStmt
where where
n = strictcount(ComplexStmt s | s = b.getAStmt()) and n = strictcount(ComplexStmt s | s = b.getAStmt()) and
n > 3 and n > 3 and

View File

@@ -17,7 +17,7 @@ where
shadowing(lv1, lv2) and shadowing(lv1, lv2) and
not lv1.isCompilerGenerated() and not lv1.isCompilerGenerated() and
not lv2.isCompilerGenerated() and not lv2.isCompilerGenerated() and
not lv1.getParentScope().(Block).isInMacroExpansion() and not lv1.getParentScope().(BlockStmt).isInMacroExpansion() and
not lv2.getParentScope().(Block).isInMacroExpansion() not lv2.getParentScope().(BlockStmt).isInMacroExpansion()
select lv1, "Variable " + lv1.getName() + " hides another variable of the same name (on $@).", lv2, select lv1, "Variable " + lv1.getName() + " hides another variable of the same name (on $@).", lv2,
"line " + lv2.getLocation().getStartLine().toString() "line " + lv2.getLocation().getStartLine().toString()

View File

@@ -14,7 +14,7 @@
import cpp import cpp
predicate emptyBlock(ControlStructure s, Block b) { predicate emptyBlock(ControlStructure s, BlockStmt b) {
b = s.getAChild() and b = s.getAChild() and
not exists(b.getAChild()) and not exists(b.getAChild()) and
not b.isInMacroExpansion() and not b.isInMacroExpansion() and
@@ -23,7 +23,7 @@ predicate emptyBlock(ControlStructure s, Block b) {
class AffectedFile extends File { class AffectedFile extends File {
AffectedFile() { AffectedFile() {
exists(Block b | exists(BlockStmt b |
emptyBlock(_, b) and emptyBlock(_, b) and
this = b.getFile() this = b.getFile()
) )
@@ -37,7 +37,7 @@ class AffectedFile extends File {
class BlockOrNonChild extends Element { class BlockOrNonChild extends Element {
BlockOrNonChild() { BlockOrNonChild() {
( (
this instanceof Block this instanceof BlockStmt
or or
this instanceof Comment this instanceof Comment
or or
@@ -78,7 +78,7 @@ class BlockOrNonChild extends Element {
/** /**
* A block that contains a non-child element. * A block that contains a non-child element.
*/ */
predicate emptyBlockContainsNonchild(Block b) { predicate emptyBlockContainsNonchild(BlockStmt b) {
emptyBlock(_, b) and emptyBlock(_, b) and
exists(BlockOrNonChild c, AffectedFile file | exists(BlockOrNonChild c, AffectedFile file |
c.(BlockOrNonChild).getStartRankIn(file) = 1 + b.(BlockOrNonChild).getStartRankIn(file) and c.(BlockOrNonChild).getStartRankIn(file) = 1 + b.(BlockOrNonChild).getStartRankIn(file) and
@@ -91,7 +91,7 @@ predicate emptyBlockContainsNonchild(Block b) {
* A block that is entirely on one line, which also contains a comment. Chances * A block that is entirely on one line, which also contains a comment. Chances
* are the comment is intended to refer to the block. * are the comment is intended to refer to the block.
*/ */
predicate lineComment(Block b) { predicate lineComment(BlockStmt b) {
emptyBlock(_, b) and emptyBlock(_, b) and
exists(Location bLocation, File f, int line | exists(Location bLocation, File f, int line |
bLocation = b.getLocation() and bLocation = b.getLocation() and
@@ -106,7 +106,7 @@ predicate lineComment(Block b) {
) )
} }
from ControlStructure s, Block eb from ControlStructure s, BlockStmt eb
where where
emptyBlock(s, eb) and emptyBlock(s, eb) and
not emptyBlockContainsNonchild(eb) and not emptyBlockContainsNonchild(eb) and

View File

@@ -12,7 +12,7 @@
import cpp import cpp
import semmle.code.cpp.commons.Exclusions import semmle.code.cpp.commons.Exclusions
Stmt getNextRealStmt(Block b, int i) { Stmt getNextRealStmt(BlockStmt b, int i) {
result = b.getStmt(i + 1) and result = b.getStmt(i + 1) and
not result instanceof EmptyStmt not result instanceof EmptyStmt
or or
@@ -20,7 +20,7 @@ Stmt getNextRealStmt(Block b, int i) {
result = getNextRealStmt(b, i + 1) result = getNextRealStmt(b, i + 1)
} }
from JumpStmt js, Block b, int i, Stmt s from JumpStmt js, BlockStmt b, int i, Stmt s
where where
b.getStmt(i) = js and b.getStmt(i) = js and
s = getNextRealStmt(b, i) and s = getNextRealStmt(b, i) and

View File

@@ -12,7 +12,7 @@
import cpp import cpp
int lineInBlock(File f) { int lineInBlock(File f) {
exists(Block block, Location blockLocation | exists(BlockStmt block, Location blockLocation |
block.getFile() = f and blockLocation = block.getLocation() block.getFile() = f and blockLocation = block.getLocation()
| |
result in [blockLocation.getStartLine() .. blockLocation.getEndLine()] result in [blockLocation.getStartLine() .. blockLocation.getEndLine()]

View File

@@ -27,11 +27,11 @@ predicate macroUseLocation(File f, int start, int end) {
} }
pragma[noopt] pragma[noopt]
predicate emptyIf(IfStmt s, Block b, File f, int start, int end) { predicate emptyIf(IfStmt s, BlockStmt b, File f, int start, int end) {
s instanceof IfStmt and s instanceof IfStmt and
not exists(s.getElse()) and not exists(s.getElse()) and
b = s.getThen() and b = s.getThen() and
b instanceof Block and b instanceof BlockStmt and
not exists(b.getAChild()) and not exists(b.getAChild()) and
f = b.getFile() and f = b.getFile() and
exists(Location l | exists(Location l |
@@ -42,7 +42,7 @@ predicate emptyIf(IfStmt s, Block b, File f, int start, int end) {
} }
pragma[noopt] pragma[noopt]
predicate query(IfStmt s, Block b) { predicate query(IfStmt s, BlockStmt b) {
exists(File f, int blockStart, int blockEnd | exists(File f, int blockStart, int blockEnd |
emptyIf(s, b, f, blockStart, blockEnd) and emptyIf(s, b, f, blockStart, blockEnd) and
not exists(int macroStart, int macroEnd | not exists(int macroStart, int macroEnd |
@@ -53,7 +53,7 @@ predicate query(IfStmt s, Block b) {
) )
} }
from IfStmt s, Block b from IfStmt s, BlockStmt b
where where
query(s, b) and query(s, b) and
not b.isInMacroExpansion() not b.isInMacroExpansion()

View File

@@ -27,7 +27,7 @@ int logicalLength(FunctionDeclarationEntry f) {
count(Stmt s | count(Stmt s |
s.getEnclosingFunction() = f.getFunction() and s.getEnclosingFunction() = f.getFunction() and
s.getFile() = f.getFile() and s.getFile() = f.getFile() and
not s instanceof Block and not s instanceof BlockStmt and
not s instanceof EmptyStmt and not s instanceof EmptyStmt and
not exists(ForStmt for | s = for.getInitialization()) and not exists(ForStmt for | s = for.getInitialization()) and
not s.isAffectedByMacro() not s.isAffectedByMacro()

View File

@@ -14,7 +14,7 @@ import cpp
class OneLineStmt extends Stmt { class OneLineStmt extends Stmt {
OneLineStmt() { OneLineStmt() {
this.getLocation().getStartLine() = this.getLocation().getEndLine() and this.getLocation().getStartLine() = this.getLocation().getEndLine() and
not this instanceof Block and not this instanceof BlockStmt and
not exists(ForStmt for | this = for.getInitialization()) and not exists(ForStmt for | this = for.getInitialization()) and
( (
// Either this statement is not touched by a macro at all... // Either this statement is not touched by a macro at all...

View File

@@ -27,7 +27,7 @@ int logicalLength(FunctionDeclarationEntry f) {
count(Stmt s | count(Stmt s |
s.getEnclosingFunction() = f.getFunction() and s.getEnclosingFunction() = f.getFunction() and
s.getFile() = f.getFile() and s.getFile() = f.getFile() and
not s instanceof Block and not s instanceof BlockStmt and
not s instanceof EmptyStmt and not s instanceof EmptyStmt and
not exists(ForStmt for | s = for.getInitialization()) and not exists(ForStmt for | s = for.getInitialization()) and
not s.isAffectedByMacro() not s.isAffectedByMacro()

View File

@@ -13,7 +13,7 @@
import cpp import cpp
predicate blockDominates(Block check, Block access) { predicate blockDominates(BlockStmt check, BlockStmt access) {
check.getLocation().getStartLine() <= access.getLocation().getStartLine() and check.getLocation().getStartLine() <= access.getLocation().getStartLine() and
check.getLocation().getEndLine() >= access.getLocation().getEndLine() check.getLocation().getEndLine() >= access.getLocation().getEndLine()
} }

View File

@@ -117,7 +117,7 @@ private predicate blockCoversStatement(int equivClass, int first, int last, Stmt
private Stmt statementInMethod(FunctionDeclarationEntry m) { private Stmt statementInMethod(FunctionDeclarationEntry m) {
result.getParent+() = m.getBlock() and result.getParent+() = m.getBlock() and
not result.getLocation() instanceof UnknownStmtLocation and not result.getLocation() instanceof UnknownStmtLocation and
not result instanceof Block not result instanceof BlockStmt
} }
private predicate duplicateStatement( private predicate duplicateStatement(

View File

@@ -13,7 +13,7 @@ import cpp
from Stmt parent, Stmt child from Stmt parent, Stmt child
where where
not child instanceof Block and not child instanceof BlockStmt and
( (
child = parent.(IfStmt).getThen() child = parent.(IfStmt).getThen()
or or

View File

@@ -28,7 +28,7 @@ predicate oppositeOperators(string op1, string op2) {
* `!op2(_, _)`. * `!op2(_, _)`.
*/ */
predicate implementedAsNegationOf(Operator op1, Operator op2) { predicate implementedAsNegationOf(Operator op1, Operator op2) {
exists(Block b, ReturnStmt r, NotExpr n, Expr o | exists(BlockStmt b, ReturnStmt r, NotExpr n, Expr o |
b = op1.getBlock() and b = op1.getBlock() and
b.getNumStmt() = 1 and b.getNumStmt() = 1 and
r = b.getStmt(0) and r = b.getStmt(0) and

View File

@@ -29,7 +29,7 @@ predicate localShadowsParameter(LocalVariable lv, Parameter p) {
from Variable v, Variable shadowed from Variable v, Variable shadowed
where where
not v.getParentScope().(Block).isInMacroExpansion() and not v.getParentScope().(BlockStmt).isInMacroExpansion() and
( (
v.(LocalVariableOrParameter).shadowsGlobal(shadowed.(GlobalVariable)) or v.(LocalVariableOrParameter).shadowsGlobal(shadowed.(GlobalVariable)) or
localShadowsParameter(v, shadowed) or localShadowsParameter(v, shadowed) or

View File

@@ -38,7 +38,7 @@ predicate noDefUsePath(LocalVariable lv, ControlFlowNode n) {
} }
predicate neighbouringStmts(Stmt s1, Stmt s2) { predicate neighbouringStmts(Stmt s1, Stmt s2) {
exists(Block b, int i | exists(BlockStmt b, int i |
i in [0 .. b.getNumStmt() - 2] and i in [0 .. b.getNumStmt() - 2] and
s1 = b.getStmt(i) and s1 = b.getStmt(i) and
s2 = b.getStmt(i + 1) s2 = b.getStmt(i + 1)

View File

@@ -22,6 +22,6 @@ where
not s instanceof ControlStructure and not s instanceof ControlStructure and
// Exclude blocks; if a child of the block violates the rule that will still // Exclude blocks; if a child of the block violates the rule that will still
// be picked up so there is no point in blaming the block as well // be picked up so there is no point in blaming the block as well
not s instanceof Block and not s instanceof BlockStmt and
s.isPure() s.isPure()
select s, "AV Rule 187: All non-null statements shall potentially have a side-effect." select s, "AV Rule 187: All non-null statements shall potentially have a side-effect."

View File

@@ -18,7 +18,7 @@ import cpp
// whether t is the last statement of s, possibly peeling off blocks // whether t is the last statement of s, possibly peeling off blocks
predicate isTerminatingStmt(Stmt s, Stmt t) { predicate isTerminatingStmt(Stmt s, Stmt t) {
s = t or isTerminatingStmt(s.(Block).getLastStmt(), t) s = t or isTerminatingStmt(s.(BlockStmt).getLastStmt(), t)
} }
from BreakStmt s from BreakStmt s

View File

@@ -128,7 +128,7 @@ class Element extends ElementBase {
/** /**
* Gets the parent scope of this `Element`, if any. * Gets the parent scope of this `Element`, if any.
* A scope is a `Type` (`Class` / `Enum`), a `Namespace`, a `Block`, a `Function`, * A scope is a `Type` (`Class` / `Enum`), a `Namespace`, a `BlockStmt`, a `Function`,
* or certain kinds of `Statement`. * or certain kinds of `Statement`.
*/ */
Element getParentScope() { Element getParentScope() {
@@ -161,7 +161,7 @@ class Element extends ElementBase {
exists(EnumConstant e | this = e and result = e.getDeclaringEnum()) exists(EnumConstant e | this = e and result = e.getDeclaringEnum())
or or
// result instanceof block|function // result instanceof block|function
exists(Block b | this = b and blockscope(unresolveElement(b), unresolveElement(result))) exists(BlockStmt b | this = b and blockscope(unresolveElement(b), unresolveElement(result)))
or or
exists(TemplateFunction tf | this = tf.getATemplateArgument() and result = tf) exists(TemplateFunction tf | this = tf.getATemplateArgument() and result = tf)
or or

View File

@@ -268,7 +268,7 @@ class Function extends Declaration, ControlFlowNode, AccessHolder, @function {
* block, this gives the block guarded by the try statement. See * block, this gives the block guarded by the try statement. See
* `FunctionTryStmt` for further information. * `FunctionTryStmt` for further information.
*/ */
Block getBlock() { result.getParentScope() = this } BlockStmt getBlock() { result.getParentScope() = this }
/** Holds if this function has an entry point. */ /** Holds if this function has an entry point. */
predicate hasEntryPoint() { exists(getEntryPoint()) } predicate hasEntryPoint() { exists(getEntryPoint()) }
@@ -276,7 +276,7 @@ class Function extends Declaration, ControlFlowNode, AccessHolder, @function {
/** /**
* Gets the first node in this function's control flow graph. * Gets the first node in this function's control flow graph.
* *
* For most functions, this first node will be the `Block` returned by * For most functions, this first node will be the `BlockStmt` returned by
* `getBlock`. However in C++, the first node can also be a * `getBlock`. However in C++, the first node can also be a
* `FunctionTryStmt`. * `FunctionTryStmt`.
*/ */
@@ -564,7 +564,7 @@ class FunctionDeclarationEntry extends DeclarationEntry, @fun_decl {
* If this is a function definition, get the block containing the * If this is a function definition, get the block containing the
* function body. * function body.
*/ */
Block getBlock() { BlockStmt getBlock() {
this.isDefinition() and this.isDefinition() and
result = getFunction().getBlock() and result = getFunction().getBlock() and
result.getFile() = this.getFile() result.getFile() = this.getFile()
@@ -576,7 +576,7 @@ class FunctionDeclarationEntry extends DeclarationEntry, @fun_decl {
*/ */
pragma[noopt] pragma[noopt]
int getNumberOfLines() { int getNumberOfLines() {
exists(Block b, Location l, int start, int end, int diff | b = getBlock() | exists(BlockStmt b, Location l, int start, int end, int diff | b = getBlock() |
l = b.getLocation() and l = b.getLocation() and
start = l.getStartLine() and start = l.getStartLine() and
end = l.getEndLine() and end = l.getEndLine() and

View File

@@ -136,7 +136,7 @@ deprecated class ObjcTryStmt extends TryStmt {
* DEPRECATED: Objective-C is no longer supported. * DEPRECATED: Objective-C is no longer supported.
* An Objective C `@finally` block. * An Objective C `@finally` block.
*/ */
deprecated class FinallyBlock extends Block { deprecated class FinallyBlock extends BlockStmt {
FinallyBlock() { none() } FinallyBlock() { none() }
/** Gets the try statement corresponding to this finally block. */ /** Gets the try statement corresponding to this finally block. */

View File

@@ -98,7 +98,7 @@ class Parameter extends LocalScopeVariable, @parameter {
* DEPRECATED: this method was used in a previous implementation of * DEPRECATED: this method was used in a previous implementation of
* getName, but is no longer in use. * getName, but is no longer in use.
*/ */
deprecated string getNameInBlock(Block b) { deprecated string getNameInBlock(BlockStmt b) {
exists(ParameterDeclarationEntry pde | exists(ParameterDeclarationEntry pde |
pde.getFunctionDeclarationEntry().getBlock() = b and pde.getFunctionDeclarationEntry().getBlock() = b and
this.getFunction().getBlock() = b and this.getFunction().getBlock() = b and
@@ -127,7 +127,7 @@ class Parameter extends LocalScopeVariable, @parameter {
* Gets the catch block to which this parameter belongs, if it is a catch * Gets the catch block to which this parameter belongs, if it is a catch
* block parameter. * block parameter.
*/ */
Block getCatchBlock() { params(underlyingElement(this), unresolveElement(result), _, _) } BlockStmt getCatchBlock() { params(underlyingElement(this), unresolveElement(result), _, _) }
/** /**
* Gets the zero-based index of this parameter. * Gets the zero-based index of this parameter.

View File

@@ -25,7 +25,7 @@ private predicate exprInVoidContext(Expr e) {
( (
exists(ExprStmt s | exists(ExprStmt s |
s = e.getParent() and s = e.getParent() and
not exists(StmtExpr se | s = se.getStmt().(Block).getLastStmt()) not exists(StmtExpr se | s = se.getStmt().(BlockStmt).getLastStmt())
) )
or or
exists(ConditionalExpr c | c.getThen() = e and c instanceof ExprInVoidContext) exists(ConditionalExpr c | c.getThen() = e and c instanceof ExprInVoidContext)

View File

@@ -118,7 +118,7 @@ private predicate excludeNodeAndNodesBelow(Expr e) {
or or
// Constructor init lists should be evaluated, and we can change this in // Constructor init lists should be evaluated, and we can change this in
// the future, but it would mean that a `Function` entry point is not // the future, but it would mean that a `Function` entry point is not
// always a `Block` or `FunctionTryStmt`. // always a `BlockStmt` or `FunctionTryStmt`.
e instanceof ConstructorInit e instanceof ConstructorInit
or or
// Destructor field destructions should also be hooked into the CFG // Destructor field destructions should also be hooked into the CFG
@@ -408,10 +408,10 @@ private Node getControlOrderChildSparse(Node n, int i) {
// in-line in the block containing their corresponding DeclStmt but should // in-line in the block containing their corresponding DeclStmt but should
// not be evaluated in the order implied by their position in the block. We // not be evaluated in the order implied by their position in the block. We
// do the following. // do the following.
// - Block skips all the VlaDeclStmt and VlaDimensionStmt children. // - BlockStmt skips all the VlaDeclStmt and VlaDimensionStmt children.
// - VlaDeclStmt is inserted as a child of DeclStmt // - VlaDeclStmt is inserted as a child of DeclStmt
// - VlaDimensionStmt is inserted as a child of VlaDeclStmt // - VlaDimensionStmt is inserted as a child of VlaDeclStmt
result = n.(Block).getChild(i) and result = n.(BlockStmt).getChild(i) and
not result instanceof VlaDeclStmt and not result instanceof VlaDeclStmt and
not result instanceof VlaDimensionStmt not result instanceof VlaDimensionStmt
or or
@@ -557,7 +557,7 @@ private class Spec extends Pos {
*/ */
private predicate straightLineSparse(Node scope, int i, Node ni, Spec spec) { private predicate straightLineSparse(Node scope, int i, Node ni, Spec spec) {
scope = scope =
any(Block b | any(BlockStmt b |
i = -1 and ni = b and spec.isAt() i = -1 and ni = b and spec.isAt()
or or
if exists(getLastControlOrderChild(b)) if exists(getLastControlOrderChild(b))
@@ -734,7 +734,7 @@ private predicate straightLineSparse(Node scope, int i, Node ni, Spec spec) {
or or
// If the switch body is not a block then this step is skipped, and the // If the switch body is not a block then this step is skipped, and the
// expression jumps directly to the cases. // expression jumps directly to the cases.
i = 1 and ni = s.getStmt().(Block) and spec.isAt() i = 1 and ni = s.getStmt().(BlockStmt) and spec.isAt()
or or
i = 2 and ni = s.getASwitchCase() and spec.isBefore() i = 2 and ni = s.getASwitchCase() and spec.isBefore()
or or
@@ -1010,7 +1010,7 @@ private predicate subEdgeIncludingDestructors(Pos p1, Node n1, Node n2, Pos p2)
* The exact placement of that call in the CFG depends on the type of * The exact placement of that call in the CFG depends on the type of
* `node` as follows: * `node` as follows:
* *
* - `Block`: after ordinary control flow falls off the end of the block * - `BlockStmt`: after ordinary control flow falls off the end of the block
* without jumps or exceptions. * without jumps or exceptions.
* - `ReturnStmt`: After the statement itself or after its operand (if * - `ReturnStmt`: After the statement itself or after its operand (if
* present). * present).

View File

@@ -182,7 +182,7 @@ private int switchCaseRangeEnd(SwitchCase sc) {
* body `switchBlock`. There may be several such expressions: for example, if * body `switchBlock`. There may be several such expressions: for example, if
* the condition is `(x ? y : z)` then the result is {`y`, `z`}. * the condition is `(x ? y : z)` then the result is {`y`, `z`}.
*/ */
private Node getASwitchExpr(SwitchStmt switch, Block switchBlock) { private Node getASwitchExpr(SwitchStmt switch, BlockStmt switchBlock) {
switch.getStmt() = switchBlock and switch.getStmt() = switchBlock and
successors_extended(result, switchBlock) successors_extended(result, switchBlock)
} }
@@ -192,7 +192,7 @@ private Node getASwitchExpr(SwitchStmt switch, Block switchBlock) {
* from `switchBlock` to `sc` is impossible. This considers only non-`default` * from `switchBlock` to `sc` is impossible. This considers only non-`default`
* switch cases. * switch cases.
*/ */
private predicate impossibleSwitchEdge(Block switchBlock, SwitchCase sc) { private predicate impossibleSwitchEdge(BlockStmt switchBlock, SwitchCase sc) {
not sc instanceof DefaultCase and not sc instanceof DefaultCase and
exists(SwitchStmt switch | exists(SwitchStmt switch |
switch = sc.getSwitchStmt() and switch = sc.getSwitchStmt() and
@@ -215,7 +215,7 @@ private predicate impossibleSwitchEdge(Block switchBlock, SwitchCase sc) {
* If a switch provably always chooses a non-default case, then the edge to * If a switch provably always chooses a non-default case, then the edge to
* the default case is impossible. * the default case is impossible.
*/ */
private predicate impossibleDefaultSwitchEdge(Block switchBlock, DefaultCase dc) { private predicate impossibleDefaultSwitchEdge(BlockStmt switchBlock, DefaultCase dc) {
exists(SwitchStmt switch | exists(SwitchStmt switch |
switch = dc.getSwitchStmt() and switch = dc.getSwitchStmt() and
switch.getStmt() = switchBlock and switch.getStmt() = switchBlock and

View File

@@ -27,7 +27,7 @@ class Expr extends StmtParent, @expr {
Function getEnclosingFunction() { result = exprEnclosingElement(this) } Function getEnclosingFunction() { result = exprEnclosingElement(this) }
/** Gets the nearest enclosing set of curly braces around this expression in the source, if any. */ /** Gets the nearest enclosing set of curly braces around this expression in the source, if any. */
Block getEnclosingBlock() { result = getEnclosingStmt().getEnclosingBlock() } BlockStmt getEnclosingBlock() { result = getEnclosingStmt().getEnclosingBlock() }
override Stmt getEnclosingStmt() { override Stmt getEnclosingStmt() {
result = this.getParent().(Expr).getEnclosingStmt() result = this.getParent().(Expr).getEnclosingStmt()
@@ -1109,7 +1109,7 @@ class StmtExpr extends Expr, @expr_stmt {
/** Get the result expression of a statement. (Helper function for StmtExpr.) */ /** Get the result expression of a statement. (Helper function for StmtExpr.) */
private Expr getStmtResultExpr(Stmt stmt) { private Expr getStmtResultExpr(Stmt stmt) {
result = stmt.(ExprStmt).getExpr() or result = stmt.(ExprStmt).getExpr() or
result = getStmtResultExpr(stmt.(Block).getLastStmt()) result = getStmtResultExpr(stmt.(BlockStmt).getLastStmt())
} }
/** /**

View File

@@ -2905,7 +2905,7 @@ predicate exprNeedsCopyIfNotLoaded(Expr expr) {
private predicate exprImmediatelyDiscarded(Expr expr) { private predicate exprImmediatelyDiscarded(Expr expr) {
exists(ExprStmt s | exists(ExprStmt s |
s = expr.getParent() and s = expr.getParent() and
not exists(StmtExpr se | s = se.getStmt().(Block).getLastStmt()) not exists(StmtExpr se | s = se.getStmt().(BlockStmt).getLastStmt())
) )
or or
exists(CommaExpr c | c.getLeftOperand() = expr) exists(CommaExpr c | c.getLeftOperand() = expr)

View File

@@ -290,7 +290,7 @@ class TranslatedTryStmt extends TranslatedStmt {
} }
class TranslatedBlock extends TranslatedStmt { class TranslatedBlock extends TranslatedStmt {
override Block stmt; override BlockStmt stmt;
override TranslatedElement getChild(int id) { result = getStmt(id) } override TranslatedElement getChild(int id) { result = getStmt(id) }

View File

@@ -334,7 +334,7 @@ private predicate branchingExpr(Expr expr) {
* Gets the number of branching statements and expressions in a block. This is * Gets the number of branching statements and expressions in a block. This is
* for computing cyclomatic complexity. * for computing cyclomatic complexity.
*/ */
int cyclomaticComplexityBranches(Block b) { int cyclomaticComplexityBranches(BlockStmt b) {
result = result =
count(Stmt stmt | count(Stmt stmt |
branchingStmt(stmt) and branchingStmt(stmt) and
@@ -373,7 +373,7 @@ private predicate skipParent(Stmt s) {
exists(Stmt parent | parent = s.getParentStmt() | exists(Stmt parent | parent = s.getParentStmt() |
s instanceof IfStmt and parent.(IfStmt).getElse() = s s instanceof IfStmt and parent.(IfStmt).getElse() = s
or or
parent instanceof Block parent instanceof BlockStmt
or or
exists(File f, int startLine, int startCol | exists(File f, int startLine, int startCol |
startsAt(s, f, startLine, startCol) and startsAt(s, f, startLine, startCol) and

View File

@@ -17,8 +17,8 @@ import semmle.code.cpp.stmts.Stmt
* } * }
* ``` * ```
*/ */
class Block extends Stmt, @stmt_block { class BlockStmt extends Stmt, @stmt_block {
override string getAPrimaryQlClass() { result = "Block" } override string getAPrimaryQlClass() { result = "BlockStmt" }
/** /**
* Gets a child declaration of this block. * Gets a child declaration of this block.
@@ -76,8 +76,8 @@ class Block extends Stmt, @stmt_block {
* the result is the expression statement `a = b`. * the result is the expression statement `a = b`.
*/ */
Stmt getLastStmtIn() { Stmt getLastStmtIn() {
if getLastStmt() instanceof Block if getLastStmt() instanceof BlockStmt
then result = getLastStmt().(Block).getLastStmtIn() then result = getLastStmt().(BlockStmt).getLastStmtIn()
else result = getLastStmt() else result = getLastStmt()
} }
@@ -126,3 +126,9 @@ class Block extends Stmt, @stmt_block {
override predicate mayBeGloballyImpure() { this.getAStmt().mayBeGloballyImpure() } override predicate mayBeGloballyImpure() { this.getAStmt().mayBeGloballyImpure() }
} }
/**
* DEPRECATED: This is now called `BlockStmt` to avoid confusion with
* `BasicBlock`.
*/
deprecated class Block = BlockStmt;

View File

@@ -25,10 +25,10 @@ class Stmt extends StmtParent, @stmt {
/** /**
* Gets the nearest enclosing block of this statement in the source, if any. * Gets the nearest enclosing block of this statement in the source, if any.
*/ */
Block getEnclosingBlock() { BlockStmt getEnclosingBlock() {
if if
getParentStmt() instanceof Block and getParentStmt() instanceof BlockStmt and
not getParentStmt().(Block).getLocation() instanceof UnknownLocation not getParentStmt().(BlockStmt).getLocation() instanceof UnknownLocation
then result = getParentStmt() then result = getParentStmt()
else result = getParentStmt().getEnclosingBlock() else result = getParentStmt().getEnclosingBlock()
} }
@@ -53,7 +53,7 @@ class Stmt extends StmtParent, @stmt {
* to trace the flow of control instead. * to trace the flow of control instead.
*/ */
Stmt getFollowingStmt() { Stmt getFollowingStmt() {
exists(Block b, int i | exists(BlockStmt b, int i |
this = b.getStmt(i) and this = b.getStmt(i) and
result = b.getStmt(i + 1) result = b.getStmt(i + 1)
) )
@@ -240,7 +240,7 @@ class IfStmt extends ConditionalStmt, @stmt_if {
* ``` * ```
* if (b) { x = 1; } * if (b) { x = 1; }
* ``` * ```
* the result is the `Block` `{ x = 1; }`. * the result is the `BlockStmt` `{ x = 1; }`.
*/ */
Stmt getThen() { if_then(underlyingElement(this), unresolveElement(result)) } Stmt getThen() { if_then(underlyingElement(this), unresolveElement(result)) }
@@ -251,7 +251,7 @@ class IfStmt extends ConditionalStmt, @stmt_if {
* ``` * ```
* if (b) { x = 1; } else { x = 2; } * if (b) { x = 1; } else { x = 2; }
* ``` * ```
* the result is the `Block` `{ x = 2; }`, and for * the result is the `BlockStmt` `{ x = 2; }`, and for
* ``` * ```
* if (b) { x = 1; } * if (b) { x = 1; }
* ``` * ```
@@ -326,7 +326,7 @@ class ConstexprIfStmt extends ConditionalStmt, @stmt_constexpr_if {
* ``` * ```
* if constexpr (b) { x = 1; } * if constexpr (b) { x = 1; }
* ``` * ```
* the result is the `Block` `{ x = 1; }`. * the result is the `BlockStmt` `{ x = 1; }`.
*/ */
Stmt getThen() { constexpr_if_then(underlyingElement(this), unresolveElement(result)) } Stmt getThen() { constexpr_if_then(underlyingElement(this), unresolveElement(result)) }
@@ -337,7 +337,7 @@ class ConstexprIfStmt extends ConditionalStmt, @stmt_constexpr_if {
* ``` * ```
* if constexpr (b) { x = 1; } else { x = 2; } * if constexpr (b) { x = 1; } else { x = 2; }
* ``` * ```
* the result is the `Block` `{ x = 2; }`, and for * the result is the `BlockStmt` `{ x = 2; }`, and for
* ``` * ```
* if constexpr (b) { x = 1; } * if constexpr (b) { x = 1; }
* ``` * ```
@@ -781,7 +781,7 @@ class RangeBasedForStmt extends Loop, @stmt_range_based_for {
* ``` * ```
* for (int x : xs) { y += x; } * for (int x : xs) { y += x; }
* ``` * ```
* the result is the `Block` `{ y += x; }`. * the result is the `BlockStmt` `{ y += x; }`.
*/ */
override Stmt getStmt() { result = this.getChild(5) } override Stmt getStmt() { result = this.getChild(5) }
@@ -1168,7 +1168,7 @@ class SwitchCase extends Stmt, @stmt_switch_case {
* DEPRECATED: use `SwitchCase.getAStmt` or `ControlFlowNode.getASuccessor` * DEPRECATED: use `SwitchCase.getAStmt` or `ControlFlowNode.getASuccessor`
* rather than this predicate. * rather than this predicate.
* *
* Gets the `Block` statement immediately following this 'switch case' * Gets the `BlockStmt` statement immediately following this 'switch case'
* statement, if any. * statement, if any.
* *
* For example, for * For example, for
@@ -1189,7 +1189,7 @@ class SwitchCase extends Stmt, @stmt_switch_case {
* the `case 7:` has result `{ x = 2; break; }`, `default:` has result * the `case 7:` has result `{ x = 2; break; }`, `default:` has result
* `{ x = 3; }`, and the others have no result. * `{ x = 3; }`, and the others have no result.
*/ */
deprecated Block getLabelledStmt() { deprecated BlockStmt getLabelledStmt() {
exists(int i, Stmt parent | exists(int i, Stmt parent |
this = parent.getChild(i) and this = parent.getChild(i) and
result = parent.getChild(i + 1) result = parent.getChild(i + 1)
@@ -1270,7 +1270,7 @@ class SwitchCase extends Stmt, @stmt_switch_case {
* `default:` has results `{ x = 3; }, `x = 4;` and `break;`. * `default:` has results `{ x = 3; }, `x = 4;` and `break;`.
*/ */
Stmt getAStmt() { Stmt getAStmt() {
exists(Block b, int i, int j | exists(BlockStmt b, int i, int j |
b.getStmt(i) = this and b.getStmt(i) = this and
b.getStmt(j) = result and b.getStmt(j) = result and
i < j and i < j and
@@ -1309,8 +1309,8 @@ class SwitchCase extends Stmt, @stmt_switch_case {
exists(Stmt lastStmt | exists(Stmt lastStmt |
lastStmt = this.getAStmt() and lastStmt = this.getAStmt() and
not lastStmt.getFollowingStmt() = this.getAStmt() and not lastStmt.getFollowingStmt() = this.getAStmt() and
if lastStmt instanceof Block if lastStmt instanceof BlockStmt
then result = lastStmt.(Block).getLastStmtIn() then result = lastStmt.(BlockStmt).getLastStmtIn()
else result = lastStmt else result = lastStmt
) )
} }
@@ -1467,7 +1467,7 @@ class SwitchStmt extends ConditionalStmt, @stmt_switch {
/** /**
* Gets the body statement of this 'switch' statement. * Gets the body statement of this 'switch' statement.
* *
* In almost all cases the result will be a `Block`, but there are * In almost all cases the result will be a `BlockStmt`, but there are
* other syntactically valid constructions. * other syntactically valid constructions.
* *
* For example, for * For example, for
@@ -1798,7 +1798,7 @@ class FunctionTryStmt extends TryStmt {
* } * }
* ``` * ```
*/ */
class CatchBlock extends Block { class CatchBlock extends BlockStmt {
override string getAPrimaryQlClass() { result = "CatchBlock" } override string getAPrimaryQlClass() { result = "CatchBlock" }
CatchBlock() { ishandler(underlyingElement(this)) } CatchBlock() { ishandler(underlyingElement(this)) }
@@ -1864,7 +1864,7 @@ class MicrosoftTryExceptStmt extends MicrosoftTryStmt {
/** Gets the expression guarding the `__except` statement. */ /** Gets the expression guarding the `__except` statement. */
Expr getCondition() { result = getChild(1) } Expr getCondition() { result = getChild(1) }
/** Gets the `__except` statement (usually a `Block`). */ /** Gets the `__except` statement (usually a `BlockStmt`). */
Stmt getExcept() { result = getChild(2) } Stmt getExcept() { result = getChild(2) }
override string getAPrimaryQlClass() { result = "MicrosoftTryExceptStmt" } override string getAPrimaryQlClass() { result = "MicrosoftTryExceptStmt" }
@@ -1888,7 +1888,7 @@ class MicrosoftTryFinallyStmt extends MicrosoftTryStmt {
override string toString() { result = "__try { ... } __finally { ... }" } override string toString() { result = "__try { ... } __finally { ... }" }
/** Gets the `__finally` statement (usually a `Block`). */ /** Gets the `__finally` statement (usually a `BlockStmt`). */
Stmt getFinally() { result = getChild(1) } Stmt getFinally() { result = getChild(1) }
override string getAPrimaryQlClass() { result = "MicrosoftTryFinallyStmt" } override string getAPrimaryQlClass() { result = "MicrosoftTryFinallyStmt" }
@@ -2047,7 +2047,7 @@ class VlaDeclStmt extends Stmt, @stmt_vla_decl {
* declaration statement. * declaration statement.
*/ */
int getNumberOfVlaDimensionStmts() { int getNumberOfVlaDimensionStmts() {
exists(Block b, int j | exists(BlockStmt b, int j |
this = b.getStmt(j) and this = b.getStmt(j) and
result = result =
j - 1 - j - 1 -
@@ -2064,7 +2064,7 @@ class VlaDeclStmt extends Stmt, @stmt_vla_decl {
*/ */
VlaDimensionStmt getVlaDimensionStmt(int i) { VlaDimensionStmt getVlaDimensionStmt(int i) {
i in [0 .. this.getNumberOfVlaDimensionStmts() - 1] and i in [0 .. this.getNumberOfVlaDimensionStmts() - 1] and
exists(Block b, int j | exists(BlockStmt b, int j |
this = b.getStmt(j) and this = b.getStmt(j) and
result = b.getStmt(j - this.getNumberOfVlaDimensionStmts() + i) result = b.getStmt(j - this.getNumberOfVlaDimensionStmts() + i)
) )

View File

@@ -19,7 +19,7 @@ AddressOf.c:
# 1| params: # 1| params:
# 1| 0: [Parameter] i # 1| 0: [Parameter] i
# 1| Type = [IntType] int # 1| Type = [IntType] int
# 1| body: [Block] { ... } # 1| body: [BlockStmt] { ... }
# 2| 0: [DeclStmt] declaration # 2| 0: [DeclStmt] declaration
# 2| 0: [VariableDeclarationEntry] definition of j # 2| 0: [VariableDeclarationEntry] definition of j
# 2| Type = [IntPointerType] int * # 2| Type = [IntPointerType] int *
@@ -34,7 +34,7 @@ AddressOf.c:
ArrayToPointer.c: ArrayToPointer.c:
# 5| [TopLevelFunction] void ArrayToPointer() # 5| [TopLevelFunction] void ArrayToPointer()
# 5| params: # 5| params:
# 6| body: [Block] { ... } # 6| body: [BlockStmt] { ... }
# 7| 0: [DeclStmt] declaration # 7| 0: [DeclStmt] declaration
# 7| 0: [VariableDeclarationEntry] definition of c # 7| 0: [VariableDeclarationEntry] definition of c
# 7| Type = [ArrayType] char[] # 7| Type = [ArrayType] char[]
@@ -70,7 +70,7 @@ Cast.c:
# 1| Type = [CharPointerType] char * # 1| Type = [CharPointerType] char *
# 1| 1: [Parameter] v # 1| 1: [Parameter] v
# 1| Type = [VoidPointerType] void * # 1| Type = [VoidPointerType] void *
# 1| body: [Block] { ... } # 1| body: [BlockStmt] { ... }
# 2| 0: [ExprStmt] ExprStmt # 2| 0: [ExprStmt] ExprStmt
# 2| 0: [AssignExpr] ... = ... # 2| 0: [AssignExpr] ... = ...
# 2| Type = [CharPointerType] char * # 2| Type = [CharPointerType] char *
@@ -89,7 +89,7 @@ Cast.c:
ConditionDecl.cpp: ConditionDecl.cpp:
# 1| [TopLevelFunction] void ConditionDecl() # 1| [TopLevelFunction] void ConditionDecl()
# 1| params: # 1| params:
# 1| body: [Block] { ... } # 1| body: [BlockStmt] { ... }
# 2| 0: [DeclStmt] declaration # 2| 0: [DeclStmt] declaration
# 2| 0: [VariableDeclarationEntry] definition of j # 2| 0: [VariableDeclarationEntry] definition of j
# 2| Type = [IntType] int # 2| Type = [IntType] int
@@ -109,7 +109,7 @@ ConditionDecl.cpp:
# 3| expr: [VariableAccess] k # 3| expr: [VariableAccess] k
# 3| Type = [IntType] int # 3| Type = [IntType] int
# 3| ValueCategory = prvalue(load) # 3| ValueCategory = prvalue(load)
# 3| 1: [Block] { ... } # 3| 1: [BlockStmt] { ... }
# 5| 2: [ReturnStmt] return ... # 5| 2: [ReturnStmt] return ...
ConstructorCall.cpp: ConstructorCall.cpp:
# 1| [CopyAssignmentOperator] C& C::operator=(C const&) # 1| [CopyAssignmentOperator] C& C::operator=(C const&)
@@ -133,7 +133,7 @@ ConstructorCall.cpp:
# 3| 0: [Parameter] i # 3| 0: [Parameter] i
# 3| Type = [IntType] int # 3| Type = [IntType] int
# 3| initializations: # 3| initializations:
# 3| body: [Block] { ... } # 3| body: [BlockStmt] { ... }
# 4| 0: [ReturnStmt] return ... # 4| 0: [ReturnStmt] return ...
# 7| [CopyAssignmentOperator] D& D::operator=(D const&) # 7| [CopyAssignmentOperator] D& D::operator=(D const&)
# 7| params: # 7| params:
@@ -154,7 +154,7 @@ ConstructorCall.cpp:
# 9| [Constructor] void D::D() # 9| [Constructor] void D::D()
# 9| params: # 9| params:
# 9| initializations: # 9| initializations:
# 9| body: [Block] { ... } # 9| body: [BlockStmt] { ... }
# 10| 0: [ReturnStmt] return ... # 10| 0: [ReturnStmt] return ...
# 13| [CopyAssignmentOperator] E& E::operator=(E const&) # 13| [CopyAssignmentOperator] E& E::operator=(E const&)
# 13| params: # 13| params:
@@ -172,7 +172,7 @@ ConstructorCall.cpp:
# 17| Type = [PointerType] D * # 17| Type = [PointerType] D *
# 17| 2: [Parameter] e # 17| 2: [Parameter] e
# 17| Type = [PointerType] E * # 17| Type = [PointerType] E *
# 17| body: [Block] { ... } # 17| body: [BlockStmt] { ... }
# 18| 0: [ExprStmt] ExprStmt # 18| 0: [ExprStmt] ExprStmt
# 18| 0: [AssignExpr] ... = ... # 18| 0: [AssignExpr] ... = ...
# 18| Type = [PointerType] C * # 18| Type = [PointerType] C *
@@ -221,7 +221,7 @@ ConstructorCall.cpp:
Conversion1.c: Conversion1.c:
# 1| [TopLevelFunction] void Conversion1() # 1| [TopLevelFunction] void Conversion1()
# 1| params: # 1| params:
# 1| body: [Block] { ... } # 1| body: [BlockStmt] { ... }
# 2| 0: [DeclStmt] declaration # 2| 0: [DeclStmt] declaration
# 2| 0: [VariableDeclarationEntry] definition of i # 2| 0: [VariableDeclarationEntry] definition of i
# 2| Type = [IntType] int # 2| Type = [IntType] int
@@ -241,7 +241,7 @@ Conversion2.c:
# 1| params: # 1| params:
# 1| 0: [Parameter] x # 1| 0: [Parameter] x
# 1| Type = [IntType] int # 1| Type = [IntType] int
# 1| body: [Block] { ... } # 1| body: [BlockStmt] { ... }
# 2| 0: [ExprStmt] ExprStmt # 2| 0: [ExprStmt] ExprStmt
# 2| 0: [AssignExpr] ... = ... # 2| 0: [AssignExpr] ... = ...
# 2| Type = [IntType] int # 2| Type = [IntType] int
@@ -277,7 +277,7 @@ Conversion3.cpp:
# 1| params: # 1| params:
# 1| 0: [Parameter] x # 1| 0: [Parameter] x
# 1| Type = [IntType] int # 1| Type = [IntType] int
# 1| body: [Block] { ... } # 1| body: [BlockStmt] { ... }
# 2| 0: [ExprStmt] ExprStmt # 2| 0: [ExprStmt] ExprStmt
# 2| 0: [AssignExpr] ... = ... # 2| 0: [AssignExpr] ... = ...
# 2| Type = [IntType] int # 2| Type = [IntType] int
@@ -327,7 +327,7 @@ Conversion4.c:
# 1| params: # 1| params:
# 1| 0: [Parameter] x # 1| 0: [Parameter] x
# 1| Type = [IntType] int # 1| Type = [IntType] int
# 1| body: [Block] { ... } # 1| body: [BlockStmt] { ... }
# 2| 0: [ExprStmt] ExprStmt # 2| 0: [ExprStmt] ExprStmt
# 2| 0: [AssignExpr] ... = ... # 2| 0: [AssignExpr] ... = ...
# 2| Type = [IntType] int # 2| Type = [IntType] int
@@ -352,7 +352,7 @@ Conversion4.c:
DestructorCall.cpp: DestructorCall.cpp:
# 3| [Destructor] void C::~C() # 3| [Destructor] void C::~C()
# 3| params: # 3| params:
# 3| body: [Block] { ... } # 3| body: [BlockStmt] { ... }
# 4| 0: [ReturnStmt] return ... # 4| 0: [ReturnStmt] return ...
# 3| destructions: # 3| destructions:
# 11| [TopLevelFunction] void DestructorCall(C*, D*) # 11| [TopLevelFunction] void DestructorCall(C*, D*)
@@ -361,7 +361,7 @@ DestructorCall.cpp:
# 11| Type = [PointerType] C * # 11| Type = [PointerType] C *
# 11| 1: [Parameter] d # 11| 1: [Parameter] d
# 11| Type = [PointerType] D * # 11| Type = [PointerType] D *
# 11| body: [Block] { ... } # 11| body: [BlockStmt] { ... }
# 12| 0: [ExprStmt] ExprStmt # 12| 0: [ExprStmt] ExprStmt
# 12| 0: [DeleteExpr] delete # 12| 0: [DeleteExpr] delete
# 12| Type = [VoidType] void # 12| Type = [VoidType] void
@@ -385,7 +385,7 @@ DynamicCast.cpp:
# 1| params: # 1| params:
#-----| 0: [Parameter] p#0 #-----| 0: [Parameter] p#0
#-----| Type = [LValueReferenceType] const Base & #-----| Type = [LValueReferenceType] const Base &
#-----| body: [Block] { ... } #-----| body: [BlockStmt] { ... }
#-----| 0: [ReturnStmt] return ... #-----| 0: [ReturnStmt] return ...
#-----| 0: [ReferenceToExpr] (reference to) #-----| 0: [ReferenceToExpr] (reference to)
#-----| Type = [LValueReferenceType] Base & #-----| Type = [LValueReferenceType] Base &
@@ -412,13 +412,13 @@ DynamicCast.cpp:
#-----| Type = [RValueReferenceType] Base && #-----| Type = [RValueReferenceType] Base &&
# 2| [VirtualFunction] void Base::f() # 2| [VirtualFunction] void Base::f()
# 2| params: # 2| params:
# 2| body: [Block] { ... } # 2| body: [BlockStmt] { ... }
# 2| 0: [ReturnStmt] return ... # 2| 0: [ReturnStmt] return ...
# 4| [CopyAssignmentOperator] Derived& Derived::operator=(Derived const&) # 4| [CopyAssignmentOperator] Derived& Derived::operator=(Derived const&)
# 4| params: # 4| params:
#-----| 0: [Parameter] p#0 #-----| 0: [Parameter] p#0
#-----| Type = [LValueReferenceType] const Derived & #-----| Type = [LValueReferenceType] const Derived &
#-----| body: [Block] { ... } #-----| body: [BlockStmt] { ... }
#-----| 0: [ExprStmt] ExprStmt #-----| 0: [ExprStmt] ExprStmt
#-----| 0: [ReferenceDereferenceExpr] (reference dereference) #-----| 0: [ReferenceDereferenceExpr] (reference dereference)
#-----| Type = [Class] Base #-----| Type = [Class] Base
@@ -478,7 +478,7 @@ DynamicCast.cpp:
#-----| Type = [RValueReferenceType] Derived && #-----| Type = [RValueReferenceType] Derived &&
# 5| [VirtualFunction] void Derived::f() # 5| [VirtualFunction] void Derived::f()
# 5| params: # 5| params:
# 5| body: [Block] { ... } # 5| body: [BlockStmt] { ... }
# 5| 0: [ReturnStmt] return ... # 5| 0: [ReturnStmt] return ...
# 8| [TopLevelFunction] void DynamicCast(Base*, Derived*) # 8| [TopLevelFunction] void DynamicCast(Base*, Derived*)
# 8| params: # 8| params:
@@ -486,7 +486,7 @@ DynamicCast.cpp:
# 8| Type = [PointerType] Base * # 8| Type = [PointerType] Base *
# 8| 1: [Parameter] d # 8| 1: [Parameter] d
# 8| Type = [PointerType] Derived * # 8| Type = [PointerType] Derived *
# 8| body: [Block] { ... } # 8| body: [BlockStmt] { ... }
# 9| 0: [ExprStmt] ExprStmt # 9| 0: [ExprStmt] ExprStmt
# 9| 0: [AssignExpr] ... = ... # 9| 0: [AssignExpr] ... = ...
# 9| Type = [PointerType] Derived * # 9| Type = [PointerType] Derived *
@@ -508,7 +508,7 @@ DynamicCast.cpp:
# 12| Type = [LValueReferenceType] Base & # 12| Type = [LValueReferenceType] Base &
# 12| 1: [Parameter] d # 12| 1: [Parameter] d
# 12| Type = [LValueReferenceType] Derived & # 12| Type = [LValueReferenceType] Derived &
# 12| body: [Block] { ... } # 12| body: [BlockStmt] { ... }
# 13| 0: [ExprStmt] ExprStmt # 13| 0: [ExprStmt] ExprStmt
# 13| 0: [ReferenceDereferenceExpr] (reference dereference) # 13| 0: [ReferenceDereferenceExpr] (reference dereference)
# 13| Type = [Class] Derived # 13| Type = [Class] Derived
@@ -545,7 +545,7 @@ Parenthesis.c:
# 1| params: # 1| params:
# 1| 0: [Parameter] i # 1| 0: [Parameter] i
# 1| Type = [IntType] int # 1| Type = [IntType] int
# 1| body: [Block] { ... } # 1| body: [BlockStmt] { ... }
# 2| 0: [ExprStmt] ExprStmt # 2| 0: [ExprStmt] ExprStmt
# 2| 0: [AssignExpr] ... = ... # 2| 0: [AssignExpr] ... = ...
# 2| Type = [IntType] int # 2| Type = [IntType] int
@@ -581,7 +581,7 @@ PointerDereference.c:
# 1| Type = [IntPointerType] int * # 1| Type = [IntPointerType] int *
# 1| 1: [Parameter] j # 1| 1: [Parameter] j
# 1| Type = [IntType] int # 1| Type = [IntType] int
# 1| body: [Block] { ... } # 1| body: [BlockStmt] { ... }
# 2| 0: [ExprStmt] ExprStmt # 2| 0: [ExprStmt] ExprStmt
# 2| 0: [AssignExpr] ... = ... # 2| 0: [AssignExpr] ... = ...
# 2| Type = [IntType] int # 2| Type = [IntType] int
@@ -603,7 +603,7 @@ ReferenceDereference.cpp:
# 4| Type = [LValueReferenceType] int & # 4| Type = [LValueReferenceType] int &
# 4| 1: [Parameter] j # 4| 1: [Parameter] j
# 4| Type = [IntType] int # 4| Type = [IntType] int
# 4| body: [Block] { ... } # 4| body: [BlockStmt] { ... }
# 5| 0: [ExprStmt] ExprStmt # 5| 0: [ExprStmt] ExprStmt
# 5| 0: [AssignExpr] ... = ... # 5| 0: [AssignExpr] ... = ...
# 5| Type = [IntType] int # 5| Type = [IntType] int
@@ -623,7 +623,7 @@ ReferenceTo.cpp:
# 1| params: # 1| params:
# 1| 0: [Parameter] i # 1| 0: [Parameter] i
# 1| Type = [IntPointerType] int * # 1| Type = [IntPointerType] int *
# 1| body: [Block] { ... } # 1| body: [BlockStmt] { ... }
# 2| 0: [ReturnStmt] return ... # 2| 0: [ReturnStmt] return ...
# 2| 0: [ReferenceToExpr] (reference to) # 2| 0: [ReferenceToExpr] (reference to)
# 2| Type = [LValueReferenceType] int & # 2| Type = [LValueReferenceType] int &
@@ -639,7 +639,7 @@ Sizeof.c:
# 1| params: # 1| params:
# 1| 0: [Parameter] array # 1| 0: [Parameter] array
# 1| Type = [ArrayType] int[] # 1| Type = [ArrayType] int[]
# 1| body: [Block] { ... } # 1| body: [BlockStmt] { ... }
# 2| 0: [DeclStmt] declaration # 2| 0: [DeclStmt] declaration
# 2| 0: [VariableDeclarationEntry] definition of i # 2| 0: [VariableDeclarationEntry] definition of i
# 2| Type = [IntType] int # 2| Type = [IntType] int
@@ -676,7 +676,7 @@ Sizeof.c:
StatementExpr.c: StatementExpr.c:
# 1| [TopLevelFunction] void StatementExpr() # 1| [TopLevelFunction] void StatementExpr()
# 1| params: # 1| params:
# 1| body: [Block] { ... } # 1| body: [BlockStmt] { ... }
# 2| 0: [DeclStmt] declaration # 2| 0: [DeclStmt] declaration
# 2| 0: [VariableDeclarationEntry] definition of j # 2| 0: [VariableDeclarationEntry] definition of j
# 2| Type = [IntType] int # 2| Type = [IntType] int
@@ -700,7 +700,7 @@ StaticMemberAccess.cpp:
# 5| Type = [IntType] int # 5| Type = [IntType] int
# 5| 1: [Parameter] xref # 5| 1: [Parameter] xref
# 5| Type = [LValueReferenceType] X & # 5| Type = [LValueReferenceType] X &
# 5| body: [Block] { ... } # 5| body: [BlockStmt] { ... }
# 7| 0: [ExprStmt] ExprStmt # 7| 0: [ExprStmt] ExprStmt
# 7| 0: [AssignExpr] ... = ... # 7| 0: [AssignExpr] ... = ...
# 7| Type = [IntType] int # 7| Type = [IntType] int
@@ -725,7 +725,7 @@ Subscript.c:
# 1| Type = [ArrayType] int[] # 1| Type = [ArrayType] int[]
# 1| 1: [Parameter] j # 1| 1: [Parameter] j
# 1| Type = [IntType] int # 1| Type = [IntType] int
# 1| body: [Block] { ... } # 1| body: [BlockStmt] { ... }
# 2| 0: [ExprStmt] ExprStmt # 2| 0: [ExprStmt] ExprStmt
# 2| 0: [AssignExpr] ... = ... # 2| 0: [AssignExpr] ... = ...
# 2| Type = [IntType] int # 2| Type = [IntType] int
@@ -762,20 +762,20 @@ Throw.cpp:
#-----| 0: [Parameter] p#0 #-----| 0: [Parameter] p#0
#-----| Type = [RValueReferenceType] F && #-----| Type = [RValueReferenceType] F &&
# 2| initializations: # 2| initializations:
# 2| body: [Block] { ... } # 2| body: [BlockStmt] { ... }
# 2| 0: [ReturnStmt] return ... # 2| 0: [ReturnStmt] return ...
# 4| [Constructor] void F::F() # 4| [Constructor] void F::F()
# 4| params: # 4| params:
# 4| initializations: # 4| initializations:
# 4| body: [Block] { ... } # 4| body: [BlockStmt] { ... }
# 4| 0: [ReturnStmt] return ... # 4| 0: [ReturnStmt] return ...
# 6| [TopLevelFunction] void Throw(int) # 6| [TopLevelFunction] void Throw(int)
# 6| params: # 6| params:
# 6| 0: [Parameter] i # 6| 0: [Parameter] i
# 6| Type = [IntType] int # 6| Type = [IntType] int
# 6| body: [Block] { ... } # 6| body: [BlockStmt] { ... }
# 7| 0: [TryStmt] try { ... } # 7| 0: [TryStmt] try { ... }
# 7| 0: [Block] { ... } # 7| 0: [BlockStmt] { ... }
# 8| 0: [IfStmt] if (...) ... # 8| 0: [IfStmt] if (...) ...
# 8| 0: [CStyleCast] (bool)... # 8| 0: [CStyleCast] (bool)...
# 8| Conversion = [BoolConversion] conversion to bool # 8| Conversion = [BoolConversion] conversion to bool
@@ -818,13 +818,13 @@ Typeid.cpp:
# 7| params: # 7| params:
# 13| [VirtualFunction] void Base::v() # 13| [VirtualFunction] void Base::v()
# 13| params: # 13| params:
# 13| body: [Block] { ... } # 13| body: [BlockStmt] { ... }
# 13| 0: [ReturnStmt] return ... # 13| 0: [ReturnStmt] return ...
# 18| [TopLevelFunction] void TypeId(Base*) # 18| [TopLevelFunction] void TypeId(Base*)
# 18| params: # 18| params:
# 18| 0: [Parameter] bp # 18| 0: [Parameter] bp
# 18| Type = [PointerType] Base * # 18| Type = [PointerType] Base *
# 18| body: [Block] { ... } # 18| body: [BlockStmt] { ... }
# 19| 0: [DeclStmt] declaration # 19| 0: [DeclStmt] declaration
# 19| 0: [VariableDeclarationEntry] definition of name # 19| 0: [VariableDeclarationEntry] definition of name
# 19| Type = [PointerType] const char * # 19| Type = [PointerType] const char *
@@ -846,7 +846,7 @@ VacuousDestructorCall.cpp:
# 2| Type = [TemplateParameter] T # 2| Type = [TemplateParameter] T
# 2| 1: [Parameter] y # 2| 1: [Parameter] y
# 2| Type = [PointerType] T * # 2| Type = [PointerType] T *
# 2| body: [Block] { ... } # 2| body: [BlockStmt] { ... }
# 3| 0: [ExprStmt] ExprStmt # 3| 0: [ExprStmt] ExprStmt
# 3| 0: [ExprCall] call to expression # 3| 0: [ExprCall] call to expression
# 3| Type = [UnknownType] unknown # 3| Type = [UnknownType] unknown
@@ -874,7 +874,7 @@ VacuousDestructorCall.cpp:
# 2| Type = [IntType] int # 2| Type = [IntType] int
# 2| 1: [Parameter] y # 2| 1: [Parameter] y
# 2| Type = [IntPointerType] int * # 2| Type = [IntPointerType] int *
# 2| body: [Block] { ... } # 2| body: [BlockStmt] { ... }
# 3| 0: [ExprStmt] ExprStmt # 3| 0: [ExprStmt] ExprStmt
# 3| 0: [VacuousDestructorCall] (vacuous destructor call) # 3| 0: [VacuousDestructorCall] (vacuous destructor call)
# 3| Type = [VoidType] void # 3| Type = [VoidType] void
@@ -894,7 +894,7 @@ VacuousDestructorCall.cpp:
# 7| params: # 7| params:
# 7| 0: [Parameter] i # 7| 0: [Parameter] i
# 7| Type = [IntType] int # 7| Type = [IntType] int
# 7| body: [Block] { ... } # 7| body: [BlockStmt] { ... }
# 10| 0: [ExprStmt] ExprStmt # 10| 0: [ExprStmt] ExprStmt
# 10| 0: [FunctionCall] call to CallDestructor # 10| 0: [FunctionCall] call to CallDestructor
# 10| Type = [VoidType] void # 10| Type = [VoidType] void
@@ -914,7 +914,7 @@ Varargs.c:
# 8| params: # 8| params:
# 8| 0: [Parameter] text # 8| 0: [Parameter] text
# 8| Type = [PointerType] const char * # 8| Type = [PointerType] const char *
# 8| body: [Block] { ... } # 8| body: [BlockStmt] { ... }
# 9| 0: [DeclStmt] declaration # 9| 0: [DeclStmt] declaration
# 9| 0: [VariableDeclarationEntry] definition of args # 9| 0: [VariableDeclarationEntry] definition of args
# 9| Type = [CTypedefType] va_list # 9| Type = [CTypedefType] va_list
@@ -947,7 +947,7 @@ macro_etc.c:
# 3| params: # 3| params:
# 3| 0: [Parameter] i # 3| 0: [Parameter] i
# 3| Type = [IntType] int # 3| Type = [IntType] int
# 3| body: [Block] { ... } # 3| body: [BlockStmt] { ... }
# 4| 0: [DeclStmt] declaration # 4| 0: [DeclStmt] declaration
# 4| 0: [TypeDeclarationEntry] definition of u # 4| 0: [TypeDeclarationEntry] definition of u
# 4| Type = [LocalUnion] u # 4| Type = [LocalUnion] u
@@ -997,7 +997,7 @@ macro_etc.c:
# 10| ValueCategory = prvalue # 10| ValueCategory = prvalue
# 22| [TopLevelFunction] int foo() # 22| [TopLevelFunction] int foo()
# 22| params: # 22| params:
# 22| body: [Block] { ... } # 22| body: [BlockStmt] { ... }
# 23| 0: [DeclStmt] declaration # 23| 0: [DeclStmt] declaration
# 23| 0: [VariableDeclarationEntry] definition of t # 23| 0: [VariableDeclarationEntry] definition of t
# 23| Type = [IntType] int # 23| Type = [IntType] int
@@ -1059,7 +1059,7 @@ macro_etc.c:
# 27| 0: [VariableAccess] i # 27| 0: [VariableAccess] i
# 27| Type = [PlainCharType] char # 27| Type = [PlainCharType] char
# 27| ValueCategory = lvalue # 27| ValueCategory = lvalue
# 27| 3: [Block] { ... } # 27| 3: [BlockStmt] { ... }
# 27| 0: [ExprStmt] ExprStmt # 27| 0: [ExprStmt] ExprStmt
# 27| 0: [AssignAddExpr] ... += ... # 27| 0: [AssignAddExpr] ... += ...
# 27| Type = [IntType] int # 27| Type = [IntType] int
@@ -1111,7 +1111,7 @@ macro_etc.c:
# 28| 0: [VariableAccess] i # 28| 0: [VariableAccess] i
# 28| Type = [PlainCharType] char # 28| Type = [PlainCharType] char
# 28| ValueCategory = lvalue # 28| ValueCategory = lvalue
# 28| 3: [Block] { ... } # 28| 3: [BlockStmt] { ... }
# 28| 0: [ExprStmt] ExprStmt # 28| 0: [ExprStmt] ExprStmt
# 28| 0: [AssignAddExpr] ... += ... # 28| 0: [AssignAddExpr] ... += ...
# 28| Type = [IntType] int # 28| Type = [IntType] int
@@ -1210,7 +1210,7 @@ union_etc.cpp:
# 2| [Constructor] void S::S() # 2| [Constructor] void S::S()
# 2| params: # 2| params:
# 2| initializations: # 2| initializations:
# 2| body: [Block] { ... } # 2| body: [BlockStmt] { ... }
# 2| 0: [ReturnStmt] return ... # 2| 0: [ReturnStmt] return ...
# 2| [CopyConstructor] void S::S(S const&) # 2| [CopyConstructor] void S::S(S const&)
# 2| params: # 2| params:
@@ -1240,7 +1240,7 @@ union_etc.cpp:
# 6| params: # 6| params:
# 6| 0: [Parameter] val # 6| 0: [Parameter] val
# 6| Type = [IntType] int # 6| Type = [IntType] int
# 6| body: [Block] { ... } # 6| body: [BlockStmt] { ... }
# 6| 0: [ExprStmt] ExprStmt # 6| 0: [ExprStmt] ExprStmt
# 6| 0: [AssignExpr] ... = ... # 6| 0: [AssignExpr] ... = ...
# 6| Type = [IntType] int # 6| Type = [IntType] int
@@ -1305,7 +1305,7 @@ union_etc.cpp:
#-----| Type = [RValueReferenceType] C && #-----| Type = [RValueReferenceType] C &&
# 22| [TopLevelFunction] int foo() # 22| [TopLevelFunction] int foo()
# 22| params: # 22| params:
# 22| body: [Block] { ... } # 22| body: [BlockStmt] { ... }
# 23| 0: [DeclStmt] declaration # 23| 0: [DeclStmt] declaration
# 23| 0: [VariableDeclarationEntry] definition of s # 23| 0: [VariableDeclarationEntry] definition of s
# 23| Type = [Struct] S # 23| Type = [Struct] S
@@ -1423,7 +1423,7 @@ union_etc.cpp:
# 33| params: # 33| params:
# 33| 0: [Parameter] val # 33| 0: [Parameter] val
# 33| Type = [IntType] int # 33| Type = [IntType] int
# 33| body: [Block] { ... } # 33| body: [BlockStmt] { ... }
# 33| 0: [ExprStmt] ExprStmt # 33| 0: [ExprStmt] ExprStmt
# 33| 0: [AssignExpr] ... = ... # 33| 0: [AssignExpr] ... = ...
# 33| Type = [IntType] int # 33| Type = [IntType] int
@@ -1440,7 +1440,7 @@ union_etc.cpp:
# 33| 1: [ReturnStmt] return ... # 33| 1: [ReturnStmt] return ...
# 36| [TopLevelFunction] int bar() # 36| [TopLevelFunction] int bar()
# 36| params: # 36| params:
# 36| body: [Block] { ... } # 36| body: [BlockStmt] { ... }
# 37| 0: [DeclStmt] declaration # 37| 0: [DeclStmt] declaration
# 37| 0: [VariableDeclarationEntry] definition of s # 37| 0: [VariableDeclarationEntry] definition of s
# 37| Type = [PointerType] const T * # 37| Type = [PointerType] const T *

File diff suppressed because it is too large Load Diff

View File

@@ -1,5 +1,5 @@
import cpp import cpp
from Block b, MacroAccess m from BlockStmt b, MacroAccess m
where affectedbymacroexpansion(unresolveElement(b), unresolveElement(m)) where affectedbymacroexpansion(unresolveElement(b), unresolveElement(m))
select b, m select b, m

View File

@@ -1,5 +1,5 @@
import cpp import cpp
from Block b, MacroAccess m from BlockStmt b, MacroAccess m
where inmacroexpansion(unresolveElement(b), unresolveElement(m)) where inmacroexpansion(unresolveElement(b), unresolveElement(m))
select b, m select b, m

View File

@@ -1,5 +1,5 @@
import cpp import cpp
from Function f, Block b from Function f, BlockStmt b
where b = f.getEntryPoint() where b = f.getEntryPoint()
select f, b, b.getAStmt() select f, b, b.getAStmt()

View File

@@ -1,6 +1,6 @@
import cpp import cpp
from Function f1, Block body, Declaration d from Function f1, BlockStmt body, Declaration d
where where
body = f1.getBlock() and body = f1.getBlock() and
d = body.getADeclaration() d = body.getADeclaration()

View File

@@ -1,4 +1,4 @@
import cpp import cpp
from Block b, int i from BlockStmt b, int i
select b, i, b.getStmt(i) select b, i, b.getStmt(i)

View File

@@ -1,6 +1,6 @@
import cpp import cpp
from Block s, int i, Stmt f, boolean succ from BlockStmt s, int i, Stmt f, boolean succ
where where
s.getParentStmt().hasChild(s, i) and s.getParentStmt().hasChild(s, i) and
s.getParentStmt().hasChild(f, i + 1) and s.getParentStmt().hasChild(f, i + 1) and

View File

@@ -8,7 +8,7 @@ import cpp
from DoStmt ds, ExprStmt last, Expr succ from DoStmt ds, ExprStmt last, Expr succ
where where
ds.getEnclosingFunction().hasName("normal") and ds.getEnclosingFunction().hasName("normal") and
last = ds.getStmt().(Block).getLastStmt() and last = ds.getStmt().(BlockStmt).getLastStmt() and
succ = last.getExpr().getASuccessor() and succ = last.getExpr().getASuccessor() and
succ = ds.getCondition().getAChild*() and succ = ds.getCondition().getAChild*() and
count(last.getExpr().getASuccessor()) = 1 count(last.getExpr().getASuccessor()) = 1

View File

@@ -9,7 +9,7 @@ import cpp
from ForStmt fs, ExprStmt last, Expr succ from ForStmt fs, ExprStmt last, Expr succ
where where
fs.getEnclosingFunction().hasName("normal") and fs.getEnclosingFunction().hasName("normal") and
last = fs.getStmt().(Block).getLastStmt() and last = fs.getStmt().(BlockStmt).getLastStmt() and
succ = fs.getCondition().getAChild*() and succ = fs.getCondition().getAChild*() and
succ = last.getExpr().getASuccessor() and succ = last.getExpr().getASuccessor() and
count(last.getExpr().getASuccessor()) = 1 count(last.getExpr().getASuccessor()) = 1

View File

@@ -10,7 +10,7 @@ where
is.getEnclosingFunction().hasName("normal") and is.getEnclosingFunction().hasName("normal") and
is.getParentStmt().hasChild(is, k) and is.getParentStmt().hasChild(is, k) and
is.getParentStmt().hasChild(l3, k + 1) and is.getParentStmt().hasChild(l3, k + 1) and
last = is.getThen().(Block).getLastStmt() and last = is.getThen().(BlockStmt).getLastStmt() and
l3 = last.getASuccessor() and l3 = last.getASuccessor() and
count(last.getASuccessor()) = 1 count(last.getASuccessor()) = 1
select last, l3.getName() select last, l3.getName()

View File

@@ -10,7 +10,7 @@ where
is.getEnclosingFunction().hasName("normal") and is.getEnclosingFunction().hasName("normal") and
is.getParentStmt().hasChild(is, k) and is.getParentStmt().hasChild(is, k) and
is.getParentStmt().hasChild(l3, k + 1) and is.getParentStmt().hasChild(l3, k + 1) and
last = is.getElse().(Block).getLastStmt() and last = is.getElse().(BlockStmt).getLastStmt() and
l3 = last.getASuccessor() and l3 = last.getASuccessor() and
count(last.getASuccessor()) = 1 count(last.getASuccessor()) = 1
select last, l3.getName() select last, l3.getName()

View File

@@ -5,7 +5,7 @@
import cpp import cpp
from IfStmt is, Block t from IfStmt is, BlockStmt t
where where
is.getEnclosingFunction().hasName("normal") and is.getEnclosingFunction().hasName("normal") and
t = is.getThen() and t = is.getThen() and

View File

@@ -10,7 +10,7 @@ where
is.getEnclosingFunction().hasName("normal") and is.getEnclosingFunction().hasName("normal") and
is.getParentStmt().hasChild(is, k) and is.getParentStmt().hasChild(is, k) and
is.getParentStmt().hasChild(l2, k + 1) and is.getParentStmt().hasChild(l2, k + 1) and
last = is.getThen().(Block).getLastStmt() and last = is.getThen().(BlockStmt).getLastStmt() and
l2 = last.getASuccessor() and l2 = last.getASuccessor() and
count(last.getASuccessor()) = 1 count(last.getASuccessor()) = 1
select last, l2.getName() select last, l2.getName()

View File

@@ -8,7 +8,7 @@ import cpp
from WhileStmt ws, ExprStmt last, Expr succ from WhileStmt ws, ExprStmt last, Expr succ
where where
ws.getEnclosingFunction().hasName("normal") and ws.getEnclosingFunction().hasName("normal") and
last = ws.getStmt().(Block).getLastStmt() and last = ws.getStmt().(BlockStmt).getLastStmt() and
succ = last.getExpr().getASuccessor() and succ = last.getExpr().getASuccessor() and
succ = ws.getCondition().getAChild*() and succ = ws.getCondition().getAChild*() and
count(last.getExpr().getASuccessor()) = 1 count(last.getExpr().getASuccessor()) = 1