[PATCH] D51382: [MinGW] Don't mark external variables as DSO local

Reid Kleckner via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 28 14:54:41 PDT 2018


rnk added inline comments.


================
Comment at: lib/CodeGen/CodeGenModule.cpp:737
+    // potentially could come from another DLL as DSO local.
+    if (GV->hasExternalLinkage() && GV->isDeclaration() &&
+        isa<llvm::GlobalVariable>(GV) && !GV->isThreadLocal())
----------------
I think this linkage and declaration check should be `GV->isDeclarationForLinker()`, since that will catch `available_externally` globals as well. Those would come from a static data member of a class template that has an explicit instantiation declaration:
```
template <typename T>
struct Foo {
  static const int x = 42;
};
extern template struct Foo<int>;
const int *bar() {
  return &Foo<int>::x;
}
```
Yep, that does it on x86_64-windows-gnu. We probably want a stub for `Foo<int>::x`.

Can you add a test at clang/test/CodeGenCXX/dso-local.cpp for this?


Repository:
  rC Clang

https://reviews.llvm.org/D51382





More information about the cfe-commits mailing list