Skip to content

Commit f5cd601

Browse files
authored
Fix nullptr dereference introduced by #1819 (#1864)
* Fix nullptr dereference introduced by #1819 * fix clang-tidy warning * Add condition check around m_Multiplexer usage instead of assigning an empty Multiplexer, because Cling assumes m_Multiplexer == nullptr * Refactor * Add the check in shouldSkipFunctionBody
1 parent e62f569 commit f5cd601

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

tools/ClangPlugin.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ void InitTimers();
182182
auto& MultiplexC = cast<MultiplexConsumer>(m_CI.getASTConsumer());
183183
auto& RobbedCs = ACCESS(MultiplexC, Consumers);
184184
assert(RobbedCs.back().get() == this && "Clad is not the last consumer");
185+
185186
const auto& Macros = m_CI.getPreprocessorOpts().Macros;
186187
const bool IsCling = llvm::any_of(
187188
Macros, [](const auto& Macro) { return Macro.first == "__CLING__"; });
@@ -477,6 +478,8 @@ void InitTimers();
477478
}
478479

479480
void CladPlugin::SendToMultiplexer() {
481+
if (!m_Multiplexer)
482+
return;
480483
for (unsigned i = m_MultiplexerProcessedDelayedCallsIdx;
481484
i < m_DelayedCalls.size(); ++i) {
482485
auto DelayedCall = m_DelayedCalls[i];
@@ -653,7 +656,8 @@ void InitTimers();
653656
FinalizeTranslationUnit();
654657
SendToMultiplexer();
655658
}
656-
m_Multiplexer->HandleTranslationUnit(C);
659+
if (m_Multiplexer)
660+
m_Multiplexer->HandleTranslationUnit(C);
657661
}
658662

659663
void CladPlugin::PrintStats() {
@@ -712,7 +716,8 @@ void InitTimers();
712716
llvm::errs() << "\n";
713717
}
714718

715-
m_Multiplexer->PrintStats();
719+
if (m_Multiplexer)
720+
m_Multiplexer->PrintStats();
716721
}
717722

718723
} // end namespace plugin

tools/ClangPlugin.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ struct DifferentiationOptions {
229229
void PrintStats() override;
230230

231231
bool shouldSkipFunctionBody(clang::Decl* D) override {
232-
return m_Multiplexer->shouldSkipFunctionBody(D);
232+
return m_Multiplexer ? m_Multiplexer->shouldSkipFunctionBody(D) : true;
233233
}
234234

235235
// SemaConsumer
@@ -243,7 +243,8 @@ struct DifferentiationOptions {
243243
void ForgetSema() override {
244244
// ForgetSema is called in the destructor of Sema which is much later
245245
// than where we can process anything. We can't delay this call.
246-
m_Multiplexer->ForgetSema();
246+
if (m_Multiplexer)
247+
m_Multiplexer->ForgetSema();
247248
}
248249

249250
// FIXME: We should hide ProcessDiffRequest when we implement proper

0 commit comments

Comments
 (0)