This is an archive of the discontinued LLVM Phabricator instance.

[MSVC] Handle out-of-line definition of static data member correctly (fix for http://llvm.org/PR21164)
ClosedPublic

Authored by alexfrol on May 19 2015, 5:38 AM.

Details

Summary

There are 3 cases of defining static const member:

  1. initialized inside the class, not defined outside the class.
  2. initialized inside the class, defined outside the class.
  3. not initialized inside the class, defined outside the class.

Revision r213304 was supposed to fix the linkage problem of case (1), but mistakenly it made case (2) behave the same.
As a result, out-of-line definition of static data member is not handled correctly.
Proposed patch distinguishes between cases (1) and (2) and allows to properly emit static const members under –fms-compatibility option.

This fixes http://llvm.org/PR21164.

Diff Detail

Repository
rL LLVM

Event Timeline

alexfrol updated this revision to Diff 26051.May 19 2015, 5:38 AM
alexfrol retitled this revision from to [MSVC] Handle out-of-line definition of static data member correctly (fix for http://llvm.org/PR21164).
alexfrol updated this object.
alexfrol edited the test plan for this revision. (Show Details)
alexfrol added reviewers: majnemer, rnk.
alexfrol set the repository for this revision to rL LLVM.
alexfrol added a subscriber: Unknown Object (MLST).
rnk added inline comments.May 19 2015, 9:41 AM
lib/AST/ASTContext.cpp
4910 ↗(On Diff #26051)

Can the last two lines be simplified to this?

VD->isFirstDecl() && VD->hasInit()

The first declaration of a static data member cannot be out of line, unless I'm mistaken.

test/CodeGenCXX/dllexport-members.cpp
113–115 ↗(On Diff #26051)

Can you add at least one test here that exercises the weak_odr linkage case? Do something like this, where the member is referenced but not defined outside the class:

struct A { static const int V = 42; };
int f() { return A::V; }
test/CodeGenCXX/ms-integer-static-data-members.cpp
1–10 ↗(On Diff #26051)

I think the explosion in RUN lines here is getting out of hand. We can test all the cases in a single TU if we just have multiple static data members in S. Do you mind doing that cleanup?

alexfrol updated this revision to Diff 26107.May 19 2015, 4:48 PM

Thank you for the quick review!
I updated the patch according to your notes.

rnk accepted this revision.May 19 2015, 5:44 PM
rnk edited edge metadata.

lgtm, thanks for the patch!

This revision is now accepted and ready to land.May 19 2015, 5:44 PM
This revision was automatically updated to reflect the committed changes.