From a2c6e7f26ec122124c91ca215a285da69d19fac9 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Thu, 29 Sep 2016 22:54:56 +0200 Subject: [PATCH] Implement P0001R1 - C++17 removal of register storage class specifier c-family/ Implement P0001R1 - C++17 removal of register storage class specifier c-family/ * c.opt (Wregister): New warning. * c-opts.c (c_common_post_options): Enable -Wregister by default for C++17. cp/ * decl.c (cp_finish_decl): Diagnose register storage class on vars except when used in GNU global or local register variable extension. (grokdeclarator): Diagnose register storage class on parameters. * except.c (expand_start_catch_block): Set DECL_REGISTER only after cp_finish_decl call. testsuite/ * c-c++-common/Wvarargs-2.c (foo1): Except new warning for C++17. * c-c++-common/vector-subscript-2.c (vf): Expect new error for C++17. * c-c++-common/vector-subscript-5.c (foo): Don't use register keyword if not __SSE2__. * c-c++-common/Wvarargs.c (foo1, foo3): Expect new warnings for C++17. * g++.dg/compat/struct-layout-1_generate.c (iterative_hash): Remove register keywords. * g++.dg/eh/pr29166.C: Add -Wno-register option. * g++.dg/warn/register-parm-1.C (erroneous_warning, no_erroneous_warning): Expect new warnings for C++17. * g++.dg/warn/register-var-2.C (f): Likewise. * g++.dg/parse/register1.C (f): Expect new error for C++17. * g++.dg/parse/linkage2.C (foo): Likewise. * g++.dg/torture/pr36826.C (CoinMin, CoinMax): Avoid register keyword on parameters for C++17. * g++.dg/cpp1z/register1.C: New test. * g++.dg/cpp1z/register2.C: New test. * g++.dg/cpp1z/register3.C: New test. From-SVN: r240638 --- gcc/c-family/ChangeLog | 7 +++++ gcc/c-family/c-opts.c | 4 +++ gcc/c-family/c.opt | 4 +++ gcc/cp/ChangeLog | 10 +++++++ gcc/cp/decl.c | 28 ++++++++++++++++- gcc/cp/except.c | 2 +- gcc/testsuite/ChangeLog | 24 +++++++++++++++ gcc/testsuite/c-c++-common/Wvarargs-2.c | 2 +- gcc/testsuite/c-c++-common/Wvarargs.c | 4 +-- .../c-c++-common/vector-subscript-2.c | 2 +- .../c-c++-common/vector-subscript-5.c | 5 +++- .../g++.dg/compat/struct-layout-1_generate.c | 10 +++---- gcc/testsuite/g++.dg/cpp1z/register1.C | 29 ++++++++++++++++++ gcc/testsuite/g++.dg/cpp1z/register2.C | 30 +++++++++++++++++++ gcc/testsuite/g++.dg/cpp1z/register3.C | 30 +++++++++++++++++++ gcc/testsuite/g++.dg/eh/pr29166.C | 1 + gcc/testsuite/g++.dg/parse/linkage2.C | 2 +- gcc/testsuite/g++.dg/parse/register1.C | 2 +- gcc/testsuite/g++.dg/torture/pr36826.C | 5 ++++ gcc/testsuite/g++.dg/warn/register-parm-1.C | 4 +-- gcc/testsuite/g++.dg/warn/register-var-2.C | 2 +- 21 files changed, 190 insertions(+), 17 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp1z/register1.C create mode 100644 gcc/testsuite/g++.dg/cpp1z/register2.C create mode 100644 gcc/testsuite/g++.dg/cpp1z/register3.C diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index c85bd729e4e..3e606940d13 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,10 @@ +2016-09-29 Jakub Jelinek + + Implement P0001R1 - C++17 removal of register storage class specifier + * c.opt (Wregister): New warning. + * c-opts.c (c_common_post_options): Enable -Wregister by + default for C++17. + 2016-09-29 James Greenhalgh * c-opts.c (c_common_post_options): Remove special case for diff --git a/gcc/c-family/c-opts.c b/gcc/c-family/c-opts.c index 5fe3132b3c2..c5a699d67cf 100644 --- a/gcc/c-family/c-opts.c +++ b/gcc/c-family/c-opts.c @@ -870,6 +870,10 @@ c_common_post_options (const char **pfilename) warn_shift_negative_value = (extra_warnings && (cxx_dialect >= cxx11 || flag_isoc99)); + /* -Wregister is enabled by default in C++17. */ + if (!global_options_set.x_warn_register) + warn_register = cxx_dialect >= cxx1z; + /* Declone C++ 'structors if -Os. */ if (flag_declone_ctor_dtor == -1) flag_declone_ctor_dtor = optimize_size; diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt index 4a9b9e88a25..e14678103cd 100644 --- a/gcc/c-family/c.opt +++ b/gcc/c-family/c.opt @@ -842,6 +842,10 @@ Wredundant-decls C ObjC C++ ObjC++ Var(warn_redundant_decls) Warning Warn about multiple declarations of the same object. +Wregister +C++ ObjC++ Var(warn_register) Warning +Warn about uses of register storage specifier. + Wreorder C++ ObjC++ Var(warn_reorder) Warning LangEnabledBy(C++ ObjC++,Wall) Warn when the compiler reorders code. diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 69bc0958a60..fb0c0e0ffaa 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,13 @@ +2016-09-29 Jakub Jelinek + + Implement P0001R1 - C++17 removal of register storage class specifier + * decl.c (cp_finish_decl): Diagnose register storage class + on vars except when used in GNU global or local register variable + extension. + (grokdeclarator): Diagnose register storage class on parameters. + * except.c (expand_start_catch_block): Set DECL_REGISTER only + after cp_finish_decl call. + 2016-09-29 Marek Polacek * rtti.c (involves_incomplete_p): Add fall through comment. diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 3dfa0423522..65966f85454 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -6711,6 +6711,19 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p, if (type == error_mark_node) return; + /* Warn about register storage specifiers except when in GNU global + or local register variable extension. */ + if (VAR_P (decl) && DECL_REGISTER (decl) && asmspec_tree == NULL_TREE) + { + if (cxx_dialect >= cxx1z) + pedwarn (DECL_SOURCE_LOCATION (decl), OPT_Wregister, + "ISO C++1z does not allow % storage " + "class specifier"); + else + warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wregister, + "% storage class specifier used"); + } + /* If a name was specified, get the string. */ if (at_namespace_scope_p ()) asmspec_tree = maybe_apply_renaming_pragma (decl, asmspec_tree); @@ -11634,7 +11647,20 @@ grokdeclarator (const cp_declarator *declarator, and in case doing stupid register allocation. */ if (storage_class == sc_register) - DECL_REGISTER (decl) = 1; + { + DECL_REGISTER (decl) = 1; + /* Warn about register storage specifiers on PARM_DECLs. */ + if (TREE_CODE (decl) == PARM_DECL) + { + if (cxx_dialect >= cxx1z) + pedwarn (DECL_SOURCE_LOCATION (decl), OPT_Wregister, + "ISO C++1z does not allow % storage " + "class specifier"); + else + warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wregister, + "% storage class specifier used"); + } + } else if (storage_class == sc_extern) DECL_THIS_EXTERN (decl) = 1; else if (storage_class == sc_static) diff --git a/gcc/cp/except.c b/gcc/cp/except.c index 014df507f22..6555d6b5576 100644 --- a/gcc/cp/except.c +++ b/gcc/cp/except.c @@ -540,9 +540,9 @@ expand_start_catch_block (tree decl) if (init_type != TREE_TYPE (init)) init = build1 (NOP_EXPR, init_type, init); exp = create_temporary_var (init_type); - DECL_REGISTER (exp) = 1; cp_finish_decl (exp, init, /*init_const_expr=*/false, NULL_TREE, LOOKUP_ONLYCONVERTING); + DECL_REGISTER (exp) = 1; initialize_handler_parm (decl, exp); } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 753b45b2a0f..804d0c27913 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,27 @@ +2016-09-29 Jakub Jelinek + + Implement P0001R1 - C++17 removal of register storage class specifier + * c-c++-common/Wvarargs-2.c (foo1): Except new warning for C++17. + * c-c++-common/vector-subscript-2.c (vf): Expect new error for + C++17. + * c-c++-common/vector-subscript-5.c (foo): Don't use register + keyword if not __SSE2__. + * c-c++-common/Wvarargs.c (foo1, foo3): Expect new warnings for + C++17. + * g++.dg/compat/struct-layout-1_generate.c (iterative_hash): Remove + register keywords. + * g++.dg/eh/pr29166.C: Add -Wno-register option. + * g++.dg/warn/register-parm-1.C (erroneous_warning, + no_erroneous_warning): Expect new warnings for C++17. + * g++.dg/warn/register-var-2.C (f): Likewise. + * g++.dg/parse/register1.C (f): Expect new error for C++17. + * g++.dg/parse/linkage2.C (foo): Likewise. + * g++.dg/torture/pr36826.C (CoinMin, CoinMax): Avoid register + keyword on parameters for C++17. + * g++.dg/cpp1z/register1.C: New test. + * g++.dg/cpp1z/register2.C: New test. + * g++.dg/cpp1z/register3.C: New test. + 2016-09-29 Uros Bizjak * gcc.target/i386/adx-check.h (main): Simplify feature bit tests. diff --git a/gcc/testsuite/c-c++-common/Wvarargs-2.c b/gcc/testsuite/c-c++-common/Wvarargs-2.c index a2e031f9140..1eacde1cbf2 100644 --- a/gcc/testsuite/c-c++-common/Wvarargs-2.c +++ b/gcc/testsuite/c-c++-common/Wvarargs-2.c @@ -23,7 +23,7 @@ foo0 (int a, int b, ...) } void -foo1 (int a, register int b, ...) +foo1 (int a, register int b, ...) // { dg-warning "ISO C\\+\\+1z does not allow 'register' storage class specifier" "" { target c++1z } } { va_list vp; /* 'b' is declared with register storage, but don't warn diff --git a/gcc/testsuite/c-c++-common/Wvarargs.c b/gcc/testsuite/c-c++-common/Wvarargs.c index 0f90cb3bfce..20d8ec77c03 100644 --- a/gcc/testsuite/c-c++-common/Wvarargs.c +++ b/gcc/testsuite/c-c++-common/Wvarargs.c @@ -23,7 +23,7 @@ foo0 (int a, int b, ...) } void -foo1 (int a, register int b, ...) +foo1 (int a, register int b, ...) // { dg-warning "ISO C\\+\\+1z does not allow 'register' storage class specifier" "" { target c++1z } } { va_list vp; /* 'b' is declared with register storage, but don't warn @@ -45,7 +45,7 @@ foo2 (int a, int b, ...) } void -foo3 (int a, register int b, ...) +foo3 (int a, register int b, ...) // { dg-warning "ISO C\\+\\+1z does not allow 'register' storage class specifier" "" { target c++1z } } { va_list vp; /* 'b' is declared with register storage, so warn. */ diff --git a/gcc/testsuite/c-c++-common/vector-subscript-2.c b/gcc/testsuite/c-c++-common/vector-subscript-2.c index 84d55b91d20..e7bd251e060 100644 --- a/gcc/testsuite/c-c++-common/vector-subscript-2.c +++ b/gcc/testsuite/c-c++-common/vector-subscript-2.c @@ -7,6 +7,6 @@ float vf(int i) { - register vector float a; + register vector float a; // { dg-error "ISO C++1z does not allow 'register' storage class specifier" "" { target c++1z } } return a[0]; } diff --git a/gcc/testsuite/c-c++-common/vector-subscript-5.c b/gcc/testsuite/c-c++-common/vector-subscript-5.c index 916b4a2d9a6..66ed87a4d0b 100644 --- a/gcc/testsuite/c-c++-common/vector-subscript-5.c +++ b/gcc/testsuite/c-c++-common/vector-subscript-5.c @@ -5,7 +5,10 @@ typedef int U __attribute__ ((vector_size (16))); int foo (int i) { - register U u +#if __SSE2__ + register +#endif + U u #if __SSE2__ asm ("xmm0") #endif diff --git a/gcc/testsuite/g++.dg/compat/struct-layout-1_generate.c b/gcc/testsuite/g++.dg/compat/struct-layout-1_generate.c index 9fab3a8d0f7..71d4af93a41 100644 --- a/gcc/testsuite/g++.dg/compat/struct-layout-1_generate.c +++ b/gcc/testsuite/g++.dg/compat/struct-layout-1_generate.c @@ -1028,12 +1028,12 @@ acceptable. Do NOT use for cryptographic purposes. static hashval_t iterative_hash (const void *k_in /* the key */, - register size_t length /* the length of the key */, - register hashval_t initval /* the previous hash, or - an arbitrary value */) + size_t length /* the length of the key */, + hashval_t initval /* the previous hash, or + an arbitrary value */) { - register const unsigned char *k = (const unsigned char *)k_in; - register hashval_t a,b,c,len; + const unsigned char *k = (const unsigned char *)k_in; + hashval_t a,b,c,len; /* Set up the internal state */ len = length; diff --git a/gcc/testsuite/g++.dg/cpp1z/register1.C b/gcc/testsuite/g++.dg/cpp1z/register1.C new file mode 100644 index 00000000000..a55a717d58d --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/register1.C @@ -0,0 +1,29 @@ +// P0001R1 - C++17 removal of register keyword +// { dg-do compile } + +#if defined(__i386__) || defined(__x86_64__) +#define REG1 "ebx" +#define REG2 "edi" +#endif + +#ifdef REG1 +register int a __asm (REG1); // { dg-bogus "ISO C\\+\\+1z does not allow 'register' storage class specifier" "" { target c++1z } } +#endif +register int b; // { dg-error "ISO C\\+\\+1z does not allow 'register' storage class specifier" "" { target c++1z } } +register int c (); // { dg-error "storage class 'register' invalid for function" } +int foo (register int d) // { dg-error "ISO C\\+\\+1z does not allow 'register' storage class specifier" "" { target c++1z } } +{ + return d; +} +int bar () +{ +#ifdef REG2 + register int e __asm (REG2); // { dg-bogus "ISO C\\+\\+1z does not allow 'register' storage class specifier" "" { target c++1z } } +#else + int e; +#endif + register int f; // { dg-error "ISO C\\+\\+1z does not allow 'register' storage class specifier" "" { target c++1z } } + e = 6; + f = 7; + return e + f; +} diff --git a/gcc/testsuite/g++.dg/cpp1z/register2.C b/gcc/testsuite/g++.dg/cpp1z/register2.C new file mode 100644 index 00000000000..1c1be5e43bf --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/register2.C @@ -0,0 +1,30 @@ +// P0001R1 - C++17 removal of register keyword +// { dg-do compile } +// { dg-options "-Wno-register" } + +#if defined(__i386__) || defined(__x86_64__) +#define REG1 "ebx" +#define REG2 "edi" +#endif + +#ifdef REG1 +register int a __asm (REG1); // { dg-bogus "ISO C\\+\\+1z does not allow 'register' storage class specifier" "" { target c++1z } } +#endif +register int b; // { dg-bogus "ISO C\\+\\+1z does not allow 'register' storage class specifier" "" { target c++1z } } +register int c (); // { dg-error "storage class 'register' invalid for function" } +int foo (register int d) // { dg-bogus "ISO C\\+\\+1z does not allow 'register' storage class specifier" "" { target c++1z } } +{ + return d; +} +int bar () +{ +#ifdef REG2 + register int e __asm (REG2); // { dg-bogus "ISO C\\+\\+1z does not allow 'register' storage class specifier" "" { target c++1z } } +#else + int e; +#endif + register int f; // { dg-bogus "ISO C\\+\\+1z does not allow 'register' storage class specifier" "" { target c++1z } } + e = 6; + f = 7; + return e + f; +} diff --git a/gcc/testsuite/g++.dg/cpp1z/register3.C b/gcc/testsuite/g++.dg/cpp1z/register3.C new file mode 100644 index 00000000000..90b7f9d09b7 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/register3.C @@ -0,0 +1,30 @@ +// P0001R1 - C++17 removal of register keyword +// { dg-do compile { target c++14_down } } +// { dg-options "-Wregister" } + +#if defined(__i386__) || defined(__x86_64__) +#define REG1 "ebx" +#define REG2 "edi" +#endif + +#ifdef REG1 +register int a __asm (REG1); // { dg-bogus "'register' storage class specifier used" } +#endif +register int b; // { dg-warning "'register' storage class specifier used" } +register int c (); // { dg-error "storage class 'register' invalid for function" } +int foo (register int d) // { dg-warning "'register' storage class specifier used" } +{ + return d; +} +int bar () +{ +#ifdef REG2 + register int e __asm (REG2); // { dg-bogus "'register' storage class specifier used" } +#else + int e; +#endif + register int f; // { dg-warning "'register' storage class specifier used" } + e = 6; + f = 7; + return e + f; +} diff --git a/gcc/testsuite/g++.dg/eh/pr29166.C b/gcc/testsuite/g++.dg/eh/pr29166.C index 432b64e9849..8d816486a6e 100644 --- a/gcc/testsuite/g++.dg/eh/pr29166.C +++ b/gcc/testsuite/g++.dg/eh/pr29166.C @@ -1,5 +1,6 @@ // PR 29166: r4-r7 corrupted when unwinding. // { dg-do run } +// { dg-additional-options "-Wno-register" } class Ex { diff --git a/gcc/testsuite/g++.dg/parse/linkage2.C b/gcc/testsuite/g++.dg/parse/linkage2.C index aa204df2a10..71402bbca40 100644 --- a/gcc/testsuite/g++.dg/parse/linkage2.C +++ b/gcc/testsuite/g++.dg/parse/linkage2.C @@ -1,3 +1,3 @@ // PR c++/27884 -extern "C" void foo(register int *my_perl); +extern "C" void foo(register int *my_perl); // { dg-error "ISO C\\+\\+1z does not allow 'register' storage class specifier" "" { target c++1z } } diff --git a/gcc/testsuite/g++.dg/parse/register1.C b/gcc/testsuite/g++.dg/parse/register1.C index 3be2e652502..4db85d4f0e1 100644 --- a/gcc/testsuite/g++.dg/parse/register1.C +++ b/gcc/testsuite/g++.dg/parse/register1.C @@ -8,7 +8,7 @@ public: operator int() { return i; } }; -C f (register C x) +C f (register C x) // { dg-error "ISO C\\+\\+1z does not allow 'register' storage class specifier" "" { target c++1z } } { return x + 31; } diff --git a/gcc/testsuite/g++.dg/torture/pr36826.C b/gcc/testsuite/g++.dg/torture/pr36826.C index 436220ba8a7..5418aaa7cd6 100644 --- a/gcc/testsuite/g++.dg/torture/pr36826.C +++ b/gcc/testsuite/g++.dg/torture/pr36826.C @@ -1,5 +1,10 @@ +#if __cplusplus > 201402L +template T CoinMax(const T x1, const T x2); +template T CoinMin(const T x1, const T x2); +#else template T CoinMax(register const T x1, register const T x2); template T CoinMin(register const T x1, register const T x2); +#endif class CoinIndexedVector; class ClpModel { protected: diff --git a/gcc/testsuite/g++.dg/warn/register-parm-1.C b/gcc/testsuite/g++.dg/warn/register-parm-1.C index 44232d3cf41..15d1aa53f26 100644 --- a/gcc/testsuite/g++.dg/warn/register-parm-1.C +++ b/gcc/testsuite/g++.dg/warn/register-parm-1.C @@ -1,9 +1,9 @@ // PR c++/60955 // { dg-options "-Wextra" } -unsigned int erroneous_warning(register int a) { +unsigned int erroneous_warning(register int a) { // { dg-warning "ISO C\\+\\+1z does not allow 'register' storage class specifier" "" { target c++1z } } if ((a) & 0xff) return 1; else return 0; } -unsigned int no_erroneous_warning(register int a) { +unsigned int no_erroneous_warning(register int a) { // { dg-warning "ISO C\\+\\+1z does not allow 'register' storage class specifier" "" { target c++1z } } if (a & 0xff) return 1; else return 0; } diff --git a/gcc/testsuite/g++.dg/warn/register-var-2.C b/gcc/testsuite/g++.dg/warn/register-var-2.C index 28f5df0cf52..d829f8ac7c2 100644 --- a/gcc/testsuite/g++.dg/warn/register-var-2.C +++ b/gcc/testsuite/g++.dg/warn/register-var-2.C @@ -9,6 +9,6 @@ void g(int *); void f(void) { - register int x; + register int x; /* { dg-warning "ISO C\\+\\+1z does not allow 'register' storage class specifier" "" { target c++1z } } */ g(&x); /* { dg-warning "address requested for 'x', which is declared 'register'" } */ }