From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1105) id C2F32385701B; Fri, 9 Sep 2022 14:12:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C2F32385701B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1662732723; bh=pklYlMy8dZk7+U5EDy73jwt2+LldJpQmFoRsKRKd8jI=; h=From:To:Subject:Date:From; b=R95dt2Hz63h2j6j5GtcF81sH//ZjRam0z5cObX+b8LRmIDmgF3JpitW5DqdMs/cuA qBgdOVDkkRhC+cZTzRctJTaGYfB623Cijn0C3bML7sanQFj57iFQWg7pxH5x+OVTKQ ArEwaYGQngleUjymk2KydfzaLuxUF3UD+T/FvXJ8= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Joseph Myers To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-2563] stddef.h: Add C2x unreachable macro X-Act-Checkin: gcc X-Git-Author: Joseph Myers X-Git-Refname: refs/heads/master X-Git-Oldrev: e230f11e9784eefed316df7dbc5df6ac999841b2 X-Git-Newrev: a1a53dc7d87969d230e9ca51fcab59f3a72e5f6e Message-Id: <20220909141203.C2F32385701B@sourceware.org> Date: Fri, 9 Sep 2022 14:12:03 +0000 (GMT) List-Id: https://gcc.gnu.org/g:a1a53dc7d87969d230e9ca51fcab59f3a72e5f6e commit r13-2563-ga1a53dc7d87969d230e9ca51fcab59f3a72e5f6e Author: Joseph Myers Date: Fri Sep 9 14:11:21 2022 +0000 stddef.h: Add C2x unreachable macro C2x adds a macro unreachable to stddef.h, with the same semantics as __builtin_unreachable. Define this macro accordingly. Bootstrapped with no regressions for x86_64-pc-linux-gnu. gcc/ * ginclude/stddef.h [__STDC_VERSION__ > 201710L] (unreachable): New macro. gcc/testsuite/ * gcc.dg/c11-unreachable-1.c, gcc.dg/c2x-unreachable-1.c: New tests. Diff: --- gcc/ginclude/stddef.h | 4 ++++ gcc/testsuite/gcc.dg/c11-unreachable-1.c | 9 +++++++++ gcc/testsuite/gcc.dg/c2x-unreachable-1.c | 29 +++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/gcc/ginclude/stddef.h b/gcc/ginclude/stddef.h index 315ff786694..3d29213e8f1 100644 --- a/gcc/ginclude/stddef.h +++ b/gcc/ginclude/stddef.h @@ -451,6 +451,10 @@ typedef struct { #endif #endif /* C23. */ +#if defined __STDC_VERSION__ && __STDC_VERSION__ > 201710L +#define unreachable() (__builtin_unreachable ()) +#endif + #endif /* _STDDEF_H was defined this time */ #endif /* !_STDDEF_H && !_STDDEF_H_ && !_ANSI_STDDEF_H && !__STDDEF_H__ diff --git a/gcc/testsuite/gcc.dg/c11-unreachable-1.c b/gcc/testsuite/gcc.dg/c11-unreachable-1.c new file mode 100644 index 00000000000..28e48392ed1 --- /dev/null +++ b/gcc/testsuite/gcc.dg/c11-unreachable-1.c @@ -0,0 +1,9 @@ +/* Test unreachable not defined in for C11. */ +/* { dg-do preprocess } */ +/* { dg-options "-std=c11 -pedantic-errors" } */ + +#include + +#ifdef unreachable +#error "unreachable defined" +#endif diff --git a/gcc/testsuite/gcc.dg/c2x-unreachable-1.c b/gcc/testsuite/gcc.dg/c2x-unreachable-1.c new file mode 100644 index 00000000000..468f1f87ebb --- /dev/null +++ b/gcc/testsuite/gcc.dg/c2x-unreachable-1.c @@ -0,0 +1,29 @@ +/* Test unreachable in for C2x. */ +/* { dg-do run } */ +/* { dg-options "-std=c2x -pedantic-errors -O2" } */ + +#include + +#ifndef unreachable +#error "unreachable not defined" +#endif + +extern void *p; +extern __typeof__ (unreachable ()) *p; + +volatile int x = 1; + +extern void not_defined (void); + +extern void exit (int); + +int +main () +{ + if (x == 2) + { + unreachable (); + not_defined (); + } + exit (0); +}