Skip to content

Commit ca7be03

Browse files
committed
[clang][analyzer] Fix alpha.unix.BlockInCriticalSection for CTU
In CTU there is not always an AnalysisDeclContext for a given call. This led to crashes. The AnalysisDeclContext access is now checked.
1 parent 415616d commit ca7be03

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

clang/lib/StaticAnalyzer/Checkers/BlockInCriticalSectionChecker.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
//
1515
//===----------------------------------------------------------------------===//
1616

17+
#include "clang/Analysis/AnalysisDeclContext.h"
1718
#include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
1819
#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
1920
#include "clang/StaticAnalyzer/Core/Checker.h"
@@ -103,9 +104,10 @@ class RAIIMutexDescriptor {
103104
// this function is called instead of early returning it. To avoid this, a
104105
// bool variable (IdentifierInfoInitialized) is used and the function will
105106
// be run only once.
106-
Guard = &Call.getCalleeAnalysisDeclContext()->getASTContext().Idents.get(
107-
GuardName);
108-
IdentifierInfoInitialized = true;
107+
if (AnalysisDeclContext *CalleCtx = Call.getCalleeAnalysisDeclContext()) {
108+
Guard = &CalleCtx->getASTContext().Idents.get(GuardName);
109+
IdentifierInfoInitialized = true;
110+
}
109111
}
110112
}
111113

0 commit comments

Comments
 (0)