From: Richard Smith Date: Wed, 12 Aug 2015 02:17:52 +0000 (+0000) Subject: [modules] Fix thread safety analysis to cope with merging of FieldDecls across modules. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=dd55b95fb2c2d3d65cf37c3cd8173380a97dd673;p=platform%2Fupstream%2Fllvm.git [modules] Fix thread safety analysis to cope with merging of FieldDecls across modules. llvm-svn: 244714 --- diff --git a/clang/lib/Analysis/ThreadSafetyCommon.cpp b/clang/lib/Analysis/ThreadSafetyCommon.cpp index d4b1ce2..3c4d6b3 100644 --- a/clang/lib/Analysis/ThreadSafetyCommon.cpp +++ b/clang/lib/Analysis/ThreadSafetyCommon.cpp @@ -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(ME->getMemberDecl()->getCanonicalDecl()); if (auto *VD = dyn_cast(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 index 0000000..879c038 --- /dev/null +++ b/clang/test/Modules/Inputs/thread-safety/a.h @@ -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 index 0000000..c8ed237 --- /dev/null +++ b/clang/test/Modules/Inputs/thread-safety/b.h @@ -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 index 0000000..ec849c2 --- /dev/null +++ b/clang/test/Modules/Inputs/thread-safety/c.h @@ -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 index 0000000..bd6ea83 --- /dev/null +++ b/clang/test/Modules/Inputs/thread-safety/module.map @@ -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 index 0000000..e6e85d2 --- /dev/null +++ b/clang/test/Modules/thread-safety.cpp @@ -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); +}