Thread safety analysis no longer hands when analyzing a self-referencing initializer.
authorAaron Ballman <aaron@aaronballman.com>
Fri, 24 Aug 2018 18:48:35 +0000 (18:48 +0000)
committerAaron Ballman <aaron@aaronballman.com>
Fri, 24 Aug 2018 18:48:35 +0000 (18:48 +0000)
This fixes PR38640.

llvm-svn: 340636

clang/lib/Analysis/ThreadSafety.cpp
clang/test/SemaCXX/warn-thread-safety-analysis.cpp

index 74648df..88b3f3c 100644 (file)
@@ -1656,6 +1656,9 @@ void BuildLockset::checkAccess(const Expr *Exp, AccessKind AK,
     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;
       }
index 50d0988..29408e8 100644 (file)
@@ -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}}
+}
+}