hook

package
v0.0.0-...-ba14292 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 10, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

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

func ReplaceConditional(pass *analysis.Pass, call *ast.CallExpr) ast.Expr

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

func SplitBlockOn(pass *analysis.Pass, call *ast.CallExpr) ast.Expr

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL