aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Analysis
diff options
context:
space:
mode:
authorAaron Puchert <aaronpuchert@alice-dsl.net>2020-09-05 15:44:20 +0200
committerAaron Puchert <aaronpuchert@alice-dsl.net>2020-09-05 17:26:12 +0200
commit9dcc82f34ea9b623d82d2577b93aaf67d36dabd2 (patch)
treee1657b4c3ae758804aa8801cc0e115f4f5e79c1a /clang/lib/Analysis
parentac87480bd8beef0a4e93981e38df2c21652e1393 (diff)
downloadllvm-9dcc82f34ea9b623d82d2577b93aaf67d36dabd2.zip
llvm-9dcc82f34ea9b623d82d2577b93aaf67d36dabd2.tar.gz
llvm-9dcc82f34ea9b623d82d2577b93aaf67d36dabd2.tar.bz2
Thread safety analysis: Consider global variables in scope
Instead of just mutex members we also consider mutex globals. Unsurprisingly they are always in scope. Now the paper [1] says that > The scope of a class member is assumed to be its enclosing class, > while the scope of a global variable is the translation unit in > which it is defined. But I don't think we should limit this to TUs where a definition is available - a declaration is enough to acquire the mutex, and if a mutex is really limited in scope to a translation unit, it should probably be only declared there. [1] https://static.googleusercontent.com/media/research.google.com/en/us/pubs/archive/42958.pdf Fixes PR46354. Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D84604
Diffstat (limited to 'clang/lib/Analysis')
-rw-r--r--clang/lib/Analysis/ThreadSafety.cpp13
1 files changed, 11 insertions, 2 deletions
diff --git a/clang/lib/Analysis/ThreadSafety.cpp b/clang/lib/Analysis/ThreadSafety.cpp
index 64e0da9..1d4aaba 100644
--- a/clang/lib/Analysis/ThreadSafety.cpp
+++ b/clang/lib/Analysis/ThreadSafety.cpp
@@ -1266,13 +1266,22 @@ ClassifyDiagnostic(const AttrTy *A) {
}
bool ThreadSafetyAnalyzer::inCurrentScope(const CapabilityExpr &CapE) {
- if (!CurrentMethod)
+ const threadSafety::til::SExpr *SExp = CapE.sexpr();
+ assert(SExp && "Null expressions should be ignored");
+
+ // Global variables are always in scope.
+ if (isa<til::LiteralPtr>(SExp))
+ return true;
+
+ // Members are in scope from methods of the same class.
+ if (const auto *P = dyn_cast<til::Project>(SExp)) {
+ if (!CurrentMethod)
return false;
- if (const auto *P = dyn_cast_or_null<til::Project>(CapE.sexpr())) {
const auto *VD = P->clangDecl();
if (VD)
return VD->getDeclContext() == CurrentMethod->getDeclContext();
}
+
return false;
}