Skip to content

Commit 89f1cd7

Browse files
committed
[clang][analyzer] Fix a nullptr dereference when -ftime-trace is used
Fixes llvm#139779. The bug was introduced in llvm#137355 in `SymbolConjured::getStmt`, when trying to obtain a statement for a CFG initializer without an initializer. This commit adds a null check before access.
1 parent 7038d50 commit 89f1cd7

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ class SymbolConjured : public SymbolData {
103103
const Stmt *getStmt() const {
104104
switch (Elem->getKind()) {
105105
case CFGElement::Initializer:
106+
if (Elem->castAs<CFGInitializer>().getInitializer() == nullptr)
107+
return nullptr;
106108
return Elem->castAs<CFGInitializer>().getInitializer()->getInit();
107109
case CFGElement::ScopeBegin:
108110
return Elem->castAs<CFGScopeBegin>().getTriggerStmt();
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// RUN: %clang --analyze %s -ftime-trace -Xclang -verify
2+
// expected-no-diagnostics
3+
4+
// GitHub issue 139779
5+
struct {} a; // no-crash

0 commit comments

Comments
 (0)