From 7e373835f1d6739e388a2c84d2f52a606df4fc45 Mon Sep 17 00:00:00 2001 From: Vince Bridgers Date: Wed, 4 Sep 2024 20:36:06 +0200 Subject: [PATCH] [analyzer] Prevent crash due to missing EventDispatch in corner case Random testing revealed it's possible to crash the analyzer through a rare command line invocation: clang -cc1 -analyze -analyzer-checker=nullability empty.c where the source file, empty.c is an empty source file. This change simply registers the ImplictNullDeref Event Dispatcher as is done in other similar checks to avoid the crash. clang: /clang/lib/StaticAnalyzer/Core/CheckerManager.cpp:56: void clang::ento::CheckerManager::finishedCheckerRegistration(): Assertion `Event.second.HasDispatcher && "No dispatcher registered for an event"' failed. PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ Stack dump: 0. Program arguments: clang -cc1 -analyze -analyzer-checker=nullability nullability-nocrash.c #0 ... ... #7 clang::ento::CheckerManager::finishedCheckerRegistration() #8 clang::ento::CheckerManager::CheckerManager(clang::ASTContext&, clang::AnalyzerOptions&, clang::Preprocessor const&, llvm::ArrayRef, std::allocator>>, llvm::ArrayRef>) --- clang/lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp | 1 + clang/test/Analysis/nullability-nocrash.c | 4 ++++ 2 files changed, 5 insertions(+) create mode 100644 clang/test/Analysis/nullability-nocrash.c diff --git a/clang/lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp index 04472bb3895a7..d75dcb5a8cd64 100644 --- a/clang/lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp @@ -84,6 +84,7 @@ class NullabilityChecker check::PostCall, check::PostStmt, check::PostObjCMessage, check::DeadSymbols, eval::Assume, check::Location, check::Event, + /*EventDispatcher,*/ check::BeginFunction> { public: diff --git a/clang/test/Analysis/nullability-nocrash.c b/clang/test/Analysis/nullability-nocrash.c new file mode 100644 index 0000000000000..4102a4fd3a846 --- /dev/null +++ b/clang/test/Analysis/nullability-nocrash.c @@ -0,0 +1,4 @@ +// RUN: %clang_analyze_cc1 -w -analyzer-checker=nullability \ +// RUN: -analyzer-output=text -verify %s +// +// expected-no-diagnostics