[clang] [clang][analyzer] Fix alpha.unix.BlockInCriticalSection for CTU (PR #90030)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 25 01:03:51 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-static-analyzer-1
@llvm/pr-subscribers-clang
Author: Endre Fülöp (gamesh411)
<details>
<summary>Changes</summary>
In CTU there is not always an AnalysisDeclContext for a given call. This
led to crashes. The AnalysisDeclContext access is now checked.
---
Full diff: https://github.com/llvm/llvm-project/pull/90030.diff
1 Files Affected:
- (modified) clang/lib/StaticAnalyzer/Checkers/BlockInCriticalSectionChecker.cpp (+5-3)
``````````diff
diff --git a/clang/lib/StaticAnalyzer/Checkers/BlockInCriticalSectionChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/BlockInCriticalSectionChecker.cpp
index e4373915410fb2..9874a68ebe47af 100644
--- a/clang/lib/StaticAnalyzer/Checkers/BlockInCriticalSectionChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/BlockInCriticalSectionChecker.cpp
@@ -14,6 +14,7 @@
//
//===----------------------------------------------------------------------===//
+#include "clang/Analysis/AnalysisDeclContext.h"
#include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
#include "clang/StaticAnalyzer/Core/Checker.h"
@@ -103,9 +104,10 @@ 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;
+ if (AnalysisDeclContext *CalleCtx = Call.getCalleeAnalysisDeclContext()) {
+ Guard = &CalleCtx->getASTContext().Idents.get(GuardName);
+ IdentifierInfoInitialized = true;
+ }
}
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/90030
More information about the cfe-commits
mailing list