Skip to content

[clang][analyzer] Fix a nullptr dereference when -ftime-trace is used (Reland) #139980

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 15, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,17 @@ class SymbolConjured : public SymbolData {

// It might return null.
const Stmt *getStmt() const {
if (const auto *Parent = Elem.getParent()) {
// Sometimes the CFG element is invalid, avoid dereferencing it.
if (Elem.getIndexInBlock() >= Parent->size())
return nullptr;
}
switch (Elem->getKind()) {
case CFGElement::Initializer:
return Elem->castAs<CFGInitializer>().getInitializer()->getInit();
if (const auto *Init = Elem->castAs<CFGInitializer>().getInitializer()) {
return Init->getInit();
}
return nullptr;
case CFGElement::ScopeBegin:
return Elem->castAs<CFGScopeBegin>().getTriggerStmt();
case CFGElement::ScopeEnd:
Expand Down
5 changes: 5 additions & 0 deletions clang/test/Analysis/ftime-trace-no-init.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// RUN: %clang_analyze_cc1 -analyzer-checker=core,apiModeling %s -ftime-trace=%t.raw.json -verify
// expected-no-diagnostics

// GitHub issue 139779
struct {} a; // no-crash
Loading