This is an archive of the discontinued LLVM Phabricator instance.

CodeGen: Fix linkage of reference temporaries
ClosedPublic

Authored by majnemer on Apr 25 2014, 10:16 AM.

Details

Summary

A reference temporary should inherit the linkage of the variable it
initializes. Otherwise, we may hit cases where a reference temporary
wouldn't have the same value in all translation units.

Diff Detail

Event Timeline

majnemer updated this revision to Diff 8852.Apr 25 2014, 10:16 AM
majnemer retitled this revision from to CodeGen: Fix linkage of reference temporaries.
majnemer updated this object.
majnemer added a reviewer: rsmith.
majnemer added a subscriber: Unknown Object (MLST).
majnemer updated this revision to Diff 8856.Apr 25 2014, 1:37 PM

Handle static data members.

majnemer updated this revision to Diff 8857.Apr 25 2014, 3:55 PM

Give proper linkage to things with GVA_TemplateInstantiation.

rsmith edited edge metadata.Apr 25 2014, 6:27 PM

This basically looks good to me, but we really need to get the Itanium ABI to cover this.

lib/CodeGen/CGDecl.cpp
133–134

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.

138–140

Hmm, I wonder why we don't do this for static locals too. Emitting it both eagerly and with a discardable linkage makes very little sense to me...

lib/CodeGen/CodeGenModule.cpp
2873–2874

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.

majnemer updated this revision to Diff 8862.Apr 25 2014, 10:56 PM
majnemer edited edge metadata.

Give reference temporaries private linkage if their variable has strong, external linkage.

majnemer added inline comments.Apr 25 2014, 11:00 PM
lib/CodeGen/CGDecl.cpp
133–134

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.

lib/CodeGen/CodeGenModule.cpp
2873–2874

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.

rsmith accepted this revision.Apr 28 2014, 2:19 PM
rsmith edited edge metadata.

LGTM

I expect we should do the same thing for visibility of such temporaries.

This revision is now accepted and ready to land.Apr 28 2014, 2:19 PM
majnemer closed this revision.Apr 30 2014, 12:05 AM

Committed in rL207451