* remove the need of -std=c2y for -fdefer-ts to take effect ---
* added a test jumping into a defer block from above. * reworded the lookup_label_for_goto error message to mention the error is a jump into the defer block, instead of out. * moved the 'defer' keyword behind a -fdefer-ts flag, and added texinfo docs plus related failure test. --- based on n3589[1], this feature mostly makes use of already-established logic, namely push_cleanup used by the cleanup attribute, and the constraints put in place for checking local jumps against statement expressions 1: https://open-std.org/JTC1/SC22/WG14/www/docs/n3589.pdf Anna (navi) Figueiredo Gomes (3): c: handle expression nodes in push_cleanup c: introduce jump barriers for statement expressions c: implement the defer keyword gcc/c-family/c-common.cc | 1 + gcc/c-family/c-common.h | 39 +++--- gcc/c-family/c-cppbuiltin.cc | 3 + gcc/c-family/c.opt | 4 + gcc/c/c-decl.cc | 141 +++++++++++++++------ gcc/c/c-parser.cc | 41 ++++++ gcc/c/c-tree.h | 8 +- gcc/c/c-typeck.cc | 56 +++++++-- gcc/doc/invoke.texi | 6 +- gcc/doc/standards.texi | 3 +- gcc/testsuite/gcc.dg/defer-1.c | 224 +++++++++++++++++++++++++++++++++ gcc/testsuite/gcc.dg/defer-2.c | 90 +++++++++++++ gcc/testsuite/gcc.dg/defer-3.c | 15 +++ gcc/testsuite/gcc.dg/defer-4.c | 6 + 14 files changed, 568 insertions(+), 69 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/defer-1.c create mode 100644 gcc/testsuite/gcc.dg/defer-2.c create mode 100644 gcc/testsuite/gcc.dg/defer-3.c create mode 100644 gcc/testsuite/gcc.dg/defer-4.c Range-diff against v2: 1: 51b7a0fc41f < -: ----------- c: add D_C2Y disable mask 2: 1f386002702 = 1: da835e79572 c: handle expression nodes in push_cleanup 3: 4d720d3b0a1 = 2: b0fd9d8165a c: introduce jump barriers for statement expressions 4: ef8d6f226b9 ! 3: 466a5360e73 c: implement the defer keyword @@ Commit message ## Notes ## + v3: + * remove the need of -std=c2y for -fdefer-ts to take effect v2: * added a test jumping into a defer block from above. * reworded the lookup_label_for_goto error message to mention the error @@ gcc/c-family/c-common.cc: const struct c_common_resword c_common_reswords[] = { "continue", RID_CONTINUE, 0 }, { "decltype", RID_DECLTYPE, D_CXXONLY | D_CXX11 | D_CXXWARN }, { "default", RID_DEFAULT, 0 }, -+ { "defer", RID_DEFER, D_DEFER | D_C2Y | D_CONLY }, ++ { "defer", RID_DEFER, D_DEFER | D_CONLY }, { "delete", RID_DELETE, D_CXXONLY | D_CXXWARN }, { "do", RID_DO, 0 }, { "double", RID_DOUBLE, 0 }, @@ gcc/c-family/c-common.h: enum rid /* C extensions */ RID_ASM, RID_TYPEOF, RID_TYPEOF_UNQUAL, RID_ALIGNOF, RID_ATTRIBUTE, @@ gcc/c-family/c-common.h: extern machine_mode c_default_pointer_mode; + #define D_CXXONLY 0x0002 /* C++ only (not in C). */ #define D_C99 0x0004 /* In C, C99 only. */ #define D_C23 0x0008 /* In C, C23 only. */ - #define D_C2Y 0x0010 /* In C, C2y only. */ --#define D_CXX11 0x0020 /* In C++, C++11 only. */ --#define D_EXT 0x0040 /* GCC extension. */ --#define D_EXT89 0x0080 /* GCC extension incorporated in C99. */ --#define D_EXT11 0x0100 /* GCC extension incorporated in C23. */ --#define D_ASM 0x0200 /* Disabled by -fno-asm. */ --#define D_OBJC 0x0400 /* In Objective C and neither C nor C++. */ --#define D_CXX_OBJC 0x0800 /* In Objective C, and C++, but not C. */ --#define D_CXXWARN 0x1000 /* In C warn with -Wcxx-compat. */ --#define D_CXX_CONCEPTS 0x2000 /* In C++, only with concepts. */ --#define D_TRANSMEM 0x4000 /* C++ transactional memory TS. */ --#define D_CXX_CHAR8_T 0x8000 /* In C++, only with -fchar8_t. */ --#define D_CXX20 0x10000 /* In C++, C++20 only. */ --#define D_CXX_COROUTINES 0x20000 /* In C++, only with coroutines. */ --#define D_CXX_MODULES 0x40000 /* In C++, only with modules. */ -+#define D_DEFER 0x0020 /* C defer statements TS. */ -+#define D_CXX11 0x0040 /* In C++, C++11 only. */ -+#define D_EXT 0x0080 /* GCC extension. */ -+#define D_EXT89 0x0100 /* GCC extension incorporated in C99. */ -+#define D_EXT11 0x0200 /* GCC extension incorporated in C23. */ -+#define D_ASM 0x0400 /* Disabled by -fno-asm. */ -+#define D_OBJC 0x0800 /* In Objective C and neither C nor C++. */ -+#define D_CXX_OBJC 0x1000 /* In Objective C, and C++, but not C. */ -+#define D_CXXWARN 0x2000 /* In C warn with -Wcxx-compat. */ -+#define D_CXX_CONCEPTS 0x4000 /* In C++, only with concepts. */ -+#define D_TRANSMEM 0x8000 /* C++ transactional memory TS. */ -+#define D_CXX_CHAR8_T 0x10000 /* In C++, only with -fchar8_t. */ -+#define D_CXX20 0x20000 /* In C++, C++20 only. */ -+#define D_CXX_COROUTINES 0x40000 /* In C++, only with coroutines. */ -+#define D_CXX_MODULES 0x80000 /* In C++, only with modules. */ +-#define D_CXX11 0x0010 /* In C++, C++11 only. */ +-#define D_EXT 0x0020 /* GCC extension. */ +-#define D_EXT89 0x0040 /* GCC extension incorporated in C99. */ +-#define D_EXT11 0x0080 /* GCC extension incorporated in C23. */ +-#define D_ASM 0x0100 /* Disabled by -fno-asm. */ +-#define D_OBJC 0x0200 /* In Objective C and neither C nor C++. */ +-#define D_CXX_OBJC 0x0400 /* In Objective C, and C++, but not C. */ +-#define D_CXXWARN 0x0800 /* In C warn with -Wcxx-compat. */ +-#define D_CXX_CONCEPTS 0x1000 /* In C++, only with concepts. */ +-#define D_TRANSMEM 0x2000 /* C++ transactional memory TS. */ +-#define D_CXX_CHAR8_T 0x4000 /* In C++, only with -fchar8_t. */ +-#define D_CXX20 0x8000 /* In C++, C++20 only. */ +-#define D_CXX_COROUTINES 0x10000 /* In C++, only with coroutines. */ +-#define D_CXX_MODULES 0x20000 /* In C++, only with modules. */ ++#define D_DEFER 0x0010 /* C defer statements TS. */ ++#define D_CXX11 0x0020 /* In C++, C++11 only. */ ++#define D_EXT 0x0040 /* GCC extension. */ ++#define D_EXT89 0x0080 /* GCC extension incorporated in C99. */ ++#define D_EXT11 0x0100 /* GCC extension incorporated in C23. */ ++#define D_ASM 0x0200 /* Disabled by -fno-asm. */ ++#define D_OBJC 0x0400 /* In Objective C and neither C nor C++. */ ++#define D_CXX_OBJC 0x0800 /* In Objective C, and C++, but not C. */ ++#define D_CXXWARN 0x1000 /* In C warn with -Wcxx-compat. */ ++#define D_CXX_CONCEPTS 0x2000 /* In C++, only with concepts. */ ++#define D_TRANSMEM 0x4000 /* C++ transactional memory TS. */ ++#define D_CXX_CHAR8_T 0x8000 /* In C++, only with -fchar8_t. */ ++#define D_CXX20 0x10000 /* In C++, C++20 only. */ ++#define D_CXX_COROUTINES 0x20000 /* In C++, only with coroutines. */ ++#define D_CXX_MODULES 0x40000 /* In C++, only with modules. */ #define D_CXX_CONCEPTS_FLAGS D_CXXONLY | D_CXX_CONCEPTS #define D_CXX_CHAR8_T_FLAGS D_CXXONLY | D_CXX_CHAR8_T @@ gcc/c-family/c-cppbuiltin.cc: c_cpp_builtins (cpp_reader *pfile) if (flag_iso) cpp_define (pfile, "__STRICT_ANSI__"); -+ if (flag_isoc2y && flag_defer_ts) ++ if (flag_defer_ts) + builtin_define_with_int_value ("__STDC_DEFER_TS25755__", 1); + if (!flag_signed_char) @@ gcc/c/c-decl.cc: c_check_switch_jump_warnings (struct c_spot_bindings *switch_bi ## gcc/c/c-parser.cc ## @@ gcc/c/c-parser.cc: c_parse_init (void) + mask |= D_C99; + if (!flag_isoc23) mask |= D_C23; - if (!flag_isoc2y) - mask |= D_C2Y; + if (!flag_defer_ts) + mask |= D_DEFER; if (flag_no_asm) @@ gcc/doc/invoke.texi: the target (the default). This option is not supported for + +@opindex fdefer-ts +@item -fdefer-ts -+Enables support for the defer keyword, as specified by ISO/DIS TS 25755, -+for @dfn{C2Y}. ++Enables support for the defer keyword, as specified by ISO/DIS TS 25755. @end table @node C++ Dialect Options @@ gcc/doc/standards.texi: enabled with @option{-std=c23} or @option{-std=iso9899:2 A further version of the C standard, known as @dfn{C2Y}, is under development; experimental and incomplete support for this is enabled -with @option{-std=c2y}. -+with @option{-std=c2y}. Under @dfn{C2Y}, GCC implements the defer -+technical specification, ISO/DIS TS 25755, enabled with @option{-fdefer-ts}. ++with @option{-std=c2y}. GCC implements the defer technical specification, ++ISO/DIS TS 25755, enabled with @option{-fdefer-ts}. By default, GCC provides some extensions to the C language that, on rare occasions conflict with the C standard. @xref{C @@ gcc/doc/standards.texi: enabled with @option{-std=c23} or @option{-std=iso9899:2 ## gcc/testsuite/gcc.dg/defer-1.c (new) ## @@ +/* { dg-do run } */ -+/* { dg-options "-std=c2y -fdefer-ts" } */ ++/* { dg-options "-fdefer-ts" } */ + +#include <setjmp.h> + @@ gcc/testsuite/gcc.dg/defer-1.c (new) ## gcc/testsuite/gcc.dg/defer-2.c (new) ## @@ +/* { dg-do compile } */ -+/* { dg-options "-std=c2y -fdefer-ts" } */ ++/* { dg-options "-fdefer-ts" } */ + +void a () +{ @@ gcc/testsuite/gcc.dg/defer-2.c (new) ## gcc/testsuite/gcc.dg/defer-3.c (new) ## @@ +/* { dg-do run } */ -+/* { dg-options "-std=c2y -fdefer-ts" } */ ++/* { dg-options "-fdefer-ts" } */ + +extern void exit(int); +extern void abort(void); @@ gcc/testsuite/gcc.dg/defer-3.c (new) ## gcc/testsuite/gcc.dg/defer-4.c (new) ## @@ +/* { dg-do compile } */ -+/* { dg-options "-std=c2y" } */ + +int main(void) +{ -- 2.49.1