mirror of
https://github.com/github/codeql.git
synced 2026-05-14 03:09:26 +02:00
Add GotoStmt, Parameter, Throw, Assignment and PatternMatchExpr to Go Ast module for updated shared CFG AstSig
Agent-Logs-Url: https://github.com/github/codeql/sessions/005953d9-1d54-4071-8cd2-5a7d26f65f61 Co-authored-by: owen-mc <62447351+owen-mc@users.noreply.github.com>
This commit is contained in:
committed by
Owen Mansel-Chan
parent
081f24a3b9
commit
beda1d26e9
@@ -9,6 +9,7 @@ module;
|
||||
|
||||
private import codeql.controlflow.ControlFlowGraph as CfgLib
|
||||
private import codeql.controlflow.SuccessorType
|
||||
private import codeql.util.Void
|
||||
|
||||
/** Contains the shared CFG library instantiation for Go. */
|
||||
module GoCfg {
|
||||
@@ -72,6 +73,14 @@ module GoCfg {
|
||||
|
||||
AstNode callableGetBody(Callable c) { result = c }
|
||||
|
||||
class Parameter extends AstNode {
|
||||
Parameter() { none() }
|
||||
|
||||
Expr getDefaultValue() { none() }
|
||||
}
|
||||
|
||||
Parameter callableGetParameter(Callable c, int index) { none() }
|
||||
|
||||
Callable getEnclosingCallable(AstNode node) {
|
||||
result = node and node instanceof Callable
|
||||
or
|
||||
@@ -152,12 +161,14 @@ module GoCfg {
|
||||
|
||||
class ContinueStmt = Go::ContinueStmt;
|
||||
|
||||
class GotoStmt = Go::GotoStmt;
|
||||
|
||||
class ReturnStmt extends Go::ReturnStmt {
|
||||
override Expr getExpr() { result = Go::ReturnStmt.super.getExpr() }
|
||||
}
|
||||
|
||||
class ThrowStmt extends Stmt {
|
||||
ThrowStmt() { none() }
|
||||
class Throw extends AstNode {
|
||||
Throw() { none() }
|
||||
|
||||
Expr getExpr() { none() }
|
||||
}
|
||||
@@ -241,12 +252,46 @@ module GoCfg {
|
||||
|
||||
boolean getValue() { result = val }
|
||||
}
|
||||
|
||||
class Assignment extends BinaryExpr {
|
||||
Assignment() { none() }
|
||||
}
|
||||
|
||||
class AssignExpr extends Assignment {
|
||||
AssignExpr() { none() }
|
||||
}
|
||||
|
||||
class CompoundAssignment extends Assignment {
|
||||
CompoundAssignment() { none() }
|
||||
}
|
||||
|
||||
class AssignLogicalAndExpr extends CompoundAssignment {
|
||||
AssignLogicalAndExpr() { none() }
|
||||
}
|
||||
|
||||
class AssignLogicalOrExpr extends CompoundAssignment {
|
||||
AssignLogicalOrExpr() { none() }
|
||||
}
|
||||
|
||||
class AssignNullCoalescingExpr extends CompoundAssignment {
|
||||
AssignNullCoalescingExpr() { none() }
|
||||
}
|
||||
|
||||
class PatternMatchExpr extends Expr {
|
||||
PatternMatchExpr() { none() }
|
||||
|
||||
Expr getExpr() { none() }
|
||||
|
||||
AstNode getPattern() { none() }
|
||||
}
|
||||
}
|
||||
|
||||
/** The Input module implementing InputSig1 and InputSig2 for Go. */
|
||||
private module Input implements Cfg0::InputSig1, Cfg1::InputSig2 {
|
||||
predicate cfgCachedStageRef() { CfgCachedStage::ref() }
|
||||
|
||||
class CallableContext = Void;
|
||||
|
||||
private newtype TLabel =
|
||||
TGoLabel(string l) { exists(Go::LabeledStmt ls | l = ls.getLabel()) } or
|
||||
TFallthrough()
|
||||
|
||||
@@ -1506,6 +1506,26 @@ module Make0<LocationSig Location, AstSig<Location> Ast> {
|
||||
n2.isAfterValue(pme, any(BooleanSuccessor s | s.getValue() = true))
|
||||
)
|
||||
or
|
||||
exists(PatternMatchExpr pme |
|
||||
n1.isBefore(pme) and
|
||||
n2.isBefore(pme.getExpr())
|
||||
or
|
||||
n1.isAfter(pme.getExpr()) and
|
||||
n2.isIn(pme)
|
||||
or
|
||||
n1.isIn(pme) and
|
||||
n2.isAfterValue(pme, any(BooleanSuccessor s | s.getValue() = false))
|
||||
or
|
||||
n1.isIn(pme) and
|
||||
n2.isAdditional(pme, patternMatchTrueTag())
|
||||
or
|
||||
n1.isAdditional(pme, patternMatchTrueTag()) and
|
||||
n2.isBefore(pme.getPattern())
|
||||
or
|
||||
n1.isAfter(pme.getPattern()) and
|
||||
n2.isAfterValue(pme, any(BooleanSuccessor s | s.getValue() = true))
|
||||
)
|
||||
or
|
||||
exists(IfStmt ifstmt |
|
||||
n1.isBefore(ifstmt) and
|
||||
n2.isBefore(ifstmt.getCondition())
|
||||
|
||||
Reference in New Issue
Block a user