Author: Endre Fülöp Date: 2024-05-15T16:26:17+02:00 New Revision: eda098aadea3e542f95b5f0d4173f00eae42dc72
URL: https://github.com/llvm/llvm-project/commit/eda098aadea3e542f95b5f0d4173f00eae42dc72 DIFF: https://github.com/llvm/llvm-project/commit/eda098aadea3e542f95b5f0d4173f00eae42dc72.diff LOG: [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. Added: clang/test/Analysis/block-in-critical-section.c Modified: clang/lib/StaticAnalyzer/Checkers/BlockInCriticalSectionChecker.cpp Removed: ################################################################################ diff --git a/clang/lib/StaticAnalyzer/Checkers/BlockInCriticalSectionChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/BlockInCriticalSectionChecker.cpp index e138debd1361c..92347f8fafc00 100644 --- a/clang/lib/StaticAnalyzer/Checkers/BlockInCriticalSectionChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/BlockInCriticalSectionChecker.cpp @@ -103,9 +103,8 @@ class RAIIMutexDescriptor { // this function is called instead of early returning it. To avoid this, a // bool variable (IdentifierInfoInitialized) is used and the function will // be run only once. - Guard = &Call.getCalleeAnalysisDeclContext()->getASTContext().Idents.get( - GuardName); - IdentifierInfoInitialized = true; + const auto &ASTCtx = Call.getState()->getStateManager().getContext(); + Guard = &ASTCtx.Idents.get(GuardName); } } diff --git a/clang/test/Analysis/block-in-critical-section.c b/clang/test/Analysis/block-in-critical-section.c new file mode 100644 index 0000000000000..1e174af541b18 --- /dev/null +++ b/clang/test/Analysis/block-in-critical-section.c @@ -0,0 +1,6 @@ +// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.unix.BlockInCriticalSection -verify %s +// expected-no-diagnostics + +// This should not crash +int (*a)(void); +void b(void) { a(); } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits