Skip to content

Commit

Permalink
Break splitBlocksOn into a new hook (#280)
Browse files Browse the repository at this point in the history
Similar to #279, this PR breaks the logic that splits the CFG block upon
seeing a trusted function into a separate strongly-typed hook for better
maintainability and slightly better performance (due to fewer lookups in
hook points). It introduces no functionality changes.

---------

Co-authored-by: Sonal Mahajan <[email protected]>
  • Loading branch information
yuxincs and sonalmahajan15 authored Oct 4, 2024
1 parent 45bee80 commit 3c8ea06
Show file tree
Hide file tree
Showing 3 changed files with 377 additions and 362 deletions.
18 changes: 6 additions & 12 deletions assertion/function/preprocess/cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,23 +120,17 @@ func copyGraph(graph *cfg.CFG) *cfg.CFG {
}

func (p *Preprocessor) splitBlockOnTrustedFuncs(graph *cfg.CFG, thisBlock, failureBlock *cfg.Block) {
var expr *ast.ExprStmt
var call *ast.CallExpr
var retExpr any
var trustedCond ast.Expr
var ok bool

for i, node := range thisBlock.Nodes {
if expr, ok = node.(*ast.ExprStmt); !ok {
continue
}
if call, ok = expr.X.(*ast.CallExpr); !ok {
expr, ok := node.(*ast.ExprStmt)
if !ok {
continue
}
if retExpr, ok = hook.As(call, p.pass); !ok {
call, ok := expr.X.(*ast.CallExpr)
if !ok {
continue
}
if trustedCond, ok = retExpr.(ast.Expr); !ok {
trustedCond := hook.SplitBlockOn(p.pass, call)
if trustedCond == nil {
continue
}

Expand Down
Loading

0 comments on commit 3c8ea06

Please sign in to comment.