[clang] [clang][analyzer] Fix alpha.unix.BlockInCriticalSection for CTU (PR #90030)
Endre Fülöp via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 25 01:03:19 PDT 2024
https://github.com/gamesh411 created https://github.com/llvm/llvm-project/pull/90030
In CTU there is not always an AnalysisDeclContext for a given call. This
led to crashes. The AnalysisDeclContext access is now checked.
>From de695f8e556e1efd6b2a4e69f916467af94e0c0d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Endre=20F=C3=BCl=C3=B6p?= <endre.fulop at sigmatechnology.com>
Date: Tue, 9 Apr 2024 10:44:43 +0200
Subject: [PATCH] [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.
---
.../Checkers/BlockInCriticalSectionChecker.cpp | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
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;
+ }
}
}
More information about the cfe-commits
mailing list