Skip to content

Commit ca281cf

Browse files
adonovangopherbot
authored andcommitted
go/analysis/passes/ctrlflow: add noreturn funcs from popular pkgs
This CL adds a number of no-return logging functions from popular logging packages to the set of known intrinsics, if their no-return status is beyond the analysis to infer. Tested manualy; unfortunately we can't test this in analysistest. For golang/go#76161 Change-Id: Ibffaabfd97fde80f3244d87c6b732b3d8b7d026a Reviewed-on: https://go-review.googlesource.com/c/tools/+/734580 Reviewed-by: Madeline Kalil <mkalil@google.com> Auto-Submit: Alan Donovan <adonovan@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
1 parent 09c21a9 commit ca281cf

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

go/analysis/passes/ctrlflow/ctrlflow.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,17 @@ func knownIntrinsic(fn *types.Func) (noreturn, known bool) {
244244

245245
// Functions known intrinsically never to return.
246246
if typesinternal.IsFunctionNamed(fn, "syscall", "Exit", "ExitProcess", "ExitThread") ||
247-
typesinternal.IsFunctionNamed(fn, "runtime", "Goexit") {
247+
typesinternal.IsFunctionNamed(fn, "runtime", "Goexit", "fatalthrow", "fatalpanic", "exit") ||
248+
// Following staticcheck (see go/ir/exits.go) we include functions
249+
// in several popular logging packages whose no-return status is
250+
// beyond the analysis to infer.
251+
// TODO(adonovan): make this list extensible.
252+
typesinternal.IsMethodNamed(fn, "go.uber.org/zap", "Logger", "Fatal", "Panic") ||
253+
typesinternal.IsMethodNamed(fn, "go.uber.org/zap", "SugaredLogger", "Fatal", "Fatalw", "Fatalf", "Panic", "Panicw", "Panicf") ||
254+
typesinternal.IsMethodNamed(fn, "github.com/sirupsen/logrus", "Logger", "Exit", "Panic", "Panicf", "Panicln") ||
255+
typesinternal.IsMethodNamed(fn, "github.com/sirupsen/logrus", "Entry", "Panicf", "Panicln") ||
256+
typesinternal.IsFunctionNamed(fn, "k8s.io/klog", "Exit", "ExitDepth", "Exitf", "Exitln", "Fatal", "FatalDepth", "Fatalf", "Fatalln") ||
257+
typesinternal.IsFunctionNamed(fn, "k8s.io/klog/v2", "Exit", "ExitDepth", "Exitf", "Exitln", "Fatal", "FatalDepth", "Fatalf", "Fatalln") {
248258
return true, true
249259
}
250260

0 commit comments

Comments
 (0)