Change the default language version for C compilation from -std=gnu17
to -std=gnu23. A few tests are updated to remove local definitions of
bool, true and false (where making such an unconditional test change
seemed to make more sense than changing the test conditionally earlier
or building it with -std=gnu17); most test issues were already
addressed in previous patches. In the case of
ctf-function-pointers-2.c, it was agreed in bug 117289 that it would
be OK to put -std=gnu17 in the test and leave more optimal BTF / CTF
output for this test as a potential future improvement.
Since the original test fixes, more such fixes have become necessary
and so are included in this patch. More noinline attributes are added
to simulate-thread tests where () meaning a prototype affected test
results, while gcc.dg/torture/pr117496-1.c (a test declaring a
function with () then calling it with arguments) gets -std=gnu17
added.
Bootstrapped with no regressions for x86_64-pc-linux-gnu.
NOTE: it's likely there are target-specific tests for non-x86 targets
that need updating as a result of this change. See commit
9fb5348e3021021e82d75e4ca4e6f8d51a34c24f ("testsuite: Prepare for
-std=gnu23 default") for examples of changes to prepare the testsuite
to work with a -std=gnu23 default. In most cases, adding
-Wno-old-style-definition (for warnings for old-style function
definitions) or -std=gnu17 (for other issues such as unprototyped
function declarations with ()) is appropriate, but watch out for cases
that indicate bugs with -std=gnu23 (in particular, any ICEs - there
was only the one nested function test where I had to fix an ICE on
x86_64).
gcc/
* doc/invoke.texi (-std=gnu17, -std=gnu23): Document -std=gnu23 as
default for C code.
gcc/c-family/
* c-opts.cc (c_common_init_options): Default to C23.
gcc/testsuite/
* c-c++-common/analyzer/asm-x86-dyndbg-2.c,
c-c++-common/analyzer/asm-x86-lp64-2.c,
c-c++-common/analyzer/attr-malloc-CVE-2019-19078-usb-leak.c,
c-c++-common/analyzer/coreutils-cksum-pr108664.c,
c-c++-common/analyzer/feasibility-3.c,
c-c++-common/analyzer/pr105783.c, c-c++-common/analyzer/sock-1.c,
c-c++-common/attributes-4.c, gcc.dg/Warray-bounds-78.c,
gcc.dg/analyzer/asm-x86-dyndbg-1.c: Do not define bool, true or
false.
* gcc.dg/debug/ctf/ctf-function-pointers-2.c: Use -std-gnu17.
* gcc.dg/gnu23-version-2.c: New test.
* gcc.dg/simulate-thread/atomic-load-int.c,
gcc.dg/simulate-thread/atomic-load-longlong.c,
gcc.dg/simulate-thread/atomic-load-short.c: Add more noinline
attributes.
* gcc.dg/torture/pr117496-1.c: Use -std=gnu17.
if (c_language == clk_c)
{
- /* The default for C is gnu17. */
- set_std_c17 (false /* ISO */);
+ /* The default for C is gnu23. */
+ set_std_c23 (false /* ISO */);
/* If preprocessing assembly language, accept any of the C-family
front end options since the driver may pass them through. */
@item gnu17
@itemx gnu18
-GNU dialect of ISO C17. This is the default for C code.
+GNU dialect of ISO C17.
@item gnu23
@itemx gnu2x
-GNU dialect of ISO C23. The name @samp{gnu2x} is deprecated.
+GNU dialect of ISO C23. This is the default for C code. The name
+@samp{gnu2x} is deprecated.
@item gnu2y
The next version of the ISO C standard, still under development, plus
/* Adapted from various files in the Linux kernel, all of which have: */
/* SPDX-License-Identifier: GPL-2.0 */
-#ifndef __cplusplus
- typedef _Bool bool;
- #define true 1
- #define false 0
-#endif
-
typedef struct {} atomic_t;
/* Adapted from include/linux/compiler_attributes.h */
/* Adapted from Linux x86: page_ref_dec_and_test.c (GPL-2.0). */
-#ifndef __cplusplus
- typedef _Bool bool;
-#endif
-
typedef struct {
int counter;
} atomic_t;
typedef unsigned char u8;
typedef unsigned short u16;
-#ifndef __cplusplus
- typedef _Bool bool;
-#endif
-
#define ENOMEM 12
#define EINVAL 22
typedef unsigned long int __uintmax_t;
typedef struct _IO_FILE FILE;
-#ifndef __cplusplus
- typedef _Bool bool;
-#endif
-
extern size_t
fread_unlocked(void* __restrict __ptr,
size_t __size,
/* Types. */
typedef unsigned char u8;
-#ifndef __cplusplus
-typedef _Bool bool;
-#endif
typedef unsigned int gfp_t;
struct file;
/* { dg-additional-options "-O" } */
-#ifndef __cplusplus
-typedef _Bool bool;
-#endif
-
struct ss_s {
union out_or_counting_u {
char *newstr;
typedef __s64 s64;
typedef __u64 u64;
typedef long long __kernel_time64_t;
-#ifndef __cplusplus
-typedef _Bool bool;
-#endif
typedef __s64 time64_t;
struct __kernel_timespec {
__kernel_time64_t tv_sec;
typedef __CHAR16_TYPE__ char16_t;
typedef __CHAR32_TYPE__ char32_t;
#elif !__cplusplus
-typedef _Bool bool;
typedef __CHAR16_TYPE__ char16_t;
typedef __CHAR32_TYPE__ char32_t;
typedef __WCHAR_TYPE__ wchar_t;
{ dg-do compile }
{ dg-options "-O2 -Wall -Wno-strict-aliasing" } */
-typedef _Bool bool;
-
#define NOIPA __attribute__ ((noipa))
struct S { };
/* Adapted from various files in the Linux kernel, all of which have: */
/* SPDX-License-Identifier: GPL-2.0 */
-typedef _Bool bool;
-#define true 1
-#define false 0
-
typedef struct {
int counter;
} atomic_t;
different function pointer types. */
/* { dg-do compile } */
-/* { dg-options "-O0 -gctf -dA" } */
+/* { dg-options "-O0 -gctf -dA -std=gnu17" } */
/* { dg-final { scan-assembler-times "\[\t \]0x16000001\[\t \]+\[^\n\]*ctt_info" 1 } } */
/* { dg-final { scan-assembler-times "ascii \"rcu_callback_t.0\"\[\t \]+\[^\n\]*ctf_string" 1 } } */
/* { dg-final { scan-assembler-times "ascii \"func.0\"\[\t \]+\[^\n\]*ctf_string" 1 } } */
--- /dev/null
+/* Test __STDC_VERSION__ for C23 with GNU extensions. Test that -std=gnu23 is
+ the default (replace this test when updating the default to a later version
+ than gnu23). */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+#if __STDC_VERSION__ == 202311L
+int i;
+#else
+#error "Bad __STDC_VERSION__."
+#endif
int table_cycle_size = 16;
/* Return 0 if 'result' is a valid value to have loaded. */
+__attribute__((noinline))
int verify_result ()
{
int x;
}
/* Iterate VALUE through the different valid values. */
+__attribute__((noinline))
void simulate_thread_other_threads ()
{
static int current = 0;
value = table[current];
}
+__attribute__((noinline))
int simulate_thread_step_verify ()
{
return verify_result ();
}
+__attribute__((noinline))
int simulate_thread_final_verify ()
{
return verify_result ();
int table_cycle_size = 16;
/* Return 0 if 'result' is a valid value to have loaded. */
+__attribute__((noinline))
int verify_result ()
{
int x;
}
/* Iterate VALUE through the different valid values. */
+__attribute__((noinline))
void simulate_thread_other_threads ()
{
static int current = 0;
value = table[current];
}
+__attribute__((noinline))
int simulate_thread_step_verify ()
{
return verify_result ();
}
+__attribute__((noinline))
int simulate_thread_final_verify ()
{
return verify_result ();
int table_cycle_size = 16;
/* Return 0 if 'result' is a valid value to have loaded. */
+__attribute__((noinline))
int verify_result ()
{
int x;
}
/* Iterate VALUE through the different valid values. */
+__attribute__((noinline))
void simulate_thread_other_threads ()
{
static int current = 0;
value = table[current];
}
+__attribute__((noinline))
int simulate_thread_step_verify ()
{
return verify_result ();
}
+__attribute__((noinline))
int simulate_thread_final_verify ()
{
return verify_result ();
/* { dg-do compile } */
+/* { dg-additional-options "-std=gnu17" } */
/* PR tree-optimization/117496 */