package ctrlflow

import "golang.org/x/tools/go/analysis/passes/ctrlflow"

Package ctrlflow is an analysis that provides a syntactic control-flow graph (CFG) for the body of a function. It records whether a function cannot return. By itself, it does not report any diagnostics.

Index

Variables

var Analyzer = &analysis.Analyzer{
	Name:       "ctrlflow",
	Doc:        "build a control-flow graph",
	URL:        "https://pkg.go.dev/golang.org/x/tools/go/analysis/passes/ctrlflow",
	Run:        run,
	ResultType: reflect.TypeFor[*CFGs](),
	FactTypes:  []analysis.Fact{new(noReturn)},
	Requires:   []*analysis.Analyzer{inspect.Analyzer},
}

Types

type CFGs

type CFGs struct {
	// contains filtered or unexported fields
}

A CFGs holds the control-flow graphs for all the functions of the current package.

func (*CFGs) FuncDecl

func (c *CFGs) FuncDecl(decl *ast.FuncDecl) *cfg.CFG

FuncDecl returns the control-flow graph for a named function. It returns nil if decl.Body==nil.

func (*CFGs) FuncLit

func (c *CFGs) FuncLit(lit *ast.FuncLit) *cfg.CFG

FuncLit returns the control-flow graph for a literal function.

func (*CFGs) NoReturn

func (c *CFGs) NoReturn(fn *types.Func) bool

NoReturn reports whether the specified control-flow graph cannot return normally.

It is defined for at least all function symbols that appear as the static callee of a CallExpr in the current package, even if the callee was imported from a dependency.

The result may incorporate interprocedural information based on induction of the "no return" property over the static call graph within the package. For example, if f simply calls g and g always calls os.Exit, then both f and g may be deemed never to return.

Source Files

ctrlflow.go

Version
v0.43.0
Published
Mar 12, 2026
Platform
js/wasm
Imports
10 packages
Last checked
3 hours ago

Tools for package owners.