[modules] Fix thread safety analysis to cope with merging of FieldDecls across modules.
authorRichard Smith <richard-llvm@metafoo.co.uk>
Wed, 12 Aug 2015 02:17:52 +0000 (02:17 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Wed, 12 Aug 2015 02:17:52 +0000 (02:17 +0000)
llvm-svn: 244714

clang/lib/Analysis/ThreadSafetyCommon.cpp
clang/test/Modules/Inputs/thread-safety/a.h [new file with mode: 0644]
clang/test/Modules/Inputs/thread-safety/b.h [new file with mode: 0644]
clang/test/Modules/Inputs/thread-safety/c.h [new file with mode: 0644]
clang/test/Modules/Inputs/thread-safety/module.map [new file with mode: 0644]
clang/test/Modules/thread-safety.cpp [new file with mode: 0644]

index d4b1ce2..3c4d6b3 100644 (file)
@@ -344,7 +344,8 @@ til::SExpr *SExprBuilder::translateMemberExpr(const MemberExpr *ME,
   til::SExpr *BE = translate(ME->getBase(), Ctx);
   til::SExpr *E  = new (Arena) til::SApply(BE);
 
-  const ValueDecl *D = ME->getMemberDecl();
+  const ValueDecl *D =
+      cast<ValueDecl>(ME->getMemberDecl()->getCanonicalDecl());
   if (auto *VD = dyn_cast<CXXMethodDecl>(D))
     D = getFirstVirtualDecl(VD);
 
diff --git a/clang/test/Modules/Inputs/thread-safety/a.h b/clang/test/Modules/Inputs/thread-safety/a.h
new file mode 100644 (file)
index 0000000..879c038
--- /dev/null
@@ -0,0 +1,4 @@
+struct __attribute__((lockable)) mutex {
+  void lock() __attribute__((exclusive_lock_function));
+  void unlock() __attribute__((unlock_function));
+};
diff --git a/clang/test/Modules/Inputs/thread-safety/b.h b/clang/test/Modules/Inputs/thread-safety/b.h
new file mode 100644 (file)
index 0000000..c8ed237
--- /dev/null
@@ -0,0 +1,8 @@
+#include "a.h"
+
+struct X {
+  mutex m;
+  int n __attribute__((guarded_by(m)));
+
+  void f();
+};
diff --git a/clang/test/Modules/Inputs/thread-safety/c.h b/clang/test/Modules/Inputs/thread-safety/c.h
new file mode 100644 (file)
index 0000000..ec849c2
--- /dev/null
@@ -0,0 +1,10 @@
+#include "a.h"
+
+struct X {
+  mutex m;
+  int n __attribute__((guarded_by(m)));
+
+  void f();
+};
+
+inline void unlock(X &x) __attribute__((unlock_function(x.m))) { x.m.unlock(); }
diff --git a/clang/test/Modules/Inputs/thread-safety/module.map b/clang/test/Modules/Inputs/thread-safety/module.map
new file mode 100644 (file)
index 0000000..bd6ea83
--- /dev/null
@@ -0,0 +1,3 @@
+module a { header "a.h" }
+module b { header "b.h" export * }
+module c { header "c.h" export * }
diff --git a/clang/test/Modules/thread-safety.cpp b/clang/test/Modules/thread-safety.cpp
new file mode 100644 (file)
index 0000000..e6e85d2
--- /dev/null
@@ -0,0 +1,18 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -fimplicit-module-maps \
+// RUN:            -I%S/Inputs/thread-safety -std=c++11 -Wthread-safety \
+// RUN:            -verify %s
+//
+// expected-no-diagnostics
+
+#include "b.h"
+#include "c.h"
+
+bool g();
+void X::f() {
+  m.lock();
+  if (g())
+    m.unlock();
+  else
+    unlock(*this);
+}