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

Atomic qualification is not removed from cast expressions, function calls, and enumeration underlying types #96717

Open
Halalaluyafail3 opened this issue Jun 26, 2024 · 2 comments
Labels
c23 clang:frontend Language frontend issues, e.g. anything involving "Sema" confirmed Verified by a second party

Comments

@Halalaluyafail3
Copy link

C23 includes the following text that removes atomic qualification in the following contexts:

Preceding an expression by a parenthesized type name converts the value of the expression to the
unqualified, non-atomic version of the named type. This construction is called a cast.

Section 6.5.5 "Cast operators" Paragraph 6 N3220

If an enum type specifier is present, then the longest possible sequence of tokens that can be
interpreted as a specifier qualifier list is interpreted as part of the enum type specifier. It shall name
an integer type that is neither an enumeration nor a bit-precise integer type. The underlying type of
the enumeration is the unqualified, non-atomic version of the type specified by the type specifiers in
the specifier qualifier list.

Section 6.7.3.3 "Enumeration specifiers" Paragraph 5 N3220

If, in the declaration "T D1", D1 has the form

D ( parameter-type-list opt ) attribute-specifier-sequence opt

and the type specified for ident in the declaration "T D" is "derived-declarator-type-list T", then the
type specified for ident is "derived-declarator-type-list function returning the unqualified, non-atomic
version of T". The optional attribute specifier sequence appertains to the function type.

Section 6.7.7.4 "Function declarators" Paragraph 4 N3220

Clang does not remove atomic qualifiers in these cases, here are some examples:

puts(_Generic((_Atomic int)0,int:"A",_Atomic int:"B"));

This should output A, Clang outputs B.

enum E:_Atomic int;

This should be valid, Clang rejects it.

puts(_Generic(((_Atomic int(*)())0)(),int:"A",_Atomic int:"B"));

This should output A, Clang outputs B.

The case described in #96713 also has the same problem (along with the other qualifiers). Clang does remove atomic qualification in lvalue conversion since this was included in C17. GCC removes atomic qualification in all cases even in C17 mode, except for directly removing them from the function return type which is instead done when calling the function. Clang also fails to remove any qualifiers from function return types, which was reported before #39494.

@EugeneZelenko EugeneZelenko added c23 clang:frontend Language frontend issues, e.g. anything involving "Sema" and removed new issue labels Jun 26, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Jun 26, 2024

@llvm/issue-subscribers-clang-frontend

Author: None (Halalaluyafail3)

C23 includes the following text that removes atomic qualification in the following contexts: >Preceding an expression by a parenthesized type name converts the value of the expression to the unqualified, non-atomic version of the named type. This construction is called a cast.

Section 6.5.5 "Cast operators" Paragraph 6 N3220
>If an enum type specifier is present, then the longest possible sequence of tokens that can be
interpreted as a specifier qualifier list is interpreted as part of the enum type specifier. It shall name
an integer type that is neither an enumeration nor a bit-precise integer type. The underlying type of
the enumeration is the unqualified, non-atomic version of the type specified by the type specifiers in
the specifier qualifier list.

Section 6.7.3.3 "Enumeration specifiers" Paragraph 5 N3220
>If, in the declaration "T D1", D1 has the form
>
>D ( parameter-type-list opt ) attribute-specifier-sequence opt
>
>and the type specified for ident in the declaration "T D" is "derived-declarator-type-list T", then the
type specified for ident is "derived-declarator-type-list function returning the unqualified, non-atomic
version of T". The optional attribute specifier sequence appertains to the function type.

Section 6.7.7.4 "Function declarators" Paragraph 4 N3220

Clang does not remove atomic qualifiers in these cases, here are some examples:

puts(_Generic((_Atomic int)0,int:"A",_Atomic int:"B"));

This should output A, Clang outputs B.

enum E:_Atomic int;

This should be valid, Clang rejects it.

puts(_Generic(((_Atomic int(*)())0)(),int:"A",_Atomic int:"B"));

This should output A, Clang outputs B.

The case described in #96713 also has the same problem (along with the other qualifiers). Clang does remove atomic qualification in lvalue conversion since this was included in C17. GCC removes atomic qualification in all cases even in C17 mode, except for directly removing them from the function return type which is instead done when calling the function. Clang also fails to remove any qualifiers from function return types, which was reported before #39494.

@shafik
Copy link
Collaborator

shafik commented Jun 26, 2024

CC @AaronBallman

@AaronBallman AaronBallman added the confirmed Verified by a second party label Jun 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c23 clang:frontend Language frontend issues, e.g. anything involving "Sema" confirmed Verified by a second party
Projects
None yet
Development

No branches or pull requests

5 participants