mirror of
https://github.com/github/codeql.git
synced 2026-05-05 05:35:13 +02:00
C++: Handle C++17 if initializers
This commit is contained in:
@@ -663,12 +663,16 @@ private predicate namedStmtChildPredicates(Locatable s, Element e, string pred)
|
||||
or
|
||||
s.(ComputedGotoStmt).getExpr() = e and pred = "getExpr()"
|
||||
or
|
||||
s.(ConstexprIfStmt).getInitialization() = e and pred = "getInitialization()"
|
||||
or
|
||||
s.(ConstexprIfStmt).getCondition() = e and pred = "getCondition()"
|
||||
or
|
||||
s.(ConstexprIfStmt).getThen() = e and pred = "getThen()"
|
||||
or
|
||||
s.(ConstexprIfStmt).getElse() = e and pred = "getElse()"
|
||||
or
|
||||
s.(IfStmt).getInitialization() = e and pred = "getInitialization()"
|
||||
or
|
||||
s.(IfStmt).getCondition() = e and pred = "getCondition()"
|
||||
or
|
||||
s.(IfStmt).getThen() = e and pred = "getThen()"
|
||||
|
||||
@@ -836,8 +836,15 @@ private predicate subEdge(Pos p1, Node n1, Node n2, Pos p2) {
|
||||
p2.nodeAt(n2, f)
|
||||
)
|
||||
or
|
||||
// IfStmt -> condition ; { then, else } ->
|
||||
// IfStmt -> [ init -> ] condition ; { then, else } ->
|
||||
exists(IfStmt s |
|
||||
p1.nodeAt(n1, s) and
|
||||
p2.nodeBefore(n2, s.getInitialization())
|
||||
or
|
||||
p1.nodeAfter(n1, s.getInitialization()) and
|
||||
p2.nodeBefore(n2, s.getCondition())
|
||||
or
|
||||
not exists(s.getInitialization()) and
|
||||
p1.nodeAt(n1, s) and
|
||||
p2.nodeBefore(n2, s.getCondition())
|
||||
or
|
||||
@@ -851,8 +858,15 @@ private predicate subEdge(Pos p1, Node n1, Node n2, Pos p2) {
|
||||
p2.nodeAfter(n2, s)
|
||||
)
|
||||
or
|
||||
// ConstexprIfStmt -> condition ; { then, else } -> // same as IfStmt
|
||||
// ConstexprIfStmt -> [ init -> ] condition ; { then, else } -> // same as IfStmt
|
||||
exists(ConstexprIfStmt s |
|
||||
p1.nodeAt(n1, s) and
|
||||
p2.nodeBefore(n2, s.getInitialization())
|
||||
or
|
||||
p1.nodeAfter(n1, s.getInitialization()) and
|
||||
p2.nodeBefore(n2, s.getCondition())
|
||||
or
|
||||
not exists(s.getInitialization()) and
|
||||
p1.nodeAt(n1, s) and
|
||||
p2.nodeBefore(n2, s.getCondition())
|
||||
or
|
||||
|
||||
@@ -421,20 +421,36 @@ class TranslatedCatchAnyHandler extends TranslatedHandler {
|
||||
class TranslatedIfStmt extends TranslatedStmt, ConditionContext {
|
||||
override IfStmt stmt;
|
||||
|
||||
override Instruction getFirstInstruction() { result = getCondition().getFirstInstruction() }
|
||||
override Instruction getFirstInstruction() {
|
||||
if hasInitialization()
|
||||
then result = getInitialization().getFirstInstruction()
|
||||
else result = getFirstConditionInstruction()
|
||||
}
|
||||
|
||||
override TranslatedElement getChild(int id) {
|
||||
id = 0 and result = getCondition()
|
||||
id = 0 and result = getInitialization()
|
||||
or
|
||||
id = 1 and result = getThen()
|
||||
id = 1 and result = getCondition()
|
||||
or
|
||||
id = 2 and result = getElse()
|
||||
id = 2 and result = getThen()
|
||||
or
|
||||
id = 3 and result = getElse()
|
||||
}
|
||||
|
||||
private predicate hasInitialization() { exists(stmt.getInitialization()) }
|
||||
|
||||
private TranslatedStmt getInitialization() {
|
||||
result = getTranslatedStmt(stmt.getInitialization())
|
||||
}
|
||||
|
||||
private TranslatedCondition getCondition() {
|
||||
result = getTranslatedCondition(stmt.getCondition().getFullyConverted())
|
||||
}
|
||||
|
||||
private Instruction getFirstConditionInstruction() {
|
||||
result = getCondition().getFirstInstruction()
|
||||
}
|
||||
|
||||
private TranslatedStmt getThen() { result = getTranslatedStmt(stmt.getThen()) }
|
||||
|
||||
private TranslatedStmt getElse() { result = getTranslatedStmt(stmt.getElse()) }
|
||||
@@ -456,6 +472,9 @@ class TranslatedIfStmt extends TranslatedStmt, ConditionContext {
|
||||
}
|
||||
|
||||
override Instruction getChildSuccessor(TranslatedElement child) {
|
||||
child = getInitialization() and
|
||||
result = getFirstConditionInstruction()
|
||||
or
|
||||
(child = getThen() or child = getElse()) and
|
||||
result = getParent().getChildSuccessor(this)
|
||||
}
|
||||
|
||||
@@ -213,6 +213,26 @@ class ConditionalStmt extends ControlStructure, TConditionalStmt { }
|
||||
class IfStmt extends ConditionalStmt, @stmt_if {
|
||||
override string getAPrimaryQlClass() { result = "IfStmt" }
|
||||
|
||||
/**
|
||||
* Gets the initialization statement of this 'if' statement.
|
||||
*
|
||||
* For example, for
|
||||
* ```
|
||||
* if (x = y; b) { f(); }
|
||||
* ```
|
||||
* the result is `x = y;`.
|
||||
*
|
||||
* Does not hold if the initialization statement is missing or an empty statement, as in
|
||||
* ```
|
||||
* if (b) { f(); }
|
||||
* ```
|
||||
* or
|
||||
* ```
|
||||
* if (; b) { f(); }
|
||||
* ```
|
||||
*/
|
||||
Stmt getInitialization() { if_initialization(underlyingElement(this), unresolveElement(result)) }
|
||||
|
||||
/**
|
||||
* Gets the condition expression of this 'if' statement.
|
||||
*
|
||||
@@ -222,7 +242,7 @@ class IfStmt extends ConditionalStmt, @stmt_if {
|
||||
* ```
|
||||
* the result is `b`.
|
||||
*/
|
||||
Expr getCondition() { result = this.getChild(0) }
|
||||
Expr getCondition() { result = this.getChild(1) }
|
||||
|
||||
override Expr getControllingExpr() { result = this.getCondition() }
|
||||
|
||||
@@ -299,6 +319,28 @@ class IfStmt extends ConditionalStmt, @stmt_if {
|
||||
class ConstexprIfStmt extends ConditionalStmt, @stmt_constexpr_if {
|
||||
override string getAPrimaryQlClass() { result = "ConstexprIfStmt" }
|
||||
|
||||
/**
|
||||
* Gets the initialization statement of this 'constexpr if' statement.
|
||||
*
|
||||
* For example, for
|
||||
* ```
|
||||
* if constexpr (x = y; b) { f(); }
|
||||
* ```
|
||||
* the result is `x = y;`.
|
||||
*
|
||||
* Does not hold if the initialization statement is missing or an empty statement, as in
|
||||
* ```
|
||||
* if constexpr (b) { f(); }
|
||||
* ```
|
||||
* or
|
||||
* ```
|
||||
* if constexpr (; b) { f(); }
|
||||
* ```
|
||||
*/
|
||||
Stmt getInitialization() {
|
||||
constexpr_if_initialization(underlyingElement(this), unresolveElement(result))
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the condition expression of this 'constexpr if' statement.
|
||||
*
|
||||
@@ -308,7 +350,7 @@ class ConstexprIfStmt extends ConditionalStmt, @stmt_constexpr_if {
|
||||
* ```
|
||||
* the result is `b`.
|
||||
*/
|
||||
Expr getCondition() { result = this.getChild(0) }
|
||||
Expr getCondition() { result = this.getChild(1) }
|
||||
|
||||
override Expr getControllingExpr() { result = this.getCondition() }
|
||||
|
||||
@@ -926,7 +968,7 @@ class ForStmt extends Loop, @stmt_for {
|
||||
*
|
||||
* Does not hold if the initialization statement is an empty statement, as in
|
||||
* ```
|
||||
* for (; i < 10; i++) { j++ }
|
||||
* for (; i < 10; i++) { j++; }
|
||||
* ```
|
||||
*/
|
||||
Stmt getInitialization() { for_initialization(underlyingElement(this), unresolveElement(result)) }
|
||||
|
||||
@@ -1863,6 +1863,11 @@ variable_vla(
|
||||
int decl: @stmt_vla_decl ref
|
||||
);
|
||||
|
||||
if_initialization(
|
||||
unique int if_stmt: @stmt_if ref,
|
||||
int init_id: @stmt ref
|
||||
);
|
||||
|
||||
if_then(
|
||||
unique int if_stmt: @stmt_if ref,
|
||||
int then_id: @stmt ref
|
||||
@@ -1873,6 +1878,11 @@ if_else(
|
||||
int else_id: @stmt ref
|
||||
);
|
||||
|
||||
constexpr_if_initialization(
|
||||
unique int constexpr_if_stmt: @stmt_constexpr_if ref,
|
||||
int init_id: @stmt ref
|
||||
);
|
||||
|
||||
constexpr_if_then(
|
||||
unique int constexpr_if_stmt: @stmt_constexpr_if ref,
|
||||
int then_id: @stmt ref
|
||||
|
||||
@@ -57,6 +57,5 @@ where
|
||||
not declarationHasSideEffects(v) and
|
||||
not exists(AsmStmt s | f = s.getEnclosingFunction()) and
|
||||
not v.getAnAttribute().getName() = "unused" and
|
||||
not any(ErrorExpr e).getEnclosingFunction() = f and // unextracted expr may use `v`
|
||||
not any(ConditionDeclExpr cde).getEnclosingFunction() = f // this case can be removed when the `if (a = b; a)` and `switch (a = b; a)` test cases don't depend on this exclusion
|
||||
not any(ErrorExpr e).getEnclosingFunction() = f // unextracted expr may use `v`
|
||||
select v, "Variable " + v.getName() + " is not used"
|
||||
|
||||
@@ -13559,6 +13559,223 @@ ir.cpp:
|
||||
# 1754| Type = [SpecifiedType] const CopyConstructorTestVirtualClass
|
||||
# 1754| ValueCategory = lvalue
|
||||
# 1755| getStmt(2): [ReturnStmt] return ...
|
||||
# 1757| [TopLevelFunction] void if_initialization(int)
|
||||
# 1757| <params>:
|
||||
# 1757| getParameter(0): [Parameter] x
|
||||
# 1757| Type = [IntType] int
|
||||
# 1757| getEntryPoint(): [BlockStmt] { ... }
|
||||
# 1758| getStmt(0): [IfStmt] if (...) ...
|
||||
# 1758| getInitialization(): [DeclStmt] declaration
|
||||
# 1758| getDeclarationEntry(0): [VariableDeclarationEntry] definition of y
|
||||
# 1758| Type = [IntType] int
|
||||
# 1758| getVariable().getInitializer(): [Initializer] initializer for y
|
||||
# 1758| getExpr(): [VariableAccess] x
|
||||
# 1758| Type = [IntType] int
|
||||
# 1758| ValueCategory = prvalue(load)
|
||||
# 1758| getCondition(): [AddExpr] ... + ...
|
||||
# 1758| Type = [IntType] int
|
||||
# 1758| ValueCategory = prvalue
|
||||
# 1758| getLeftOperand(): [VariableAccess] x
|
||||
# 1758| Type = [IntType] int
|
||||
# 1758| ValueCategory = prvalue(load)
|
||||
# 1758| getRightOperand(): [Literal] 1
|
||||
# 1758| Type = [IntType] int
|
||||
# 1758| Value = [Literal] 1
|
||||
# 1758| ValueCategory = prvalue
|
||||
# 1758| getThen(): [BlockStmt] { ... }
|
||||
# 1759| getStmt(0): [ExprStmt] ExprStmt
|
||||
# 1759| getExpr(): [AssignExpr] ... = ...
|
||||
# 1759| Type = [IntType] int
|
||||
# 1759| ValueCategory = lvalue
|
||||
# 1759| getLValue(): [VariableAccess] x
|
||||
# 1759| Type = [IntType] int
|
||||
# 1759| ValueCategory = lvalue
|
||||
# 1759| getRValue(): [AddExpr] ... + ...
|
||||
# 1759| Type = [IntType] int
|
||||
# 1759| ValueCategory = prvalue
|
||||
# 1759| getLeftOperand(): [VariableAccess] x
|
||||
# 1759| Type = [IntType] int
|
||||
# 1759| ValueCategory = prvalue(load)
|
||||
# 1759| getRightOperand(): [VariableAccess] y
|
||||
# 1759| Type = [IntType] int
|
||||
# 1759| ValueCategory = prvalue(load)
|
||||
# 1758| getCondition().getFullyConverted(): [CStyleCast] (bool)...
|
||||
# 1758| Conversion = [BoolConversion] conversion to bool
|
||||
# 1758| Type = [BoolType] bool
|
||||
# 1758| ValueCategory = prvalue
|
||||
# 1762| getStmt(1): [DeclStmt] declaration
|
||||
# 1762| getDeclarationEntry(0): [VariableDeclarationEntry] definition of w
|
||||
# 1762| Type = [IntType] int
|
||||
# 1763| getStmt(2): [IfStmt] if (...) ...
|
||||
# 1763| getInitialization(): [ExprStmt] ExprStmt
|
||||
# 1763| getExpr(): [AssignExpr] ... = ...
|
||||
# 1763| Type = [IntType] int
|
||||
# 1763| ValueCategory = lvalue
|
||||
# 1763| getLValue(): [VariableAccess] w
|
||||
# 1763| Type = [IntType] int
|
||||
# 1763| ValueCategory = lvalue
|
||||
# 1763| getRValue(): [VariableAccess] x
|
||||
# 1763| Type = [IntType] int
|
||||
# 1763| ValueCategory = prvalue(load)
|
||||
# 1763| getCondition(): [AddExpr] ... + ...
|
||||
# 1763| Type = [IntType] int
|
||||
# 1763| ValueCategory = prvalue
|
||||
# 1763| getLeftOperand(): [VariableAccess] x
|
||||
# 1763| Type = [IntType] int
|
||||
# 1763| ValueCategory = prvalue(load)
|
||||
# 1763| getRightOperand(): [Literal] 1
|
||||
# 1763| Type = [IntType] int
|
||||
# 1763| Value = [Literal] 1
|
||||
# 1763| ValueCategory = prvalue
|
||||
# 1763| getThen(): [BlockStmt] { ... }
|
||||
# 1764| getStmt(0): [ExprStmt] ExprStmt
|
||||
# 1764| getExpr(): [AssignExpr] ... = ...
|
||||
# 1764| Type = [IntType] int
|
||||
# 1764| ValueCategory = lvalue
|
||||
# 1764| getLValue(): [VariableAccess] x
|
||||
# 1764| Type = [IntType] int
|
||||
# 1764| ValueCategory = lvalue
|
||||
# 1764| getRValue(): [AddExpr] ... + ...
|
||||
# 1764| Type = [IntType] int
|
||||
# 1764| ValueCategory = prvalue
|
||||
# 1764| getLeftOperand(): [VariableAccess] x
|
||||
# 1764| Type = [IntType] int
|
||||
# 1764| ValueCategory = prvalue(load)
|
||||
# 1764| getRightOperand(): [VariableAccess] w
|
||||
# 1764| Type = [IntType] int
|
||||
# 1764| ValueCategory = prvalue(load)
|
||||
# 1763| getCondition().getFullyConverted(): [CStyleCast] (bool)...
|
||||
# 1763| Conversion = [BoolConversion] conversion to bool
|
||||
# 1763| Type = [BoolType] bool
|
||||
# 1763| ValueCategory = prvalue
|
||||
# 1767| getStmt(3): [IfStmt] if (...) ...
|
||||
# 1767| getInitialization(): [ExprStmt] ExprStmt
|
||||
# 1767| getExpr(): [AssignExpr] ... = ...
|
||||
# 1767| Type = [IntType] int
|
||||
# 1767| ValueCategory = lvalue
|
||||
# 1767| getLValue(): [VariableAccess] w
|
||||
# 1767| Type = [IntType] int
|
||||
# 1767| ValueCategory = lvalue
|
||||
# 1767| getRValue(): [VariableAccess] x
|
||||
# 1767| Type = [IntType] int
|
||||
# 1767| ValueCategory = prvalue(load)
|
||||
# 1767| getCondition(): [ConditionDeclExpr] (condition decl)
|
||||
# 1767| Type = [BoolType] bool
|
||||
# 1767| ValueCategory = prvalue
|
||||
# 1767| getVariableAccess(): [VariableAccess] w2
|
||||
# 1767| Type = [IntType] int
|
||||
# 1767| ValueCategory = prvalue(load)
|
||||
# 1767| getVariableAccess().getFullyConverted(): [CStyleCast] (bool)...
|
||||
# 1767| Conversion = [BoolConversion] conversion to bool
|
||||
# 1767| Type = [BoolType] bool
|
||||
# 1767| ValueCategory = prvalue
|
||||
# 1767| getThen(): [BlockStmt] { ... }
|
||||
# 1768| getStmt(0): [ExprStmt] ExprStmt
|
||||
# 1768| getExpr(): [AssignExpr] ... = ...
|
||||
# 1768| Type = [IntType] int
|
||||
# 1768| ValueCategory = lvalue
|
||||
# 1768| getLValue(): [VariableAccess] x
|
||||
# 1768| Type = [IntType] int
|
||||
# 1768| ValueCategory = lvalue
|
||||
# 1768| getRValue(): [AddExpr] ... + ...
|
||||
# 1768| Type = [IntType] int
|
||||
# 1768| ValueCategory = prvalue
|
||||
# 1768| getLeftOperand(): [VariableAccess] x
|
||||
# 1768| Type = [IntType] int
|
||||
# 1768| ValueCategory = prvalue(load)
|
||||
# 1768| getRightOperand(): [VariableAccess] w
|
||||
# 1768| Type = [IntType] int
|
||||
# 1768| ValueCategory = prvalue(load)
|
||||
# 1771| getStmt(4): [IfStmt] if (...) ...
|
||||
# 1771| getInitialization(): [DeclStmt] declaration
|
||||
# 1771| getDeclarationEntry(0): [VariableDeclarationEntry] definition of v
|
||||
# 1771| Type = [IntType] int
|
||||
# 1771| getVariable().getInitializer(): [Initializer] initializer for v
|
||||
# 1771| getExpr(): [VariableAccess] x
|
||||
# 1771| Type = [IntType] int
|
||||
# 1771| ValueCategory = prvalue(load)
|
||||
# 1771| getCondition(): [ConditionDeclExpr] (condition decl)
|
||||
# 1771| Type = [BoolType] bool
|
||||
# 1771| ValueCategory = prvalue
|
||||
# 1771| getVariableAccess(): [VariableAccess] v2
|
||||
# 1771| Type = [IntType] int
|
||||
# 1771| ValueCategory = prvalue(load)
|
||||
# 1771| getVariableAccess().getFullyConverted(): [CStyleCast] (bool)...
|
||||
# 1771| Conversion = [BoolConversion] conversion to bool
|
||||
# 1771| Type = [BoolType] bool
|
||||
# 1771| ValueCategory = prvalue
|
||||
# 1771| getThen(): [BlockStmt] { ... }
|
||||
# 1772| getStmt(0): [ExprStmt] ExprStmt
|
||||
# 1772| getExpr(): [AssignExpr] ... = ...
|
||||
# 1772| Type = [IntType] int
|
||||
# 1772| ValueCategory = lvalue
|
||||
# 1772| getLValue(): [VariableAccess] x
|
||||
# 1772| Type = [IntType] int
|
||||
# 1772| ValueCategory = lvalue
|
||||
# 1772| getRValue(): [AddExpr] ... + ...
|
||||
# 1772| Type = [IntType] int
|
||||
# 1772| ValueCategory = prvalue
|
||||
# 1772| getLeftOperand(): [VariableAccess] x
|
||||
# 1772| Type = [IntType] int
|
||||
# 1772| ValueCategory = prvalue(load)
|
||||
# 1772| getRightOperand(): [VariableAccess] v
|
||||
# 1772| Type = [IntType] int
|
||||
# 1772| ValueCategory = prvalue(load)
|
||||
# 1775| getStmt(5): [DeclStmt] declaration
|
||||
# 1775| getDeclarationEntry(0): [VariableDeclarationEntry] definition of z
|
||||
# 1775| Type = [IntType] int
|
||||
# 1775| getVariable().getInitializer(): [Initializer] initializer for z
|
||||
# 1775| getExpr(): [VariableAccess] x
|
||||
# 1775| Type = [IntType] int
|
||||
# 1775| ValueCategory = prvalue(load)
|
||||
# 1776| getStmt(6): [IfStmt] if (...) ...
|
||||
# 1776| getCondition(): [VariableAccess] z
|
||||
# 1776| Type = [IntType] int
|
||||
# 1776| ValueCategory = prvalue(load)
|
||||
# 1776| getThen(): [BlockStmt] { ... }
|
||||
# 1777| getStmt(0): [ExprStmt] ExprStmt
|
||||
# 1777| getExpr(): [AssignExpr] ... = ...
|
||||
# 1777| Type = [IntType] int
|
||||
# 1777| ValueCategory = lvalue
|
||||
# 1777| getLValue(): [VariableAccess] x
|
||||
# 1777| Type = [IntType] int
|
||||
# 1777| ValueCategory = lvalue
|
||||
# 1777| getRValue(): [AddExpr] ... + ...
|
||||
# 1777| Type = [IntType] int
|
||||
# 1777| ValueCategory = prvalue
|
||||
# 1777| getLeftOperand(): [VariableAccess] x
|
||||
# 1777| Type = [IntType] int
|
||||
# 1777| ValueCategory = prvalue(load)
|
||||
# 1777| getRightOperand(): [VariableAccess] z
|
||||
# 1777| Type = [IntType] int
|
||||
# 1777| ValueCategory = prvalue(load)
|
||||
# 1776| getCondition().getFullyConverted(): [CStyleCast] (bool)...
|
||||
# 1776| Conversion = [BoolConversion] conversion to bool
|
||||
# 1776| Type = [BoolType] bool
|
||||
# 1776| ValueCategory = prvalue
|
||||
# 1780| getStmt(7): [IfStmt] if (...) ...
|
||||
# 1780| getCondition(): [ConditionDeclExpr] (condition decl)
|
||||
# 1780| Type = [BoolType] bool
|
||||
# 1780| ValueCategory = prvalue
|
||||
# 1780| getVariableAccess(): [VariableAccess] z2
|
||||
# 1780| Type = [IntType] int
|
||||
# 1780| ValueCategory = prvalue(load)
|
||||
# 1780| getVariableAccess().getFullyConverted(): [CStyleCast] (bool)...
|
||||
# 1780| Conversion = [BoolConversion] conversion to bool
|
||||
# 1780| Type = [BoolType] bool
|
||||
# 1780| ValueCategory = prvalue
|
||||
# 1780| getThen(): [BlockStmt] { ... }
|
||||
# 1781| getStmt(0): [ExprStmt] ExprStmt
|
||||
# 1781| getExpr(): [AssignAddExpr] ... += ...
|
||||
# 1781| Type = [IntType] int
|
||||
# 1781| ValueCategory = lvalue
|
||||
# 1781| getLValue(): [VariableAccess] x
|
||||
# 1781| Type = [IntType] int
|
||||
# 1781| ValueCategory = lvalue
|
||||
# 1781| getRValue(): [VariableAccess] z2
|
||||
# 1781| Type = [IntType] int
|
||||
# 1781| ValueCategory = prvalue(load)
|
||||
# 1783| getStmt(8): [ReturnStmt] return ...
|
||||
perf-regression.cpp:
|
||||
# 4| [CopyAssignmentOperator] Big& Big::operator=(Big const&)
|
||||
# 4| <params>:
|
||||
|
||||
@@ -1754,4 +1754,32 @@ int implicit_copy_constructor_test(
|
||||
CopyConstructorTestVirtualClass cy = y;
|
||||
}
|
||||
|
||||
void if_initialization(int x) {
|
||||
if (int y = x; x + 1) {
|
||||
x = x + y;
|
||||
}
|
||||
|
||||
int w;
|
||||
if (w = x; x + 1) {
|
||||
x = x + w;
|
||||
}
|
||||
|
||||
if (w = x; int w2 = w) {
|
||||
x = x + w;
|
||||
}
|
||||
|
||||
if (int v = x; int v2 = v) {
|
||||
x = x + v;
|
||||
}
|
||||
|
||||
int z = x;
|
||||
if (z) {
|
||||
x = x + z;
|
||||
}
|
||||
|
||||
if (int z2 = z) {
|
||||
x += z2;
|
||||
}
|
||||
}
|
||||
|
||||
// semmle-extractor-options: -std=c++17 --clang
|
||||
|
||||
@@ -8215,6 +8215,138 @@
|
||||
| ir.cpp:1754:42:1754:42 | SideEffect | ~m1752_4 |
|
||||
| ir.cpp:1754:42:1754:42 | Unary | r1754_5 |
|
||||
| ir.cpp:1754:42:1754:42 | Unary | r1754_6 |
|
||||
| ir.cpp:1757:6:1757:22 | ChiPartial | partial:m1757_3 |
|
||||
| ir.cpp:1757:6:1757:22 | ChiTotal | total:m1757_2 |
|
||||
| ir.cpp:1757:6:1757:22 | SideEffect | m1757_3 |
|
||||
| ir.cpp:1757:28:1757:28 | Address | &:r1757_5 |
|
||||
| ir.cpp:1758:13:1758:13 | Address | &:r1758_1 |
|
||||
| ir.cpp:1758:17:1758:17 | Address | &:r1758_2 |
|
||||
| ir.cpp:1758:17:1758:17 | Load | m1757_6 |
|
||||
| ir.cpp:1758:17:1758:17 | StoreValue | r1758_3 |
|
||||
| ir.cpp:1758:20:1758:20 | Address | &:r1758_5 |
|
||||
| ir.cpp:1758:20:1758:20 | Left | r1758_6 |
|
||||
| ir.cpp:1758:20:1758:20 | Load | m1757_6 |
|
||||
| ir.cpp:1758:20:1758:24 | Condition | r1758_10 |
|
||||
| ir.cpp:1758:20:1758:24 | Left | r1758_8 |
|
||||
| ir.cpp:1758:20:1758:24 | Right | r1758_9 |
|
||||
| ir.cpp:1758:24:1758:24 | Right | r1758_7 |
|
||||
| ir.cpp:1759:9:1759:9 | Address | &:r1759_6 |
|
||||
| ir.cpp:1759:13:1759:13 | Address | &:r1759_1 |
|
||||
| ir.cpp:1759:13:1759:13 | Left | r1759_2 |
|
||||
| ir.cpp:1759:13:1759:13 | Load | m1757_6 |
|
||||
| ir.cpp:1759:13:1759:17 | StoreValue | r1759_5 |
|
||||
| ir.cpp:1759:17:1759:17 | Address | &:r1759_3 |
|
||||
| ir.cpp:1759:17:1759:17 | Load | m1758_4 |
|
||||
| ir.cpp:1759:17:1759:17 | Right | r1759_4 |
|
||||
| ir.cpp:1762:9:1762:9 | Address | &:r1762_2 |
|
||||
| ir.cpp:1762:9:1762:9 | Phi | from 0:m1757_6 |
|
||||
| ir.cpp:1762:9:1762:9 | Phi | from 1:m1759_7 |
|
||||
| ir.cpp:1763:9:1763:9 | Address | &:r1763_3 |
|
||||
| ir.cpp:1763:13:1763:13 | Address | &:r1763_1 |
|
||||
| ir.cpp:1763:13:1763:13 | Load | m1762_1 |
|
||||
| ir.cpp:1763:13:1763:13 | StoreValue | r1763_2 |
|
||||
| ir.cpp:1763:16:1763:16 | Address | &:r1763_5 |
|
||||
| ir.cpp:1763:16:1763:16 | Left | r1763_6 |
|
||||
| ir.cpp:1763:16:1763:16 | Load | m1762_1 |
|
||||
| ir.cpp:1763:16:1763:20 | Condition | r1763_10 |
|
||||
| ir.cpp:1763:16:1763:20 | Left | r1763_8 |
|
||||
| ir.cpp:1763:16:1763:20 | Right | r1763_9 |
|
||||
| ir.cpp:1763:20:1763:20 | Right | r1763_7 |
|
||||
| ir.cpp:1764:9:1764:9 | Address | &:r1764_6 |
|
||||
| ir.cpp:1764:13:1764:13 | Address | &:r1764_1 |
|
||||
| ir.cpp:1764:13:1764:13 | Left | r1764_2 |
|
||||
| ir.cpp:1764:13:1764:13 | Load | m1762_1 |
|
||||
| ir.cpp:1764:13:1764:17 | StoreValue | r1764_5 |
|
||||
| ir.cpp:1764:17:1764:17 | Address | &:r1764_3 |
|
||||
| ir.cpp:1764:17:1764:17 | Load | m1763_4 |
|
||||
| ir.cpp:1764:17:1764:17 | Right | r1764_4 |
|
||||
| ir.cpp:1767:9:1767:9 | Address | &:r1767_4 |
|
||||
| ir.cpp:1767:13:1767:13 | Address | &:r1767_2 |
|
||||
| ir.cpp:1767:13:1767:13 | Load | m1767_1 |
|
||||
| ir.cpp:1767:13:1767:13 | Phi | from 2:m1762_1 |
|
||||
| ir.cpp:1767:13:1767:13 | Phi | from 3:m1764_7 |
|
||||
| ir.cpp:1767:13:1767:13 | StoreValue | r1767_3 |
|
||||
| ir.cpp:1767:14:1767:25 | Address | &:r1767_6 |
|
||||
| ir.cpp:1767:14:1767:25 | Condition | r1767_14 |
|
||||
| ir.cpp:1767:20:1767:21 | Address | &:r1767_10 |
|
||||
| ir.cpp:1767:20:1767:21 | Left | r1767_11 |
|
||||
| ir.cpp:1767:20:1767:21 | Load | m1767_9 |
|
||||
| ir.cpp:1767:20:1767:21 | Right | r1767_12 |
|
||||
| ir.cpp:1767:20:1767:21 | Unary | r1767_13 |
|
||||
| ir.cpp:1767:25:1767:25 | Address | &:r1767_7 |
|
||||
| ir.cpp:1767:25:1767:25 | Load | m1767_5 |
|
||||
| ir.cpp:1767:25:1767:25 | StoreValue | r1767_8 |
|
||||
| ir.cpp:1768:9:1768:9 | Address | &:r1768_6 |
|
||||
| ir.cpp:1768:13:1768:13 | Address | &:r1768_1 |
|
||||
| ir.cpp:1768:13:1768:13 | Left | r1768_2 |
|
||||
| ir.cpp:1768:13:1768:13 | Load | m1767_1 |
|
||||
| ir.cpp:1768:13:1768:17 | StoreValue | r1768_5 |
|
||||
| ir.cpp:1768:17:1768:17 | Address | &:r1768_3 |
|
||||
| ir.cpp:1768:17:1768:17 | Load | m1767_5 |
|
||||
| ir.cpp:1768:17:1768:17 | Right | r1768_4 |
|
||||
| ir.cpp:1771:9:1771:29 | Address | &:r1771_6 |
|
||||
| ir.cpp:1771:9:1771:29 | Condition | r1771_14 |
|
||||
| ir.cpp:1771:13:1771:13 | Address | &:r1771_2 |
|
||||
| ir.cpp:1771:13:1771:13 | Phi | from 4:m1767_1 |
|
||||
| ir.cpp:1771:13:1771:13 | Phi | from 5:m1768_7 |
|
||||
| ir.cpp:1771:17:1771:17 | Address | &:r1771_3 |
|
||||
| ir.cpp:1771:17:1771:17 | Load | m1771_1 |
|
||||
| ir.cpp:1771:17:1771:17 | StoreValue | r1771_4 |
|
||||
| ir.cpp:1771:24:1771:25 | Address | &:r1771_10 |
|
||||
| ir.cpp:1771:24:1771:25 | Left | r1771_11 |
|
||||
| ir.cpp:1771:24:1771:25 | Load | m1771_9 |
|
||||
| ir.cpp:1771:24:1771:25 | Right | r1771_12 |
|
||||
| ir.cpp:1771:24:1771:25 | Unary | r1771_13 |
|
||||
| ir.cpp:1771:29:1771:29 | Address | &:r1771_7 |
|
||||
| ir.cpp:1771:29:1771:29 | Load | m1771_5 |
|
||||
| ir.cpp:1771:29:1771:29 | StoreValue | r1771_8 |
|
||||
| ir.cpp:1772:9:1772:9 | Address | &:r1772_6 |
|
||||
| ir.cpp:1772:13:1772:13 | Address | &:r1772_1 |
|
||||
| ir.cpp:1772:13:1772:13 | Left | r1772_2 |
|
||||
| ir.cpp:1772:13:1772:13 | Load | m1771_1 |
|
||||
| ir.cpp:1772:13:1772:17 | StoreValue | r1772_5 |
|
||||
| ir.cpp:1772:17:1772:17 | Address | &:r1772_3 |
|
||||
| ir.cpp:1772:17:1772:17 | Load | m1771_5 |
|
||||
| ir.cpp:1772:17:1772:17 | Right | r1772_4 |
|
||||
| ir.cpp:1775:9:1775:9 | Address | &:r1775_2 |
|
||||
| ir.cpp:1775:9:1775:9 | Phi | from 6:m1771_1 |
|
||||
| ir.cpp:1775:9:1775:9 | Phi | from 7:m1772_7 |
|
||||
| ir.cpp:1775:13:1775:13 | Address | &:r1775_3 |
|
||||
| ir.cpp:1775:13:1775:13 | Load | m1775_1 |
|
||||
| ir.cpp:1775:13:1775:13 | StoreValue | r1775_4 |
|
||||
| ir.cpp:1776:9:1776:9 | Address | &:r1776_1 |
|
||||
| ir.cpp:1776:9:1776:9 | Condition | r1776_4 |
|
||||
| ir.cpp:1776:9:1776:9 | Left | r1776_2 |
|
||||
| ir.cpp:1776:9:1776:9 | Load | m1775_5 |
|
||||
| ir.cpp:1776:9:1776:9 | Right | r1776_3 |
|
||||
| ir.cpp:1777:9:1777:9 | Address | &:r1777_6 |
|
||||
| ir.cpp:1777:13:1777:13 | Address | &:r1777_1 |
|
||||
| ir.cpp:1777:13:1777:13 | Left | r1777_2 |
|
||||
| ir.cpp:1777:13:1777:13 | Load | m1775_1 |
|
||||
| ir.cpp:1777:13:1777:17 | StoreValue | r1777_5 |
|
||||
| ir.cpp:1777:17:1777:17 | Address | &:r1777_3 |
|
||||
| ir.cpp:1777:17:1777:17 | Load | m1775_5 |
|
||||
| ir.cpp:1777:17:1777:17 | Right | r1777_4 |
|
||||
| ir.cpp:1780:9:1780:18 | Address | &:r1780_2 |
|
||||
| ir.cpp:1780:9:1780:18 | Condition | r1780_10 |
|
||||
| ir.cpp:1780:9:1780:18 | Phi | from 8:m1775_1 |
|
||||
| ir.cpp:1780:9:1780:18 | Phi | from 9:m1777_7 |
|
||||
| ir.cpp:1780:13:1780:14 | Address | &:r1780_6 |
|
||||
| ir.cpp:1780:13:1780:14 | Left | r1780_7 |
|
||||
| ir.cpp:1780:13:1780:14 | Load | m1780_5 |
|
||||
| ir.cpp:1780:13:1780:14 | Right | r1780_8 |
|
||||
| ir.cpp:1780:13:1780:14 | Unary | r1780_9 |
|
||||
| ir.cpp:1780:18:1780:18 | Address | &:r1780_3 |
|
||||
| ir.cpp:1780:18:1780:18 | Load | m1775_5 |
|
||||
| ir.cpp:1780:18:1780:18 | StoreValue | r1780_4 |
|
||||
| ir.cpp:1781:9:1781:9 | Address | &:r1781_3 |
|
||||
| ir.cpp:1781:9:1781:9 | Address | &:r1781_3 |
|
||||
| ir.cpp:1781:9:1781:9 | Left | r1781_4 |
|
||||
| ir.cpp:1781:9:1781:9 | Load | m1780_1 |
|
||||
| ir.cpp:1781:9:1781:15 | StoreValue | r1781_5 |
|
||||
| ir.cpp:1781:14:1781:15 | Address | &:r1781_1 |
|
||||
| ir.cpp:1781:14:1781:15 | Load | m1780_5 |
|
||||
| ir.cpp:1781:14:1781:15 | Right | r1781_2 |
|
||||
| perf-regression.cpp:6:3:6:5 | Address | &:r6_5 |
|
||||
| perf-regression.cpp:6:3:6:5 | Address | &:r6_5 |
|
||||
| perf-regression.cpp:6:3:6:5 | Address | &:r6_7 |
|
||||
|
||||
@@ -9418,6 +9418,172 @@ ir.cpp:
|
||||
# 1750| v1750_6(void) = AliasedUse : ~m?
|
||||
# 1750| v1750_7(void) = ExitFunction :
|
||||
|
||||
# 1757| void if_initialization(int)
|
||||
# 1757| Block 0
|
||||
# 1757| v1757_1(void) = EnterFunction :
|
||||
# 1757| mu1757_2(unknown) = AliasedDefinition :
|
||||
# 1757| mu1757_3(unknown) = InitializeNonLocal :
|
||||
# 1757| r1757_4(glval<int>) = VariableAddress[x] :
|
||||
# 1757| mu1757_5(int) = InitializeParameter[x] : &:r1757_4
|
||||
# 1758| r1758_1(glval<int>) = VariableAddress[y] :
|
||||
# 1758| r1758_2(glval<int>) = VariableAddress[x] :
|
||||
# 1758| r1758_3(int) = Load[x] : &:r1758_2, ~m?
|
||||
# 1758| mu1758_4(int) = Store[y] : &:r1758_1, r1758_3
|
||||
# 1758| r1758_5(glval<int>) = VariableAddress[x] :
|
||||
# 1758| r1758_6(int) = Load[x] : &:r1758_5, ~m?
|
||||
# 1758| r1758_7(int) = Constant[1] :
|
||||
# 1758| r1758_8(int) = Add : r1758_6, r1758_7
|
||||
# 1758| r1758_9(int) = Constant[0] :
|
||||
# 1758| r1758_10(bool) = CompareNE : r1758_8, r1758_9
|
||||
# 1758| v1758_11(void) = ConditionalBranch : r1758_10
|
||||
#-----| False -> Block 2
|
||||
#-----| True -> Block 1
|
||||
|
||||
# 1759| Block 1
|
||||
# 1759| r1759_1(glval<int>) = VariableAddress[x] :
|
||||
# 1759| r1759_2(int) = Load[x] : &:r1759_1, ~m?
|
||||
# 1759| r1759_3(glval<int>) = VariableAddress[y] :
|
||||
# 1759| r1759_4(int) = Load[y] : &:r1759_3, ~m?
|
||||
# 1759| r1759_5(int) = Add : r1759_2, r1759_4
|
||||
# 1759| r1759_6(glval<int>) = VariableAddress[x] :
|
||||
# 1759| mu1759_7(int) = Store[x] : &:r1759_6, r1759_5
|
||||
#-----| Goto -> Block 2
|
||||
|
||||
# 1762| Block 2
|
||||
# 1762| r1762_1(glval<int>) = VariableAddress[w] :
|
||||
# 1762| mu1762_2(int) = Uninitialized[w] : &:r1762_1
|
||||
# 1763| r1763_1(glval<int>) = VariableAddress[x] :
|
||||
# 1763| r1763_2(int) = Load[x] : &:r1763_1, ~m?
|
||||
# 1763| r1763_3(glval<int>) = VariableAddress[w] :
|
||||
# 1763| mu1763_4(int) = Store[w] : &:r1763_3, r1763_2
|
||||
# 1763| r1763_5(glval<int>) = VariableAddress[x] :
|
||||
# 1763| r1763_6(int) = Load[x] : &:r1763_5, ~m?
|
||||
# 1763| r1763_7(int) = Constant[1] :
|
||||
# 1763| r1763_8(int) = Add : r1763_6, r1763_7
|
||||
# 1763| r1763_9(int) = Constant[0] :
|
||||
# 1763| r1763_10(bool) = CompareNE : r1763_8, r1763_9
|
||||
# 1763| v1763_11(void) = ConditionalBranch : r1763_10
|
||||
#-----| False -> Block 4
|
||||
#-----| True -> Block 3
|
||||
|
||||
# 1764| Block 3
|
||||
# 1764| r1764_1(glval<int>) = VariableAddress[x] :
|
||||
# 1764| r1764_2(int) = Load[x] : &:r1764_1, ~m?
|
||||
# 1764| r1764_3(glval<int>) = VariableAddress[w] :
|
||||
# 1764| r1764_4(int) = Load[w] : &:r1764_3, ~m?
|
||||
# 1764| r1764_5(int) = Add : r1764_2, r1764_4
|
||||
# 1764| r1764_6(glval<int>) = VariableAddress[x] :
|
||||
# 1764| mu1764_7(int) = Store[x] : &:r1764_6, r1764_5
|
||||
#-----| Goto -> Block 4
|
||||
|
||||
# 1767| Block 4
|
||||
# 1767| r1767_1(glval<int>) = VariableAddress[x] :
|
||||
# 1767| r1767_2(int) = Load[x] : &:r1767_1, ~m?
|
||||
# 1767| r1767_3(glval<int>) = VariableAddress[w] :
|
||||
# 1767| mu1767_4(int) = Store[w] : &:r1767_3, r1767_2
|
||||
# 1767| r1767_5(glval<int>) = VariableAddress[w2] :
|
||||
# 1767| r1767_6(glval<int>) = VariableAddress[w] :
|
||||
# 1767| r1767_7(int) = Load[w] : &:r1767_6, ~m?
|
||||
# 1767| mu1767_8(int) = Store[w2] : &:r1767_5, r1767_7
|
||||
# 1767| r1767_9(glval<int>) = VariableAddress[w2] :
|
||||
# 1767| r1767_10(int) = Load[w2] : &:r1767_9, ~m?
|
||||
# 1767| r1767_11(int) = Constant[0] :
|
||||
# 1767| r1767_12(bool) = CompareNE : r1767_10, r1767_11
|
||||
# 1767| r1767_13(bool) = CopyValue : r1767_12
|
||||
# 1767| v1767_14(void) = ConditionalBranch : r1767_13
|
||||
#-----| False -> Block 6
|
||||
#-----| True -> Block 5
|
||||
|
||||
# 1768| Block 5
|
||||
# 1768| r1768_1(glval<int>) = VariableAddress[x] :
|
||||
# 1768| r1768_2(int) = Load[x] : &:r1768_1, ~m?
|
||||
# 1768| r1768_3(glval<int>) = VariableAddress[w] :
|
||||
# 1768| r1768_4(int) = Load[w] : &:r1768_3, ~m?
|
||||
# 1768| r1768_5(int) = Add : r1768_2, r1768_4
|
||||
# 1768| r1768_6(glval<int>) = VariableAddress[x] :
|
||||
# 1768| mu1768_7(int) = Store[x] : &:r1768_6, r1768_5
|
||||
#-----| Goto -> Block 6
|
||||
|
||||
# 1771| Block 6
|
||||
# 1771| r1771_1(glval<int>) = VariableAddress[v] :
|
||||
# 1771| r1771_2(glval<int>) = VariableAddress[x] :
|
||||
# 1771| r1771_3(int) = Load[x] : &:r1771_2, ~m?
|
||||
# 1771| mu1771_4(int) = Store[v] : &:r1771_1, r1771_3
|
||||
# 1771| r1771_5(glval<int>) = VariableAddress[v2] :
|
||||
# 1771| r1771_6(glval<int>) = VariableAddress[v] :
|
||||
# 1771| r1771_7(int) = Load[v] : &:r1771_6, ~m?
|
||||
# 1771| mu1771_8(int) = Store[v2] : &:r1771_5, r1771_7
|
||||
# 1771| r1771_9(glval<int>) = VariableAddress[v2] :
|
||||
# 1771| r1771_10(int) = Load[v2] : &:r1771_9, ~m?
|
||||
# 1771| r1771_11(int) = Constant[0] :
|
||||
# 1771| r1771_12(bool) = CompareNE : r1771_10, r1771_11
|
||||
# 1771| r1771_13(bool) = CopyValue : r1771_12
|
||||
# 1771| v1771_14(void) = ConditionalBranch : r1771_13
|
||||
#-----| False -> Block 8
|
||||
#-----| True -> Block 7
|
||||
|
||||
# 1772| Block 7
|
||||
# 1772| r1772_1(glval<int>) = VariableAddress[x] :
|
||||
# 1772| r1772_2(int) = Load[x] : &:r1772_1, ~m?
|
||||
# 1772| r1772_3(glval<int>) = VariableAddress[v] :
|
||||
# 1772| r1772_4(int) = Load[v] : &:r1772_3, ~m?
|
||||
# 1772| r1772_5(int) = Add : r1772_2, r1772_4
|
||||
# 1772| r1772_6(glval<int>) = VariableAddress[x] :
|
||||
# 1772| mu1772_7(int) = Store[x] : &:r1772_6, r1772_5
|
||||
#-----| Goto -> Block 8
|
||||
|
||||
# 1775| Block 8
|
||||
# 1775| r1775_1(glval<int>) = VariableAddress[z] :
|
||||
# 1775| r1775_2(glval<int>) = VariableAddress[x] :
|
||||
# 1775| r1775_3(int) = Load[x] : &:r1775_2, ~m?
|
||||
# 1775| mu1775_4(int) = Store[z] : &:r1775_1, r1775_3
|
||||
# 1776| r1776_1(glval<int>) = VariableAddress[z] :
|
||||
# 1776| r1776_2(int) = Load[z] : &:r1776_1, ~m?
|
||||
# 1776| r1776_3(int) = Constant[0] :
|
||||
# 1776| r1776_4(bool) = CompareNE : r1776_2, r1776_3
|
||||
# 1776| v1776_5(void) = ConditionalBranch : r1776_4
|
||||
#-----| False -> Block 10
|
||||
#-----| True -> Block 9
|
||||
|
||||
# 1777| Block 9
|
||||
# 1777| r1777_1(glval<int>) = VariableAddress[x] :
|
||||
# 1777| r1777_2(int) = Load[x] : &:r1777_1, ~m?
|
||||
# 1777| r1777_3(glval<int>) = VariableAddress[z] :
|
||||
# 1777| r1777_4(int) = Load[z] : &:r1777_3, ~m?
|
||||
# 1777| r1777_5(int) = Add : r1777_2, r1777_4
|
||||
# 1777| r1777_6(glval<int>) = VariableAddress[x] :
|
||||
# 1777| mu1777_7(int) = Store[x] : &:r1777_6, r1777_5
|
||||
#-----| Goto -> Block 10
|
||||
|
||||
# 1780| Block 10
|
||||
# 1780| r1780_1(glval<int>) = VariableAddress[z2] :
|
||||
# 1780| r1780_2(glval<int>) = VariableAddress[z] :
|
||||
# 1780| r1780_3(int) = Load[z] : &:r1780_2, ~m?
|
||||
# 1780| mu1780_4(int) = Store[z2] : &:r1780_1, r1780_3
|
||||
# 1780| r1780_5(glval<int>) = VariableAddress[z2] :
|
||||
# 1780| r1780_6(int) = Load[z2] : &:r1780_5, ~m?
|
||||
# 1780| r1780_7(int) = Constant[0] :
|
||||
# 1780| r1780_8(bool) = CompareNE : r1780_6, r1780_7
|
||||
# 1780| r1780_9(bool) = CopyValue : r1780_8
|
||||
# 1780| v1780_10(void) = ConditionalBranch : r1780_9
|
||||
#-----| False -> Block 12
|
||||
#-----| True -> Block 11
|
||||
|
||||
# 1781| Block 11
|
||||
# 1781| r1781_1(glval<int>) = VariableAddress[z2] :
|
||||
# 1781| r1781_2(int) = Load[z2] : &:r1781_1, ~m?
|
||||
# 1781| r1781_3(glval<int>) = VariableAddress[x] :
|
||||
# 1781| r1781_4(int) = Load[x] : &:r1781_3, ~m?
|
||||
# 1781| r1781_5(int) = Add : r1781_4, r1781_2
|
||||
# 1781| mu1781_6(int) = Store[x] : &:r1781_3, r1781_5
|
||||
#-----| Goto -> Block 12
|
||||
|
||||
# 1783| Block 12
|
||||
# 1783| v1783_1(void) = NoOp :
|
||||
# 1757| v1757_6(void) = ReturnVoid :
|
||||
# 1757| v1757_7(void) = AliasedUse : ~m?
|
||||
# 1757| v1757_8(void) = ExitFunction :
|
||||
|
||||
perf-regression.cpp:
|
||||
# 6| void Big::Big()
|
||||
# 6| Block 0
|
||||
|
||||
8
cpp/ql/test/successor-tests/ifstmt/ifstmt/ifstmt.cpp
Normal file
8
cpp/ql/test/successor-tests/ifstmt/ifstmt/ifstmt.cpp
Normal file
@@ -0,0 +1,8 @@
|
||||
void normal(int x, int y) {
|
||||
if(int z = y; x == z) {
|
||||
l1:;
|
||||
}
|
||||
l2:;
|
||||
}
|
||||
|
||||
// semmle-extractor-options: -std=c++17
|
||||
@@ -1 +1,2 @@
|
||||
| ifstmt.c:28:6:28:11 | ... == ... | l2 |
|
||||
| ifstmt.cpp:2:17:2:22 | ... == ... | l2 |
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
| ifstmt.c:28:6:28:11 | ... == ... | l1 |
|
||||
| ifstmt.cpp:2:17:2:22 | ... == ... | l1 |
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
| ifstmt.c:29:8:29:8 | ; | l2 |
|
||||
| ifstmt.cpp:3:8:3:8 | ; | l2 |
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
/**
|
||||
* @name ifstmt05
|
||||
* @description Every if statement has its condition or one of the condition's descendants as its unique successor.
|
||||
* @description Every if statement with an initialization has the initialization or one of the
|
||||
* initialization's descendants as its unique successor. Every if statement without
|
||||
* and initialization has its condition or one of the condition's descendants as
|
||||
* its unique successor.
|
||||
*/
|
||||
|
||||
import cpp
|
||||
@@ -8,7 +11,11 @@ import cpp
|
||||
from IfStmt is
|
||||
where
|
||||
not (
|
||||
is.getASuccessor() = is.getCondition().getAChild*() and
|
||||
(
|
||||
if exists(is.getInitialization())
|
||||
then is.getASuccessor() = is.getInitialization().getAChild*()
|
||||
else is.getASuccessor() = is.getCondition().getAChild*()
|
||||
) and
|
||||
count(is.getASuccessor()) = 1
|
||||
)
|
||||
select is
|
||||
|
||||
@@ -1,12 +1,27 @@
|
||||
| 0 | ifstmt.c:27:27:32:1 | { ... } | 1 | ifstmt.c:28:3:30:3 | if (...) ... |
|
||||
| 0 | ifstmt.cpp:1:27:6:1 | { ... } | 1 | ifstmt.cpp:2:3:4:3 | if (...) ... |
|
||||
| 1 | ifstmt.c:28:3:30:3 | if (...) ... | 1 | ifstmt.c:28:6:28:6 | x |
|
||||
| 1 | ifstmt.c:28:6:28:6 | x | 1 | ifstmt.c:28:11:28:11 | y |
|
||||
| 1 | ifstmt.c:28:6:28:11 | ... == ... | 1 | ifstmt.c:28:14:30:3 | { ... } |
|
||||
| 1 | ifstmt.c:28:6:28:11 | ... == ... | 4 | ifstmt.c:31:3:31:5 | label ...: |
|
||||
| 1 | ifstmt.c:28:11:28:11 | y | 1 | ifstmt.c:28:6:28:11 | ... == ... |
|
||||
| 1 | ifstmt.c:28:14:30:3 | { ... } | 2 | ifstmt.c:29:5:29:7 | label ...: |
|
||||
| 1 | ifstmt.cpp:2:3:4:3 | if (...) ... | 1 | ifstmt.cpp:2:6:2:6 | declaration |
|
||||
| 1 | ifstmt.cpp:2:6:2:6 | declaration | 1 | ifstmt.cpp:2:13:2:14 | initializer for z |
|
||||
| 1 | ifstmt.cpp:2:13:2:14 | initializer for z | 1 | ifstmt.cpp:2:14:2:14 | y |
|
||||
| 1 | ifstmt.cpp:2:14:2:14 | y | 1 | ifstmt.cpp:2:17:2:17 | x |
|
||||
| 1 | ifstmt.cpp:2:17:2:17 | x | 1 | ifstmt.cpp:2:22:2:22 | z |
|
||||
| 1 | ifstmt.cpp:2:17:2:22 | ... == ... | 1 | ifstmt.cpp:2:25:4:3 | { ... } |
|
||||
| 1 | ifstmt.cpp:2:17:2:22 | ... == ... | 4 | ifstmt.cpp:5:3:5:5 | label ...: |
|
||||
| 1 | ifstmt.cpp:2:22:2:22 | z | 1 | ifstmt.cpp:2:17:2:22 | ... == ... |
|
||||
| 1 | ifstmt.cpp:2:25:4:3 | { ... } | 2 | ifstmt.cpp:3:5:3:7 | label ...: |
|
||||
| 2 | ifstmt.c:29:5:29:7 | label ...: | 2 | ifstmt.c:29:8:29:8 | ; |
|
||||
| 2 | ifstmt.c:29:8:29:8 | ; | 4 | ifstmt.c:31:3:31:5 | label ...: |
|
||||
| 2 | ifstmt.cpp:3:5:3:7 | label ...: | 2 | ifstmt.cpp:3:8:3:8 | ; |
|
||||
| 2 | ifstmt.cpp:3:8:3:8 | ; | 4 | ifstmt.cpp:5:3:5:5 | label ...: |
|
||||
| 4 | ifstmt.c:31:3:31:5 | label ...: | 4 | ifstmt.c:31:6:31:6 | ; |
|
||||
| 4 | ifstmt.c:31:6:31:6 | ; | 5 | ifstmt.c:32:1:32:1 | return ... |
|
||||
| 4 | ifstmt.cpp:5:3:5:5 | label ...: | 4 | ifstmt.cpp:5:6:5:6 | ; |
|
||||
| 4 | ifstmt.cpp:5:6:5:6 | ; | 5 | ifstmt.cpp:6:1:6:1 | return ... |
|
||||
| 5 | ifstmt.c:32:1:32:1 | return ... | 0 | ifstmt.c:27:6:27:11 | normal |
|
||||
| 5 | ifstmt.cpp:6:1:6:1 | return ... | 0 | ifstmt.cpp:1:6:1:11 | normal |
|
||||
|
||||
15
cpp/ql/test/successor-tests/ifstmt/ifstmt/ifstmt11.ql
Normal file
15
cpp/ql/test/successor-tests/ifstmt/ifstmt/ifstmt11.ql
Normal file
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* @name ifstmt11
|
||||
* @description If an initialization exists, then the condition is a successor of the initialization.
|
||||
*/
|
||||
|
||||
import cpp
|
||||
|
||||
from IfStmt is, Expr e, Stmt s, ControlFlowNode n
|
||||
where
|
||||
s = is.getInitialization() and
|
||||
e = is.getCondition() and
|
||||
n = s.getASuccessor*() and
|
||||
not exists(ControlFlowNode m | m = e.getASuccessor*() | m = n) and
|
||||
not exists(ControlFlowNode m | m = e.getAPredecessor*() | m = n)
|
||||
select is
|
||||
Reference in New Issue
Block a user