mirror of
https://github.com/github/codeql.git
synced 2026-06-06 05:57:07 +02:00
Use shared CFG getIfInit
This commit is contained in:
@@ -128,9 +128,8 @@ module GoCfg {
|
||||
|
||||
class ExprStmt = Go::ExprStmt;
|
||||
|
||||
/** If statements without init (those with init use custom steps). */
|
||||
class IfStmt extends Stmt {
|
||||
IfStmt() { this instanceof Go::IfStmt and not exists(this.(Go::IfStmt).getInit()) }
|
||||
IfStmt() { this instanceof Go::IfStmt }
|
||||
|
||||
Expr getCondition() { result = this.(Go::IfStmt).getCond() }
|
||||
|
||||
@@ -139,6 +138,8 @@ module GoCfg {
|
||||
Stmt getElse() { result = this.(Go::IfStmt).getElse() }
|
||||
}
|
||||
|
||||
AstNode getIfInit(IfStmt ifstmt) { result = ifstmt.(Go::IfStmt).getInit() }
|
||||
|
||||
class LoopStmt extends Stmt {
|
||||
LoopStmt() { this instanceof Go::LoopStmt }
|
||||
|
||||
@@ -341,8 +342,6 @@ module GoCfg {
|
||||
predicate inConditionalContext(Ast::AstNode n, ConditionKind kind) {
|
||||
kind.isBoolean() and
|
||||
(
|
||||
exists(Go::IfStmt ifstmt | ifstmt.getCond() = n and exists(ifstmt.getInit()))
|
||||
or
|
||||
n = any(Go::ForStmt fs).getCond()
|
||||
or
|
||||
exists(Go::ExpressionSwitchStmt ess |
|
||||
@@ -734,7 +733,6 @@ module GoCfg {
|
||||
}
|
||||
|
||||
predicate step(PreControlFlowNode n1, PreControlFlowNode n2) {
|
||||
ifWithInit(n1, n2) or
|
||||
rangeLoop(n1, n2) or
|
||||
switchStmt(n1, n2) or
|
||||
selectStmt(n1, n2) or
|
||||
@@ -1191,27 +1189,6 @@ module GoCfg {
|
||||
)
|
||||
}
|
||||
|
||||
private predicate ifWithInit(PreControlFlowNode n1, PreControlFlowNode n2) {
|
||||
exists(Go::IfStmt s | exists(s.getInit()) |
|
||||
n1.isBefore(s) and n2.isBefore(s.getInit())
|
||||
or
|
||||
n1.isAfter(s.getInit()) and n2.isBefore(s.getCond())
|
||||
or
|
||||
n1.isAfterTrue(s.getCond()) and n2.isBefore(s.getThen())
|
||||
or
|
||||
n1.isAfterFalse(s.getCond()) and
|
||||
(
|
||||
n2.isBefore(s.getElse())
|
||||
or
|
||||
not exists(s.getElse()) and n2.isAfter(s)
|
||||
)
|
||||
or
|
||||
n1.isAfter(s.getThen()) and n2.isAfter(s)
|
||||
or
|
||||
n1.isAfter(s.getElse()) and n2.isAfter(s)
|
||||
)
|
||||
}
|
||||
|
||||
private predicate rangeLoop(PreControlFlowNode n1, PreControlFlowNode n2) {
|
||||
exists(Go::RangeStmt s |
|
||||
// Use the shared library's auto-created `[LoopHeader]` additional node
|
||||
|
||||
Reference in New Issue
Block a user