This is an archive of the discontinued LLVM Phabricator instance.

Use the MS ABI for Win32 target by default
ClosedPublic

Authored by hans on Dec 13 2013, 9:22 AM.

Details

Summary

This makes Clang use the MS ABI by default when targeting Win32.

In addition to being a sensible default, this also improves the test coverage for the MS ABI: any bot that targets Win32 will now run the tests in MS ABI mode by default.

I plan to commit this in two steps: test updates first, and functionality change second so that it can be reverted separately if needed.

Diff Detail

Event Timeline

rnk added a comment.Dec 13 2013, 10:43 AM

I think all the test/CodeGen* changes are good, and should probably land now.

The test/CXX and test/SemaCXX changes should probably be reviewed separately by Richard.

test/CXX/drs/dr2xx.cpp
543 ↗(On Diff #6089)

So, I remember we decided to do it this way, but now we've essentially weakened this test to pass if we fail to diagnose this in the Itanium C++ ABI. Can you remind me what the issue is here? This has to do with differing operator delete lookup behavior?

I wonder if we're being too eager when performing operator delete lookup for a class with a virtual destructor. Instead of performing the lookup when the destructor is declared, could we defer it until the vtable is used?

test/CXX/class.access/p4.cpp
129 ↗(On Diff #6089)

Why do we do the access check in the callee under the MS ABI? We can still do dtor access checks in the caller, even though we actually make the call in the callee, can't we? Presumably MSVC redundantly checks access in both places?

(Do we need to omit the access checking in the caller for compatibility somehow?)

test/CXX/drs/dr2xx.cpp
543 ↗(On Diff #6089)

Please conditionalize this extra diagnostic on use of the MS ABI. Do we have a predefined macro indicating the ABI? If not, maybe we should add one?

test/CXX/special/class.dtor/p5-0x.cpp
98–104 ↗(On Diff #6089)

This looks incorrect. We shouldn't be trying to mark the operator delete as used if the destructor is deleted.

test/Sema/empty1.c
1 ↗(On Diff #6089)

This looks weird. I think you're adding this because empty structs have size 4 under MSVC, but that's controlled by the psABI, not the C++ ABI.

test/SemaCXX/destructor.cpp
86–93 ↗(On Diff #6089)

Please test that this produces diagnostics with the MS ABI, rather than not testing it at all.

108–117 ↗(On Diff #6089)

There's something odd here. We should be producing a note indicating the place at which the instantiation of A<int> was triggered under the MS ABI.

test/SemaCXX/implicit-virtual-member-functions.cpp
7–16 ↗(On Diff #6089)

Can you provide an alternative set of expected diagnostics here for MS ABI rather than disabling that half of the test? (I assume the point is that we trigger operator delete lookup earlier?)

test/SemaCXX/undefined-internal.cpp
1–4 ↗(On Diff #6089)

Why does this test need to force the Itanium ABI?

test/SemaCXX/virtual-base-used.cpp
1 ↗(On Diff #6089)

Why does this test need to force the Itanium ABI?

test/SemaCXX/warn-weak-vtables.cpp
1 ↗(On Diff #6089)

Can you also test this in MS ABI mode, to ensure the warning is suppressed there? Something like -Wweak-vtables -Wweak-template-vtables -Werror (with no -verify)?

test/SemaTemplate/virtual-member-functions.cpp
89–93 ↗(On Diff #6089)

Maybe instead change this test to pass the arguments by reference instead of by value?

hans added a comment.Dec 13 2013, 2:34 PM

I think all the test/CodeGen* changes are good, and should probably land now.

OK, I'll split off and commit those. It should make this patch easier to manage :)

test/CXX/class.access/p4.cpp
129 ↗(On Diff #6089)

IIRC, Reid told me that John had told him to do the access check in the callee too when he implemented this.

We still have the access check in the caller.

test/CXX/drs/dr2xx.cpp
543 ↗(On Diff #6089)

Can you remind me what the issue is here? This has to do with differing operator delete lookup behavior?

Yes, we diagnose the multiple 'operator delete' when 'virtual ~C()' is declared below, whereas in Itanium we diagnose it when that dtor is defined further on.

543 ↗(On Diff #6089)

Please conditionalize this extra diagnostic on use of the MS ABI.

Done.

Do we have a predefined macro indicating the ABI? If not, maybe we should add one?

No, we don't have a macro for this. We could create one, but it's also easy to run the test in both modes and set a macro ourselves, I've done that in a few other tests.

test/CXX/special/class.dtor/p5-0x.cpp
98–104 ↗(On Diff #6089)

But neither ~D3() nor ~D4() below are deleted.

test/Sema/empty1.c
1 ↗(On Diff #6089)

Hmm, it seems to be controlled by -cxx-abi by us :) I agree this is weird, though.

Would you be ok a FIXME here and filing a bug with Warren on the cc list? Or running the test with a fixed target?

test/SemaCXX/destructor.cpp
86–93 ↗(On Diff #6089)

Done.

108–117 ↗(On Diff #6089)

But we are. In MS ABI we emit a note on the declaration of '~A()'. On itanium the note comes later, on the definition of 'class B'.

test/SemaCXX/implicit-virtual-member-functions.cpp
7–16 ↗(On Diff #6089)

In MS ABI we don't require the destructor for B here, so we expect no diagnostics. I've fixed the test to check that.

test/SemaCXX/undefined-internal.cpp
1–4 ↗(On Diff #6089)

We fail during codegen with "error: cannot mangle RTTI descriptors for type 'A' yet", and we need RTTI for the typeid which is used in the test.

This isn't a problem for the '-verify' line though. I'll update that.

test/SemaCXX/virtual-base-used.cpp
1 ↗(On Diff #6089)

In MS ABI we don't emit any diagnostics in this test. We should probably take a second look and verify that's correct behaviour.

I figured the test mostly seemed to be a regression test for the ICE in PR7800, so maybe we shouldn't run it in MS mode since none of the expectations apply.

test/SemaCXX/warn-weak-vtables.cpp
1 ↗(On Diff #6089)

Done.

test/SemaTemplate/virtual-member-functions.cpp
89–93 ↗(On Diff #6089)

Done.

hans updated this revision to Unknown Object (????).Dec 13 2013, 3:03 PM

Address comments and cut out the CodeGenCXX tests which were committed in r197281.

rsmith added inline comments.Dec 13 2013, 3:23 PM
test/CXX/class.access/p4.cpp
129 ↗(On Diff #6089)

So the access check in the callee serves no purpose other than to reject valid code? Can we just remove it?

test/CXX/drs/dr2xx.cpp
543 ↗(On Diff #6089)

I think the macro would be generally useful, and not just as a way of cleaning up these tests slightly. But that's something we can address separately.

test/CXX/special/class.dtor/p5-0x.cpp
98–104 ↗(On Diff #6089)

The expected-* diagnostics below say that they both are.

test/Sema/empty1.c
1 ↗(On Diff #6089)

Sure, a FIXME works for me.

test/SemaCXX/destructor.cpp
108–117 ↗(On Diff #6089)

Sure, but that diagnostic doesn't actually say why we're instantiating A<int>; we're missing the outermost level of the instantiation backtrace.

test/SemaCXX/implicit-virtual-member-functions.cpp
7–16 ↗(On Diff #6089)

That seems inconsistent: B (implicitly) has a virtual destructor, and operator delete lookup for it would fail, but we don't diagnose it.

test/SemaCXX/undefined-internal.cpp
1–4 ↗(On Diff #6089)

Please either XFAIL or add a FIXME; this test *should* pass without the -cxx-abi itanium.

test/SemaCXX/virtual-base-used.cpp
1 ↗(On Diff #6089)

This looks like the same root cause as implicit-virtual-member-functions.cpp -- we don't trigger vtable emission, so we don't implicitly define the destructor. In both that file and this one, you could get more consistent behavior in the MS ABI with something like this:

  void D::foo() {}
  D d;
#if MSABI
  // expected-note@-2 {{implicit destructor for 'B' first required here}}
#else
  // expected-note@-5 {{implicit destructor for 'B' first required here}}
#endif
hans added a comment.Dec 17 2013, 1:59 PM

Thanks for the review! New patch coming up.

test/CXX/class.access/p4.cpp
129 ↗(On Diff #6089)

I've sent out a patch for this: http://llvm-reviews.chandlerc.com/D2409

test/Sema/empty1.c
1 ↗(On Diff #6089)

OK, added a FIXME.

test/SemaCXX/destructor.cpp
108–117 ↗(On Diff #6089)

I think something like this is happening (and correct me if I'm wrong, because I'm not familiar with the instantiation process):

When we declare B, we require the complete class of A, so we instantiate it (Sema::InstantiateClass), and then we do Sema::CheckCompletedCXXClass. In MS ABI mode, this means that we call CheckDestructor() (see r182270), which will mark the destructor as referenced, and is added to PendingInstantiations.

Later, we process the destructor in PendingInstantiations. But now we don't have anything on the ActiveInstantiations list, so we fail to emit a note about why we're instantiating it.

I don't see a straightforward way of fixing this, and since we plan on moving these checks to some later time (vtable emission or something), would it be alright to just put a FIXME here in the meantime?

test/SemaCXX/implicit-virtual-member-functions.cpp
7–16 ↗(On Diff #6089)

I've added "new D" calls to trigger vtable emission, I think it worked out pretty well in this test.

test/SemaCXX/undefined-internal.cpp
1–4 ↗(On Diff #6089)

I've added a FIXME.

test/SemaCXX/virtual-base-used.cpp
1 ↗(On Diff #6089)

This worked great in implicit-virtual-member-functions.cpp, but in this test it gets a bit more hairy as it we start getting a bunch of notes about requiring implicit default constructors etc. I don't know if it's ok, if there's a cleaner way, or if it's not worth the mess to run the test in ms mode.

hans updated this revision to Unknown Object (????).Dec 17 2013, 2:00 PM

Address comments.

hans updated this revision to Unknown Object (????).Dec 18 2013, 5:13 PM

Tiny update: no need to change test/CXX/special/class.dtor/p5-0x.cpp anymore.

hans added a comment.Dec 18 2013, 5:14 PM

I'd really like to get this in, so trying to summarize where we are on the tests. I think these are the three tests that are still under discussion:

test/CXX/class.access/p4.cpp
The "Elide dtor access checks for pass-by-val objects in callees" patch at http://llvm-reviews.chandlerc.com/D2409 addresses this. Can we decide to make the expectations in this test depend on the outcome of that code review?

test/SemaCXX/destructor.cpp
The missing outermost level of template instantiation backtrace. I've commented on this.

test/SemaCXX/virtual-base-used.cpp
Adding "new D" to trigger vtable emission got pretty hairy here, so maybe we don't want to do that.

Richard: I'm interested to hear your thoughts.

  • Hans
hans updated this revision to Unknown Object (????).Jan 9 2014, 3:28 PM

Back from the holidays, let's see if we can get this landed :)

I've rebased the patch. The only necessary change was to force itanium mode for CodeGenCXX/instr-profile.cpp (it has expectations on itanium-mangled names, and uses exceptions/RTTI which the MS mode cannot handle).

IIRC, this is where we left last year:

test/CXX/class.access/p4.cpp - Dtor access checks for pass-by-value objects in callee. I think David's comment on http://llvm-reviews.chandlerc.com/D2409 about this being SFINAE-detectable means we need to follow visual studio here.

test/SemaCXX/destructor.cpp - Missing outermost level of template instantiation backtrace, I've commented on this at http://llvm-reviews.chandlerc.com/D2401?id=6089#inline-12902

test/SemaCXX/virtual-base-used.cpp - Adding "new D" to trigger vtable emission got pretty hairy here, so maybe we don't want to do that.

Please take a look.

rsmith added a comment.Jan 9 2014, 4:31 PM

LGTM

I'd still be interested in us pursuing two things:

  1. Don't access-check the dtor call for a by-val parameter (D2409), and
  2. Don't perform operator delete lookup when we see a virtual dtor declaration, instead perform it when we see a dtor definition or a use of the vtable.

But those don't have to happen before this lands.

test/SemaCXX/virtual-base-used.cpp
1–2 ↗(On Diff #6401)

Please add a comment somewhere in this test explaining that we need to do different things for MSVC versus Itanium because MSVC doesn't have key functions.

test/SemaCXX/warn-weak-vtables.cpp
2 ↗(On Diff #6401)

Maybe -Werror here? Otherwise I'm not sure what the -Wno-weak-* are for.

test/SemaTemplate/instantiate-exception-spec-cxx11.cpp
1 ↗(On Diff #6401)

Please add a comment saying that this test is Itanium-specific because it depends on key functions in namespace PR12763 (maybe as a FIXME).

rsmith accepted this revision.Jan 9 2014, 4:32 PM
hans closed this revision.Jan 13 2014, 11:54 AM

Closed by commit rL199130 (authored by @hans).