-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[clang][analyzer] Fix a crash in alpha.unix.BlockInCriticalSection #90030
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-clang-static-analyzer-1 @llvm/pr-subscribers-clang Author: Endre Fülöp (gamesh411) ChangesIn CTU there is not always an AnalysisDeclContext for a given call. This Full diff: https://github.com/llvm/llvm-project/pull/90030.diff 1 Files Affected:
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;
+ }
}
}
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In CTU there is not always an AnalysisDeclContext for a given call.
Why?
Could you demonstrate the fix in a test?
d811a17
to
bc759c4
Compare
When analyzing C code with function pointers the checker crashes because of how the implementation extracts IdentifierInfo. Without the fix, this test crashes. Add crashing test
bc759c4
to
af05be9
Compare
After reducing a crashing TU, I have found, that the issue came up without CTU analysis as well. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now the change makes sense. I disagree with the fix though, see inline.
clang/lib/StaticAnalyzer/Checkers/BlockInCriticalSectionChecker.cpp
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
When analyzing C code with function pointers the checker crashes because
of how the implementation extracts IdentifierInfo. Without the fix, this
test crashes.