[llvm-dev] Qualifiers not being discarded for atomic types while compiling with clang

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[llvm-dev] Qualifiers not being discarded for atomic types while compiling with clang

Gerolf Hoflehner via llvm-dev
Hi, 
I am trying to compile the following:

char * _Atomic restrict h;

When compiled with -std=c11,clang gives error:
         "restrict requires a pointer or reference (_Atomic(char*) is invalid)"

while gcc compiles it successfully.

Similarly, while trying to compile this

extern int i;
extern int _Atomic const ci;
extern __typeof(ci) i;

Clang gives error:

          "Redeclaration of 'i' with a different type: 'typeof (ci)' (aka 'typeof _Atomic(int)') vs 'int' "

while gcc compiles it successfully.

This seems to be because clang probably considers Atomic int differently than int while gcc disregards these.

Please suggest what should be the right behaviour in such cases.

Thanks in advance.
Best regards,
Puneetha

_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [llvm-dev] Qualifiers not being discarded for atomic types while compiling with clang

Gerolf Hoflehner via llvm-dev
On Fri, Jun 09, 2017 at 12:51:17PM +0530, Puneetha K via llvm-dev wrote:

> Similarly, while trying to compile this
>
> extern int i;
> extern int _Atomic const ci;
> extern __typeof(ci) i;
>
> Clang gives error:
>
>           "Redeclaration of 'i' with a different type: 'typeof (ci)' (aka
> 'typeof _Atomic(int)') vs 'int' "
>
> while gcc compiles it successfully.
>
> This seems to be because clang probably considers Atomic int differently
> than int while gcc disregards these.

This one is entirely legit. "_Atomic int" and "int" are very different
types, they may even have different alignment requirements.

Joerg
_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [llvm-dev] Qualifiers not being discarded for atomic types while compiling with clang

Gerolf Hoflehner via llvm-dev
In reply to this post by Gerolf Hoflehner via llvm-dev
On 9 June 2017 at 00:21, Puneetha K via llvm-dev <[hidden email]> wrote:
Hi, 
I am trying to compile the following:

char * _Atomic restrict h;

When compiled with -std=c11,clang gives error:
         "restrict requires a pointer or reference (_Atomic(char*) is invalid)"

C11 6.7.3/5: "If other qualifiers appear along with the _Atomic qualifier in a specifier-qualifier-list, the resulting type is the so-qualified atomic type."

So the type of 'h' is 'restrict _Atomic(char*)', not '_Atomic(char *restrict)'.

C11 6.7.3/2: "Types other than pointer types whose referenced type is an object type shall not be restrict-qualified."

The type being restrict-qualified is _Atomic(char*), which is an atomic type, not a pointer type, and thus this is ill-formed. (As it happens, '_Atomic(char *restrict)' would also be ill-formed, due to 6.7.2.4/3: "The type name in an atomic type specifier shall not refer to [...] a qualified type.")
 
while gcc compiles it successfully.

Similarly, while trying to compile this

extern int i;
extern int _Atomic const ci;
extern __typeof(ci) i;

Clang gives error:

          "Redeclaration of 'i' with a different type: 'typeof (ci)' (aka 'typeof _Atomic(int)') vs 'int' "

while gcc compiles it successfully.

This seems to be because clang probably considers Atomic int differently than int while gcc disregards these.

Please suggest what should be the right behaviour in such cases. 

_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Loading...