c: C2x noreturn attribute
authorJoseph Myers <joseph@codesourcery.com>
Thu, 29 Sep 2022 22:59:22 +0000 (22:59 +0000)
committerJoseph Myers <joseph@codesourcery.com>
Thu, 29 Sep 2022 22:59:22 +0000 (22:59 +0000)
commit3a3516bc4a0a0307cd48dce044a497e95816c8f5
treedc36354d8478aea7275978397c3f4634444c8358
parent7ea258a13a115e9e73d60f59369d16892ed07435
c: C2x noreturn attribute

C2x adds a standard [[noreturn]] attribute (which can also be spelt
[[_Noreturn]] for use with <stdnoreturn.h>), so allowing non-returning
functions to be declared in a manner compatible with C++; the
_Noreturn function specifier remains available but is marked
obsolescent.

Implement this attribute.  It's more restricted than GNU
__attribute__ ((noreturn)) - that allows function pointers but using
the standard attribute on a function pointer is a constraint
violation.  Thus, the attribute gets its own handler that checks for a
FUNCTION_DECL before calling the handler for the GNU attribute.  Tests
for the attribute are based on those for C11 _Noreturn and for other
C2x attributes.

Bootstrapped with no regressions for x86_64-pc-linux-gnu.

gcc/c-family/
* c-lex.cc (c_common_has_attribute): Handle noreturn attribute for
C.

gcc/c/
* c-decl.cc (handle_std_noreturn_attribute): New function.
(std_attribute_table): Add _Noreturn and noreturn.

gcc/testsuite/
* gcc.dg/c2x-attr-noreturn-1.c, gcc.dg/c2x-attr-noreturn-2.c,
gcc.dg/c2x-attr-noreturn-3.c: New tests.
* gcc.dg/c2x-has-c-attribute-2.c: Also test __has_c_attribute for
noreturn attribute.
gcc/c-family/c-lex.cc
gcc/c/c-decl.cc
gcc/testsuite/gcc.dg/c2x-attr-noreturn-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/c2x-attr-noreturn-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/c2x-attr-noreturn-3.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/c2x-has-c-attribute-2.c