Skip to content

[clang] Support __typeof_unqual__ in all C modes #87392

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

Merged
merged 5 commits into from
Apr 3, 2024

Conversation

nathanchance
Copy link
Member

GCC has added __typeof_unqual__ to allow typeof_unqual to be used in all C modes (not just C23 and newer), similar to __typeof__ and typeof.

https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=607d9d50ee44163cee621cd991600acaf78c2fee

The Linux kernel would like to start using __typeof_unqual__ to strip type qualifiers such as address spaces from inputs to macros but cannot switch to C23 due to compiler version requirements.

Match GCC and allow __typeof_unqual__ in all C modes.

Closes: #76423
Link: https://lore.kernel.org/CAFULd4YG21NdF_qNVBGDtXO6xnaYFeRPvKicB=gpgUUqYE=4jw@mail.gmail.com/

PR notes/commentary:

  • I am not sure if there are any other tests I should add, I could not tell where __typeof__ was being used normally versus being explicitly tested aside from this test.
  • If there are any comments in the source code that should be updated, I am more than happy to do so, I just didn't want to be preemptive if they were not going to matter.

GCC has added __typeof_unqual__ to allow typeof_unqual to be used in all
C modes (not just C23 and newer), similar to __typeof__ and typeof.

https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=607d9d50ee44163cee621cd991600acaf78c2fee

The Linux kernel would like to start using __typeof_unqual__ to strip
type qualifiers such as address spaces from inputs to macros but cannot
switch to C23 due to compiler version requirements.

Match GCC and allow __typeof_unqual__ in all C modes.

Closes: llvm#76423
Link: https://lore.kernel.org/CAFULd4YG21NdF_qNVBGDtXO6xnaYFeRPvKicB=gpgUUqYE=4jw@mail.gmail.com/
Signed-off-by: Nathan Chancellor <[email protected]>
Copy link
Member

@nickdesaulniers nickdesaulniers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the patch!

Copy link
Collaborator

@AaronBallman AaronBallman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this; I think it's a very reasonable extension!

Allow __typeof_unqual__ in C++

Signed-off-by: Nathan Chancellor <[email protected]>
While in the area, add a test for __typeof, which should be handled in
the same manner as __typeof__.

Signed-off-by: Nathan Chancellor <[email protected]>
Copy link
Collaborator

@AaronBallman AaronBallman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, please add a C++-specific test when landing, since this is also going into C++.

Add a C++ test, as this will be exposed there as well

Signed-off-by: Nathan Chancellor <[email protected]>
@nathanchance
Copy link
Member Author

LGTM, please add a C++-specific test when landing, since this is also going into C++.

Does 4f9e79b seem reasonable on that front? Should I add a test that typeof_unqual is not accepted for C++? As far as I understand it, that is not supported by any compiler or the standard, correct?

@AaronBallman
Copy link
Collaborator

LGTM, please add a C++-specific test when landing, since this is also going into C++.

Does 4f9e79b seem reasonable on that front?

Yup, thank you!

Should I add a test that typeof_unqual is not accepted for C++? As far as I understand it, that is not supported by any compiler or the standard, correct?

I don't think there's a need for that (your patch doesn't change the status quo for typeof_unqual). That said, I will rarely complain about additional test coverage. ;-)

Include more coverage for new test

Signed-off-by: Nathan Chancellor <[email protected]>
@nathanchance
Copy link
Member Author

Should I add a test that typeof_unqual is not accepted for C++? As far as I understand it, that is not supported by any compiler or the standard, correct?

I don't think there's a need for that (your patch doesn't change the status quo for typeof_unqual). That said, I will rarely complain about additional test coverage. ;-)

Since it is a new test, I will add that coverage just to make it a little more obvious that is expected: c89b969

I'll merge this once presubmit is finished and no obvious regressions are noticed, thank you both for the quick feedback!

@nathanchance nathanchance merged commit cc308f6 into llvm:main Apr 3, 2024
@nathanchance
Copy link
Member Author

Would it make sense to apply this to release/18.x to get it into the hands of users quicker? It seems like it should be a safe change to apply. It sounds like GCC 14 will be the first one to support __typeof_unqual__, which should be released quite soon if I understand their release cycle correctly, so it makes sense that Clang would support it around the same time. No worries if it does not seem reasonable, just figured it was worth asking.

@nathanchance nathanchance deleted the __typeof_unqual__ branch April 3, 2024 16:53
@AaronBallman
Copy link
Collaborator

I agree that the feature is safe, but I don't think it qualifies because it's adding a new feature rather than fixing an issue. That said, if @tru or @tstellar think it's worth adding as release managers, I won't block it (because it really should be quite safe).

@tru
Copy link
Collaborator

tru commented Apr 20, 2024

The final decision is Toms, but I don't think it qualifies since we are so late in the current process and that 19 will start in just a few months.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

typeof_unqual outside C2X using alternate keyword
6 participants