Skip to content

Commit eda098a

Browse files
authored
[clang][analyzer] Fix a crash in alpha.unix.BlockInCriticalSection (#90030)
When analyzing C code with function pointers the checker crashes because of how the implementation extracts `IdentifierInfo`. Without the fix, this test crashes.
1 parent 61da636 commit eda098a

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

clang/lib/StaticAnalyzer/Checkers/BlockInCriticalSectionChecker.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,8 @@ class RAIIMutexDescriptor {
103103
// this function is called instead of early returning it. To avoid this, a
104104
// bool variable (IdentifierInfoInitialized) is used and the function will
105105
// be run only once.
106-
Guard = &Call.getCalleeAnalysisDeclContext()->getASTContext().Idents.get(
107-
GuardName);
108-
IdentifierInfoInitialized = true;
106+
const auto &ASTCtx = Call.getState()->getStateManager().getContext();
107+
Guard = &ASTCtx.Idents.get(GuardName);
109108
}
110109
}
111110

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.unix.BlockInCriticalSection -verify %s
2+
// expected-no-diagnostics
3+
4+
// This should not crash
5+
int (*a)(void);
6+
void b(void) { a(); }

0 commit comments

Comments
 (0)