[PATCH] CodeGen: Fix linkage of reference temporaries
David Majnemer
david.majnemer at gmail.com
Fri Apr 25 23:00:27 PDT 2014
================
Comment at: lib/CodeGen/CGDecl.cpp:133-134
@@ -132,4 @@
- // can be uniqued.
- if (D.isExternallyVisible()) {
- Linkage = llvm::GlobalValue::LinkOnceODRLinkage;
-
----------------
Richard Smith wrote:
> Do you have tests for this change? It seems to imply that dllimport, dllexport, and selectany now work on static local variables and didn't previously.
It is a semantic error for any of those to appear on static local variables. We get this wrong but I believe that's a different bug from this one.
================
Comment at: lib/CodeGen/CodeGenModule.cpp:2873-2874
@@ -2862,5 +2872,4 @@
// Create a global variable for this lifetime-extended temporary.
- llvm::GlobalVariable *GV =
- new llvm::GlobalVariable(getModule(), Type, Constant,
- llvm::GlobalValue::PrivateLinkage,
- InitialValue, Name.c_str());
+ llvm::GlobalValue::LinkageTypes Linkage =
+ GetLLVMLinkageVarDefinition(VD, Constant);
+ unsigned AddrSpace = GetGlobalVarAddressSpace(
----------------
Richard Smith wrote:
> What should the linkage of the temporary be if the linkage of the variable is strong? Seems we have two choices here:
>
> 1) Always the same as that of the variable. This creates more symbols than are strictly necessary, but allows us to emit the variable as available_externally in some circumstances.
> 2) If the variable is strong, the temporary is private.
>
> The difference only seems to matter if it's possible to provide an available_externally definition (that is, for a static data member with an initializer specified within the class). Since our mangling doesn't collide with anyone else's, this will only matter if/when we start emitting the available_externally definitions.
I've updated this differential to implement option #2. This //should// cause us to use `available_externally` for the reference temporary if the variable was `available_externally` while using `private` if the variable was `external`.
http://reviews.llvm.org/D3515
More information about the cfe-commits
mailing list