This is an archive of the discontinued LLVM Phabricator instance.

Allow writing calling convention attributes on function types
ClosedPublic

Authored by aaron.ballman on Feb 25 2018, 12:29 PM.

Details

Reviewers
rsmith
Summary

Calling convention attributes notionally appertain to the function type -- they modify the mangling of the function, change the behavior of assignment operations, etc. However, they're not currently allowed to be written in the type position within a function declaration. This patch allows the calling convention attributes to be written in the type position as well as the declaration position. This also adds a new diagnostic to diagnose this as being incompatible with GCC despite the attribute being in the gnu namespace. I do not think this incompatibility is sufficient to warrant adding a clang namespace for the attributes, but that is another option available to us if there is concern over the incompatibility.

Eventually, I would like to extend this to other attributes that really should be type attributes, such as enable_if. The calling convention attributes just happen to be the lowest hanging fruit.

Diff Detail

Event Timeline

aaron.ballman created this revision.Feb 25 2018, 12:29 PM
rsmith accepted this revision.May 2 2018, 3:12 PM

I'm really sad about this; C++11 attributes were supposed to fix the undisciplined "do what I mean" behavior of GNU attributes. But you're right, these really are type attributes, and really should be permitted to appertain to types. That we permit these to appertain to function declarations is the mistake, but it's a mistake we need to make to match GCC, so while I'm sad about it, I think this patch is the right thing.

This revision is now accepted and ready to land.May 2 2018, 3:12 PM
aaron.ballman closed this revision.May 3 2018, 8:37 AM

I'm really sad about this; C++11 attributes were supposed to fix the undisciplined "do what I mean" behavior of GNU attributes. But you're right, these really are type attributes, and really should be permitted to appertain to types. That we permit these to appertain to function declarations is the mistake, but it's a mistake we need to make to match GCC, so while I'm sad about it, I think this patch is the right thing.

Yeah, this situation doesn't make me overly happy but I think it's the best way for us to move forward. Hopefully, after enough time has passed, we can consider deprecating writing these attributes on declarations with the eventual goal of disallowing it.

Committed in r331459.