This is an archive of the discontinued LLVM Phabricator instance.

Sema: Add semantic analysis for the C++ ABI stability attributes and whitelist.
Needs ReviewPublic

Authored by pcc on Mar 4 2016, 12:04 PM.

Diff Detail

Event Timeline

pcc updated this revision to Diff 49842.Mar 4 2016, 12:04 PM
pcc retitled this revision from to Sema: Add semantic analysis for the C++ ABI stability attributes and whitelist..
pcc updated this object.
pcc added a subscriber: cfe-commits.
aaron.ballman added a subscriber: aaron.ballman.

I may have more comments when I catch up on email next week. Just a drive-by as I added myself as reviewer.

include/clang/Basic/Attr.td
1582

No new undocumented attributes, please. Same below.

pcc added inline comments.Mar 4 2016, 12:16 PM
include/clang/Basic/Attr.td
1582

Yes, sorry, forgot to go back and add documentation for these attributes. Will do. (Reckon it's not worth documenting the feature itself until it actually does something.)

pcc updated this revision to Diff 49843.Mar 4 2016, 12:43 PM
  • Add attribute docs
aaron.ballman edited edge metadata.Mar 8 2016, 10:31 AM

Missing some attribute-related tests like attaching the attribute to something other than a record, or passing arguments to the attribute.

include/clang/Basic/DiagnosticSemaKinds.td
8376

It would be good to combine these into one Note using %select.

8380

Same for these.

8389

Should this also be a %select, or can you really add either attribute to silence the warning?

lib/Sema/SemaDeclCXX.cpp
4896

Since the attributes do nothing for a non-dynamic class, should the user get a warning if the place the attribute on one (so they know it does nothing)?

pcc updated this revision to Diff 50667.Mar 14 2016, 3:45 PM
pcc marked 3 inline comments as done.
pcc edited edge metadata.
  • Address review comments
pcc updated this revision to Diff 50668.Mar 14 2016, 3:47 PM
  • Add a test for passing arguments to the attribute
pcc added a comment.Mar 14 2016, 3:47 PM

Missing some attribute-related tests like attaching the attribute to something other than a record, or passing arguments to the attribute.

Added.

include/clang/Basic/DiagnosticSemaKinds.td
8389

The latter. I gave this a better name to make things clear.

lib/Sema/SemaDeclCXX.cpp
4896

I suppose so; done.

pcc updated this revision to Diff 50672.Mar 14 2016, 4:20 PM
  • Claim -funstable-c++-abi-classes= flags

Attribute side of things looks good, but I leave it to others to decide if the ABI functionality makes sense (it does to me, but I'm no ABI expert).

mehdi_amini edited edge metadata.Mar 16 2016, 8:30 AM

LGTM, but I'm not a clang expert, so if Richard or someone else could double-check?

lib/Sema/SemaDeclCXX.cpp
4999

Isn't this correct by the loop which starts with DC = InnermostExternalDC?

mehdi_amini added inline comments.Mar 16 2016, 8:50 AM
lib/Sema/SemaDeclCXX.cpp
4999

s/correct/already covered/

pcc added inline comments.Mar 16 2016, 2:59 PM
lib/Sema/SemaDeclCXX.cpp
4999

That loop checks for glob contexts (contexts ending in ** in the ABI list), which have different semantics to regular contexts (ending in *).

mehdi_amini added inline comments.Mar 16 2016, 3:04 PM
lib/Sema/SemaDeclCXX.cpp
4999

Oh, I misread UnstableABIGlobContexts for UnstableABIContexts...

rsmith added inline comments.Mar 18 2016, 7:47 AM
include/clang/Basic/DiagnosticSemaKinds.td
8380

How valuable is it to warn on this? It seems like we may want unstable_abi to affect other things than virtual functions in future (for instance, we may want to apply the ARM ABI "return this from constructors" change to classes with unstable ABI, fix some subtle problems in the class layout algorithm, pass certain trivially-copyable structs in registers even though they're not POD for the purpose of layout, ...). If the design intent is that this only affects the virtual call portion of the ABI, then I think it has the wrong name.

(If someone asks for the unstable ABI for the class, and it happens that the unstable ABI is the same as the stable one, I don't think that warrants a warning.)

lib/Sema/SemaDeclCXX.cpp
4891

Can we exit early if no unstable class ABI flags were passed?

4935–4943

Should you also diagnose conflicts with other struct ABI attributes like ms_struct?

5018–5019

-Weverything users will not like this.

pcc updated this revision to Diff 51052.Mar 18 2016, 12:01 PM
pcc edited edge metadata.
  • Make -Wunused-stability-attr a non-default flag
include/clang/Basic/DiagnosticSemaKinds.td
8380

I agree that the attribute should permit other struct ABI changes. I also agree that we shouldn't warn by default. We've traditionally warned when an attribute has no effect, but that's probably the wrong decision in this case. I've made this a non-default warning.

lib/Sema/SemaDeclCXX.cpp
4891

We may need to inherit an ABI from a base, even if no flags were passed.

4935–4943

I'd expect those attributes to be orthogonal, e.g. ms_struct + unstable_abi would give you whatever just unstable_abi would give you when targeting Windows.

5018–5019

That's unfortunate, but I think the alternative of creating a category of warnings that -Weverything does not warn on would be worse. My understanding is that as a user-facing flag -Weverything is mostly intended for manual discovery of warnings that Clang produces; as part of that manual process, users can easily add the -Wno-c++-stable-abi flag.

rjmccall added inline comments.Mar 18 2016, 1:08 PM
lib/Sema/SemaDeclCXX.cpp
4935–4943

No, ms_struct is a request for a specific ABI; this would be a conflict.

pcc added inline comments.Mar 18 2016, 1:27 PM
lib/Sema/SemaDeclCXX.cpp
4935–4943

Fair point. I think we can handle this by making ms_struct imply stable_abi in the same way that uuid would imply stable_abi. Then there would be a conflict between ms_struct and unstable_abi, and we would infer the correct ABI in implied namespaces.

Are there any other attributes like that? I could only find vecreturn and novtable.

rjmccall added inline comments.Mar 18 2016, 1:37 PM
lib/Sema/SemaDeclCXX.cpp
4935–4943

I can't think of anything else that's a conflict. vecreturn affects a different aspect of the ABI. novtable is advisory and orthogonal. Alignment/packed attributes should still be honored under an unstable ABI.

pcc updated this revision to Diff 51067.Mar 18 2016, 2:11 PM
  • Attributes uuid and ms_struct imply stable_abi. Also improve docs and diagnostics for non-dynamic classes
lib/Sema/SemaDeclCXX.cpp
4935–4943

Thanks, I've added conflicts for ms_struct and uuid.

espindola edited reviewers, added: espindola; removed: rafael.Mar 15 2018, 10:54 AM

I think this is okay. We can review further if we see other problems.