Skip to content

Commit

Permalink
[analyzer] Remove assert from CheckerManager for registered Events
Browse files Browse the repository at this point in the history
Random testing revealed it's possible to crash the analyzer through a rare
command line invocation:

clang -cc1 -analyze -analyzer-checker=nullability empty.c

The assert in CheckerManager.cpp was deemed to be too strict so is removed.

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&)>>)
  • Loading branch information
Vince Bridgers committed Sep 5, 2024
1 parent 1a12647 commit b7ab0f7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
10 changes: 1 addition & 9 deletions clang/lib/StaticAnalyzer/Core/CheckerManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,7 @@ bool CheckerManager::hasPathSensitiveCheckers() const {
EvalCallCheckers, EndOfTranslationUnitCheckers);
}

void CheckerManager::finishedCheckerRegistration() {
#ifndef NDEBUG
// Make sure that for every event that has listeners, there is at least
// one dispatcher registered for it.
for (const auto &Event : Events)
assert(Event.second.HasDispatcher &&
"No dispatcher registered for an event");
#endif
}
void CheckerManager::finishedCheckerRegistration() {}

void CheckerManager::reportInvalidCheckerOptionValue(
const CheckerBase *C, StringRef OptionName,
Expand Down
10 changes: 10 additions & 0 deletions clang/test/Analysis/nullability-nocrash.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// RUN: %clang_analyze_cc1 -w -analyzer-checker=nullability \
// RUN: -analyzer-output=text -verify %s
//
// expected-no-diagnostics
//
// This case previously crashed because of an assert in CheckerManager.cpp,
// checking for registered event dispatchers. This check is too strict so
// was removed by this commit. This test case covers the previous crash,
// and is expected to simply not crash. The source file can be anything,
// and does not need to be empty.

0 comments on commit b7ab0f7

Please sign in to comment.