r340636 - Thread safety analysis no longer hands when analyzing a self-referencing initializer.
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Fri Aug 24 11:48:35 PDT 2018
Author: aaronballman
Date: Fri Aug 24 11:48:35 2018
New Revision: 340636
URL: http://llvm.org/viewvc/llvm-project?rev=340636&view=rev
Log:
Thread safety analysis no longer hands when analyzing a self-referencing initializer.
This fixes PR38640.
Modified:
cfe/trunk/lib/Analysis/ThreadSafety.cpp
cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp
Modified: cfe/trunk/lib/Analysis/ThreadSafety.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/ThreadSafety.cpp?rev=340636&r1=340635&r2=340636&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/ThreadSafety.cpp (original)
+++ cfe/trunk/lib/Analysis/ThreadSafety.cpp Fri Aug 24 11:48:35 2018
@@ -1656,6 +1656,9 @@ void BuildLockset::checkAccess(const Exp
const auto *VD = dyn_cast<VarDecl>(DRE->getDecl()->getCanonicalDecl());
if (VD && VD->isLocalVarDecl() && VD->getType()->isReferenceType()) {
if (const auto *E = VD->getInit()) {
+ // Guard against self-initialization. e.g., int &i = i;
+ if (E == Exp)
+ break;
Exp = E;
continue;
}
Modified: cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp?rev=340636&r1=340635&r2=340636&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp Fri Aug 24 11:48:35 2018
@@ -5503,3 +5503,11 @@ namespace ReturnScopedLockable {
return ptr->f();
}
}
+
+namespace PR38640 {
+void f() {
+ // Self-referencing assignment previously caused an infinite loop when thread
+ // safety analysis was enabled.
+ int &i = i; // expected-warning {{reference 'i' is not yet bound to a value when used within its own initialization}}
+}
+}
More information about the cfe-commits
mailing list