[PATCH] D38458: Fix assertion failure in thread safety analysis (PR34800).

Alexander Kornienko via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 4 03:26:28 PDT 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL314895: Fix assertion failure in thread safety analysis (PR34800). (authored by alexfh).

Repository:
  rL LLVM

https://reviews.llvm.org/D38458

Files:
  cfe/trunk/include/clang/Analysis/Analyses/ThreadSafetyTIL.h
  cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp


Index: cfe/trunk/include/clang/Analysis/Analyses/ThreadSafetyTIL.h
===================================================================
--- cfe/trunk/include/clang/Analysis/Analyses/ThreadSafetyTIL.h
+++ cfe/trunk/include/clang/Analysis/Analyses/ThreadSafetyTIL.h
@@ -909,15 +909,10 @@
 public:
   static bool classof(const SExpr *E) { return E->opcode() == COP_Project; }
 
-  Project(SExpr *R, StringRef SName)
-      : SExpr(COP_Project), Rec(R), SlotName(SName), Cvdecl(nullptr)
-  { }
   Project(SExpr *R, const clang::ValueDecl *Cvd)
-      : SExpr(COP_Project), Rec(R), SlotName(Cvd->getName()), Cvdecl(Cvd)
-  { }
-  Project(const Project &P, SExpr *R)
-      : SExpr(P), Rec(R), SlotName(P.SlotName), Cvdecl(P.Cvdecl)
-  { }
+      : SExpr(COP_Project), Rec(R), Cvdecl(Cvd) {
+    assert(Cvd && "ValueDecl must not be null");
+  }
 
   SExpr *record() { return Rec; }
   const SExpr *record() const { return Rec; }
@@ -931,10 +926,14 @@
   }
 
   StringRef slotName() const {
-    if (Cvdecl)
+    if (Cvdecl->getDeclName().isIdentifier())
       return Cvdecl->getName();
-    else
-      return SlotName;
+    if (!SlotName) {
+      SlotName = "";
+      llvm::raw_string_ostream OS(*SlotName);
+      Cvdecl->printName(OS);
+    }
+    return *SlotName;
   }
 
   template <class V>
@@ -953,7 +952,7 @@
 
 private:
   SExpr* Rec;
-  StringRef SlotName;
+  mutable llvm::Optional<std::string> SlotName;
   const clang::ValueDecl *Cvdecl;
 };
 
Index: cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp
===================================================================
--- cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp
+++ cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp
@@ -5233,3 +5233,18 @@
   } // expected-warning {{mutex 'lock_' is still held at the end of function}}
   Mutex lock_ ACQUIRED_BEFORE("");
 };
+
+namespace PR34800 {
+struct A {
+  operator int() const;
+};
+struct B {
+  bool g() __attribute__((locks_excluded(h))); // expected-warning {{'locks_excluded' attribute requires arguments whose type is annotated with 'capability' attribute; type here is 'int'}}
+  int h;
+};
+struct C {
+  B *operator[](int);
+};
+C c;
+void f() { c[A()]->g(); }
+} // namespace PR34800


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D38458.117652.patch
Type: text/x-patch
Size: 2222 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20171004/4951fa3c/attachment-0001.bin>


More information about the cfe-commits mailing list