[cfe-dev] Missing NoReturnAttr in the AST?

Richard Smith via cfe-dev cfe-dev at lists.llvm.org
Fri Oct 4 11:04:37 PDT 2019


On Fri, 4 Oct 2019 at 07:18, Hubert Tong via cfe-dev <cfe-dev at lists.llvm.org>
wrote:

> On Fri, Oct 4, 2019 at 6:12 AM Gábor Márton via cfe-dev <
> cfe-dev at lists.llvm.org> wrote:
>
>> I've found that the GCC __attribute__((noreturn)) is part of the type,
>> and not parsed into a separate AST node like the C++11 [[noreturn]] or the
>> GNU __attribute__((analyzer_noreturn)).
>> To query the GCC __attribute__((noreturn)) we can use
>> FunctionType::getNoReturnAttr().
>>
>> Why do we have these differences, with these attributes, why was the GCC
>> noreturn uplifted into the Type?
>>
> Because it applies to function types:
> typedef void (*fptype)(void) __attribute__((__noreturn__));
> int f(int x, fptype fp) {
>   if (x) return 42;
>   fp();
> }
>

Yes. We are missing the AttributedType node in the AST in this case, though:

typedef void (*fptype)(void) __attribute__((__noreturn__));
#pragma clang __debug dump fptype;

gives:

TypedefDecl 0x55822b34e048 <<source>:1:1, col:28> col:16 fptype 'void (*)()
__attribute__((noreturn))'
`-PointerType 0x55822b34dff0 'void (*)() __attribute__((noreturn))'
  `-ParenType 0x55822b34df90 'void () __attribute__((noreturn))' sugar
    `-FunctionProtoType 0x55822b34df60 'void () __attribute__((noreturn))'
noreturn cdecl
      `-BuiltinType 0x55822b30b7e0 'void'

Consider for comparison

typedef int *__attribute__((address_space(3))) *p;
#pragma clang __debug dump p;

which gives:

TypedefDecl 0x5619f0bc2f90 <<source>:1:1, col:49> col:49 p 'int
*__attribute__((address_space(3))) *'
`-PointerType 0x5619f0bc2f40 'int *__attribute__((address_space(3))) *'
  `-AttributedType 0x5619f0bc2ee0 'int *__attribute__((address_space(3)))'
sugar
    |-PointerType 0x5619f0bc2e70 'int *'
    | `-BuiltinType 0x5619f0b80880 'int'
    `-QualType 0x5619f0bc2ec8 'int *__attribute__((address_space(3)))'
__attribute__((address_space(3)))
      `-PointerType 0x5619f0bc2e70 'int *'
        `-BuiltinType 0x5619f0b80880 'int'

(The reason for this is that support for noreturn long predates
AttributedType and we forgot to update the relevant code to produce the
AttributedType wrapper.)


>
>> Thanks,
>> Gabor
>>
>> On Fri, Oct 4, 2019 at 11:40 AM Gábor Márton <martongabesz at gmail.com>
>> wrote:
>>
>>> Hi,
>>>
>>> Having a source file (/tmp/attr.cpp)
>>>   void f() __attribute__((analyzer_noreturn));
>>>   void g() __attribute__((noreturn));
>>>   [[gnu::noreturn]] void h(void);
>>> Generates the following AST, when clang -cc1 -ast-dump /tmp/attr.cpp is
>>> used
>>>   |-FunctionDecl 0x18a5178 </tmp/attr.cpp:1:1, col:43> col:6 f 'void ()'
>>>   | `-AnalyzerNoReturnAttr 0x18a5218 <col:25>
>>>   |-FunctionDecl 0x18a5308 <line:2:1, col:34> col:6 g 'void ()
>>> __attribute__((noreturn))'
>>>   `-FunctionDecl 0x18a5440 <line:3:19, col:30> col:24 h 'void ()
>>> __attribute__((noreturn))'
>>>
>>> I.e. the NoReturnAttr node is missing. This is very confusing, when
>>> compared to the AnalyzerNoReturnAttr, which is there.
>>> The only difference in Attr.td is that noreturn has GCC spelling, while
>>> analyzer_noreturn has GNU spelling.
>>> What am I missing to have a NoReturnAttr node? Do I have to specify a
>>> special extra flag for CC1 to enable GCC attributes?
>>>
>>> Thanks,
>>> Gabor
>>>
>> _______________________________________________
>> cfe-dev mailing list
>> cfe-dev at lists.llvm.org
>> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20191004/6898fa28/attachment.html>


More information about the cfe-dev mailing list