Skip to content

Commit da11ede

Browse files
vabridgersVince Bridgers
and
Vince Bridgers
authored
[analyzer] Remove overzealous "No dispatcher registered" assertion (#107294)
Random testing revealed it's possible to crash the analyzer with the command line invocation: clang -cc1 -analyze -analyzer-checker=nullability empty.c where the source file, empty.c is an empty source file. ``` 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&)>>) ``` This commit removes the assertion which failed here, because it was logically incorrect: it required that if an Event is handled by some (enabled) checker, then there must be an **enabled** checker which can emit that kind of Event. It should be OK to disable the event-producing checkers but enable an event-consuming checker which has different responsibilities in addition to handling the events. Note that this assertion was in an `#ifndef NDEBUG` block, so this change does not impact the non-debug builds. Co-authored-by: Vince Bridgers <vince.a.bridgers@ericsson.com>
1 parent 04742f3 commit da11ede

File tree

4 files changed

+13
-13
lines changed

4 files changed

+13
-13
lines changed

clang/include/clang/StaticAnalyzer/Core/CheckerManager.h

-2
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,6 @@ class CheckerManager {
164164

165165
bool hasPathSensitiveCheckers() const;
166166

167-
void finishedCheckerRegistration();
168-
169167
const LangOptions &getLangOpts() const { return LangOpts; }
170168
const AnalyzerOptions &getAnalyzerOptions() const { return AOptions; }
171169
const Preprocessor &getPreprocessor() const {

clang/lib/StaticAnalyzer/Core/CheckerManager.cpp

-10
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,6 @@ bool CheckerManager::hasPathSensitiveCheckers() const {
4848
EvalCallCheckers, EndOfTranslationUnitCheckers);
4949
}
5050

51-
void CheckerManager::finishedCheckerRegistration() {
52-
#ifndef NDEBUG
53-
// Make sure that for every event that has listeners, there is at least
54-
// one dispatcher registered for it.
55-
for (const auto &Event : Events)
56-
assert(Event.second.HasDispatcher &&
57-
"No dispatcher registered for an event");
58-
#endif
59-
}
60-
6151
void CheckerManager::reportInvalidCheckerOptionValue(
6252
const CheckerBase *C, StringRef OptionName,
6353
StringRef ExpectedValueDesc) const {

clang/lib/StaticAnalyzer/Frontend/CreateCheckerManager.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ CheckerManager::CheckerManager(
2828
AOptions, checkerRegistrationFns);
2929
Registry.initializeRegistry(*this);
3030
Registry.initializeManager(*this);
31-
finishedCheckerRegistration();
3231
}
3332

3433
CheckerManager::CheckerManager(AnalyzerOptions &AOptions,
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: %clang_analyze_cc1 -w -analyzer-checker=nullability \
2+
// RUN: -analyzer-output=text -verify %s
3+
//
4+
// expected-no-diagnostics
5+
//
6+
// Previously there was an assertion requiring that if an Event is handled by
7+
// some enabled checker, then there must be at least one enabled checker which
8+
// can emit that kind of Event.
9+
// This assertion failed when NullabilityChecker (which is a subclass of
10+
// check::Event<ImplicitNullDerefEvent>) was enabled, but the checkers
11+
// inheriting from EventDispatcher<ImplicitNullDerefEvent> were all disabled.
12+
// This test file validates that enabling the nullability checkers (without any
13+
// other checkers) no longer causes a crash.

0 commit comments

Comments
 (0)