Puneetha K via llvm-dev
2017-Jun-09 07:21 UTC
[llvm-dev] Qualifiers not being discarded for atomic types while compiling with clang
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 -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170609/a9d55f95/attachment.html>
Joerg Sonnenberger via llvm-dev
2017-Jun-09 13:36 UTC
[llvm-dev] Qualifiers not being discarded for atomic types while compiling with clang
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
Richard Smith via llvm-dev
2017-Jun-09 22:17 UTC
[llvm-dev] Qualifiers not being discarded for atomic types while compiling with clang
On 9 June 2017 at 00:21, Puneetha K via llvm-dev <llvm-dev at lists.llvm.org> 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. >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170609/e3bd1477/attachment.html>