[clang] [analyzer] Prevent crash due to missing EventDispatch in corner case (PR #107294)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Sep 4 12:24:19 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: None (vabridgers)
<details>
<summary>Changes</summary>
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: <root>/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 <addr> clang::ento::CheckerManager::finishedCheckerRegistration()
#<!-- -->8 <addr> clang::ento::CheckerManager::CheckerManager(clang::ASTContext&,
clang::AnalyzerOptions&, clang::Preprocessor const&,
llvm::ArrayRef<std::__cxx11::basic_string<char, std::char_traits<char>,
std::allocator<char>>>, llvm::ArrayRef<std::function<void (clang::ento::CheckerRegistry&)>>)
---
Full diff: https://github.com/llvm/llvm-project/pull/107294.diff
2 Files Affected:
- (modified) clang/lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp (+1)
- (added) clang/test/Analysis/nullability-nocrash.c (+4)
``````````diff
diff --git a/clang/lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
index 04472bb3895a78..d75dcb5a8cd644 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<ExplicitCastExpr>,
check::PostObjCMessage, check::DeadSymbols, eval::Assume,
check::Location, check::Event<ImplicitNullDerefEvent>,
+ /*EventDispatcher<ImplicitNullDerefEvent>,*/
check::BeginFunction> {
public:
diff --git a/clang/test/Analysis/nullability-nocrash.c b/clang/test/Analysis/nullability-nocrash.c
new file mode 100644
index 00000000000000..4102a4fd3a846f
--- /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
``````````
</details>
https://github.com/llvm/llvm-project/pull/107294
More information about the cfe-commits
mailing list