summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaDecl.cpp
diff options
context:
space:
mode:
authorHans Wennborg <hans@hanshq.net>2015-08-28 21:47:01 +0000
committerHans Wennborg <hans@hanshq.net>2015-08-28 21:47:01 +0000
commit6eaa8323a887a878f54dfcc65d4fff72c0f5c161 (patch)
tree7dda0796d6e35b1752714167c273cb6bf0010ffc /clang/lib/Sema/SemaDecl.cpp
parente235d4502665e377cc920049dc33dfb693ad2067 (diff)
downloadbcm5719-llvm-6eaa8323a887a878f54dfcc65d4fff72c0f5c161.tar.gz
bcm5719-llvm-6eaa8323a887a878f54dfcc65d4fff72c0f5c161.zip
Allow TLS vars in dllimport/export functions; only inline dllimport functions when safe (PR24593)
This patch does two things: 1) Don't error about dllimport/export on thread-local static local variables. We put those attributes on static locals in dllimport/export functions implicitly in case the function gets inlined. Now, for TLS variables this is a problem because we can't import such variables, but it's a benign problem becase: 2) Make sure we never inline a dllimport function TLS static locals. In fact, never inline a dllimport function that references a non-imported function or variable (because these are not defined in the importing library). This seems to match MSVC's behaviour. Differential Revision: http://reviews.llvm.org/D12422 llvm-svn: 246338
Diffstat (limited to 'clang/lib/Sema/SemaDecl.cpp')
-rw-r--r--clang/lib/Sema/SemaDecl.cpp14
1 files changed, 11 insertions, 3 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index c94d2dd5a9e..1fe6a5c18f1 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -9967,9 +9967,17 @@ Sema::FinalizeDeclaration(Decl *ThisDecl) {
// dllimport/dllexport variables cannot be thread local, their TLS index
// isn't exported with the variable.
if (DLLAttr && VD->getTLSKind()) {
- Diag(VD->getLocation(), diag::err_attribute_dll_thread_local) << VD
- << DLLAttr;
- VD->setInvalidDecl();
+ FunctionDecl *F = dyn_cast<FunctionDecl>(VD->getDeclContext());
+ if (F && getDLLAttr(F)) {
+ assert(VD->isStaticLocal());
+ // But if this is a static local in a dlimport/dllexport function, the
+ // function will never be inlined, which means the var would never be
+ // imported, so having it marked import/export is safe.
+ } else {
+ Diag(VD->getLocation(), diag::err_attribute_dll_thread_local) << VD
+ << DLLAttr;
+ VD->setInvalidDecl();
+ }
}
if (UsedAttr *Attr = VD->getAttr<UsedAttr>()) {
OpenPOWER on IntegriCloud