Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GNU attributes after declspecs don't parse #24933

Closed
zmodem opened this issue Aug 24, 2015 · 10 comments
Closed

GNU attributes after declspecs don't parse #24933

zmodem opened this issue Aug 24, 2015 · 10 comments
Labels
bugzilla Issues migrated from bugzilla clang:frontend Language frontend issues, e.g. anything involving "Sema"

Comments

@zmodem
Copy link
Collaborator

zmodem commented Aug 24, 2015

Bugzilla Link 24559
Resolution FIXED
Resolved on Jan 29, 2021 05:19
Version trunk
OS Linux
CC @AaronBallman,@majnemer,@MaskRay,@nico,@rnk

Extended Description

With clang-cl, this parses fine:

struct attribute((lockable)) __declspec(dllexport) S { };

while this does not:

struct __declspec(dllexport) attribute((lockable)) T { };

/tmp/a.cc(3,1) : error: declaration of anonymous struct must be a definition
struct __declspec(dllexport) attribute((lockable)) T { };
^
/tmp/a.cc(3,1) : warning: declaration does not declare anything
[-Wmissing-declarations]
struct __declspec(dllexport) attribute((lockable)) T { };
^

It would be great if we could allow both orderings, or at least provide a better error message.

@AaronBallman
Copy link
Collaborator

With clang-cl, this parses fine:

struct attribute((lockable)) __declspec(dllexport) S { };

while this does not:

struct __declspec(dllexport) attribute((lockable)) T { };

/tmp/a.cc(3,1) : error: declaration of anonymous struct must be a definition
struct __declspec(dllexport) attribute((lockable)) T { };
^
/tmp/a.cc(3,1) : warning: declaration does not declare anything
[-Wmissing-declarations]
struct __declspec(dllexport) attribute((lockable)) T { };
^

Are you running into this with a particular library, or is this an issue you happened upon?

It would be great if we could allow both orderings, or at least provide a
better error message.

From a user perspective, I think it definitely makes sense to allow arbitrary orderings of attributes (where applicable).

@zmodem
Copy link
Collaborator Author

zmodem commented Aug 24, 2015

With clang-cl, this parses fine:

struct attribute((lockable)) __declspec(dllexport) S { };

while this does not:

struct __declspec(dllexport) attribute((lockable)) T { };

/tmp/a.cc(3,1) : error: declaration of anonymous struct must be a definition
struct __declspec(dllexport) attribute((lockable)) T { };
^
/tmp/a.cc(3,1) : warning: declaration does not declare anything
[-Wmissing-declarations]
struct __declspec(dllexport) attribute((lockable)) T { };
^

Are you running into this with a particular library, or is this an issue you
happened upon?

It just came up in Chromium. I'll try to work around by reordering for now.

@AaronBallman
Copy link
Collaborator

Are you running into this with a particular library, or is this an issue you
happened upon?

It just came up in Chromium. I'll try to work around by reordering for now.

I think that's a good solution for the time being. At some point, it might be nice to add a ParseAttributes(mask)-like function that allows for eldritch horrors like:

struct attribute((lockable)) [[foo]] __declspec(dllexport) attribute((bar)) S {};

The function would basically parse all attributes that meet the mask requirements, instead of requiring explicit calls to parse each attribute spelling. I'm not certain how feasible this idea is in practice just yet, though.

@AaronBallman
Copy link
Collaborator

I have a patch in progress that fixes this particular issue, but there's a deeper underlying problem with attribute parsing.

[[noreturn]] attribute((cdecl)) __declspec(dllexport) void f();

In this case, the [[noreturn]] is parsed as part of the top-level declaration, while the GNU and declspec attributes are parsed as part of the declaration specifier, and everything is accepted.

attribute((cdecl)) [[noreturn]] __declspec(dllexport) void f();

In this case, nothing is parsed as part of the top-level declaration, and everything is parsed as part of the declaration specifier. However, the C++ attribute is prohibited from appearing on a declaration specifier and so is diagnosed.

I think ParseDeclarationSpecifiers() needs to accept a ParsedAttributesWithRange object representing the top-level declaration attributes, and the parser needs to attach the C++ attributes to it up until we the first non-attribute token is found. But I'm not 100% certain that's the right approach.

I will explore further, and propose a patch to the lists to at least see if we all agree on the direction I've taken.

@AaronBallman
Copy link
Collaborator

*** Bug llvm/llvm-bugzilla-archive#24925 has been marked as a duplicate of this bug. ***

@nico
Copy link
Contributor

nico commented Sep 24, 2015

If it's any easier to only handle the __declspec attribute case at first, it might be worth doing that first. Those are a lot more common than C++11 attributes in practice.

If it's easier to improve the diagnostic than accepting either ordering, that would also be useful.

The current experience for getting this wrong is pretty bad: https://codereview.chromium.org/1363363002/ So if there was some way to make it less bad sooner, it might be worth doing that first and fixing it for real later :-)

@AaronBallman
Copy link
Collaborator

If it's any easier to only handle the __declspec attribute case at
first, it might be worth doing that first. Those are a lot more common than
C++11 attributes in practice.

If it's easier to improve the diagnostic than accepting either ordering,
that would also be useful.

The current experience for getting this wrong is pretty bad:
https://codereview.chromium.org/1363363002/ So if there was some way to make
it less bad sooner, it might be worth doing that first and fixing it for
real later :-)

I haven't had the chance to keep working on this patch (work has me on other priorities currently, so this is a spare time patch for me currently), but here's what I've gotten so far:

http://reviews.llvm.org/D12375

It's reasonably far along, I just need to finish up the comments Richard had on it. You're welcome to steal the patch from me and put on the finishing touches if you have time. Otherwise, I am hoping to get to it sooner rather than later, but that may be a month away.

@MaskRay
Copy link
Member

MaskRay commented Jan 15, 2021

This popped up again: https://reviews.llvm.org/D94788

@AaronBallman
Copy link
Collaborator

This should be resolved by 9f2c7ef

@AaronBallman
Copy link
Collaborator

mentioned in issue llvm/llvm-bugzilla-archive#24925

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla clang:frontend Language frontend issues, e.g. anything involving "Sema"
Projects
None yet
Development

No branches or pull requests

4 participants