Documentation ¶
Overview ¶
Package hook implements a hook framework for NilAway where it hooks into different parts to provide additional context for certain function calls. This is useful for well-known standard or 3rd party libraries where we can encode certain knowledge about them (e.g., `assert.Nil(t, x)` implies `x == nil`) and use that to provide better analysis.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssumeReturn ¶
func AssumeReturn(pass *analysis.Pass, call *ast.CallExpr) *annotation.ProduceTrigger
AssumeReturn returns the producer for the return value of the given call expression, which would have the assumed nilability. This is useful for modeling the return value of stdlib and 3rd party functions that are not analyzed by NilAway. For example, "errors.New" is assumed to return a nonnil value. If the given call expression does not match any known function, nil is returned.
func ReplaceConditional ¶
ReplaceConditional replaces a call to a matched function with the returned expression. This is useful for modeling stdlib and 3rd party functions that return a single boolean value, which implies nilability of the arguments. For example, `errors.As(err, &target)` implies `target != nil`, so it can be replaced with `target != nil`.
If the call does not match any known function, nil is returned.
func SplitBlockOn ¶
SplitBlockOn splits the CFG block on seeing matched trusted functions, where the condition is the returned expression. For example, a binary expression `x != nil` is returned for trusted function `assert.NotNil(t, x)`, and the CFG block is split as if it were written like `if x != nil { <...code after the function call...> }`. This helps NilAway understand the nilability of the arguments after certain functions with side effects.
Types ¶
This section is empty.