From ff1ff960f5039cf1d2970bfe2ba965d1b994caf1 Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Tue, 24 Oct 2017 19:01:03 +0000 Subject: [PATCH] re PR c++/82466 (Missing warning for re-declaration of built-in function as variable) 2017-10-24 Paolo Carlini PR c++/82466 * doc/invoke.texi ([Wbuiltin-declaration-mismatch]): Extend description. /cp 2017-10-24 Paolo Carlini PR c++/82466 * decl.c (duplicate_decls): Warn for built-in functions declared as non-function, use OPT_Wbuiltin_declaration_mismatch. * decl.c (duplicate_decls): Avoid redundant '+' in warning_at. /c 2017-10-24 Paolo Carlini PR c++/82466 * c-decl.c (diagnose_mismatched_decls): Use OPT_Wbuiltin_declaration_mismatch. /testsuite 2017-10-24 Paolo Carlini PR c++/82466 * c-c++-common/Wbuiltin-declaration-mismatch-1.c: New. * c-c++-common/Wno-builtin-declaration-mismatch-1.c: Likewise. * g++.dg/warn/Wbuiltin_declaration_mismatch-1.C: Likewise. * g++.dg/parse/builtin2.C: Adjust. * g++.old-deja/g++.mike/p811.C: Likewise. From-SVN: r254057 --- gcc/ChangeLog | 12 +++++++++--- gcc/c/ChangeLog | 6 ++++++ gcc/c/c-decl.c | 3 ++- gcc/cp/ChangeLog | 8 ++++++++ gcc/cp/decl.c | 12 ++++++++++-- gcc/doc/invoke.texi | 3 ++- gcc/testsuite/ChangeLog | 9 +++++++++ .../c-c++-common/Wbuiltin-declaration-mismatch-1.c | 4 ++++ .../Wno-builtin-declaration-mismatch-1.c | 4 ++++ gcc/testsuite/g++.dg/parse/builtin2.C | 2 +- .../g++.dg/warn/Wbuiltin_declaration_mismatch-1.C | 7 +++++++ gcc/testsuite/g++.old-deja/g++.mike/p811.C | 2 +- 12 files changed, 63 insertions(+), 9 deletions(-) create mode 100644 gcc/testsuite/c-c++-common/Wbuiltin-declaration-mismatch-1.c create mode 100644 gcc/testsuite/c-c++-common/Wno-builtin-declaration-mismatch-1.c create mode 100644 gcc/testsuite/g++.dg/warn/Wbuiltin_declaration_mismatch-1.C diff --git a/gcc/ChangeLog b/gcc/ChangeLog index e0ef3edb9da..a27df40cd62 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2017-10-24 Paolo Carlini + + PR c++/82466 + * doc/invoke.texi ([Wbuiltin-declaration-mismatch]): Extend + description. + 2017-10-24 Wilco Dijkstra PR rtl-optimization/82396 @@ -55,7 +61,7 @@ * tree-outof-ssa.h (always_initialized_rtx_for_ssa_name_p): Delete. * expr.c (expand_expr_real_1) : Revert latest change. * loop-iv.c (iv_get_reaching_def): Likewise. - * cfgexpand.c (expand_one_ssa_partition): Initialize the RTX if the + * cfgexpand.c (expand_one_ssa_partition): Initialize the RTX if the variable is promoted and the partition contains undefined values. 2017-10-23 Sandra Loosemore @@ -76,7 +82,7 @@ (nios2_symbolic_constant_allowed): New. (nios2_symbolic_constant_p): New. (nios2_plus_symbolic_constant_p): New. - (nios2_valid_addr_expr_p): Recognize addresses involving + (nios2_valid_addr_expr_p): Recognize addresses involving symbolic constants. (nios2_legitimate_address_p): Likewise, also LO_SUM. (nios2_symbolic_memory_operand_p): New. @@ -157,7 +163,7 @@ * i386.h (processor_costs): Remove sse_move; add xmm_move, ymm_move and zmm_move. Increase size of sse load and store tables; add unaligned load and store tables; add ssemmx_to_integer. - * x86-tune-costs.h: Update all entries according to real + * x86-tune-costs.h: Update all entries according to real move latencies from Agner Fog's manual and chip documentation. 2017-10-23 Jakub Jelinek diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index 1f697f17f99..c260f62b111 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,9 @@ +2017-10-24 Paolo Carlini + + PR c++/82466 + * c-decl.c (diagnose_mismatched_decls): Use + OPT_Wbuiltin_declaration_mismatch. + 2017-10-12 David Malcolm * c-parser.c (c_parser_require): Add "type_is_unique" param and diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c index 26b34ab3e50..5c472e66af8 100644 --- a/gcc/c/c-decl.c +++ b/gcc/c/c-decl.c @@ -1837,7 +1837,8 @@ diagnose_mismatched_decls (tree newdecl, tree olddecl, locate_old_decl (olddecl); } else if (TREE_PUBLIC (newdecl)) - warning (0, "built-in function %q+D declared as non-function", + warning (OPT_Wbuiltin_declaration_mismatch, + "built-in function %q+D declared as non-function", newdecl); else warning (OPT_Wshadow, "declaration of %q+D shadows " diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index e24a1949d86..8c587a3e845 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,11 @@ +2017-10-24 Paolo Carlini + + PR c++/82466 + * decl.c (duplicate_decls): Warn for built-in functions declared as + non-function, use OPT_Wbuiltin_declaration_mismatch. + + * decl.c (duplicate_decls): Avoid redundant '+' in warning_at. + 2017-10-24 Paolo Carlini PR c++/80991 diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index a3cc80cf7a3..bb48099da56 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -1431,7 +1431,15 @@ duplicate_decls (tree newdecl, tree olddecl, bool newdecl_is_friend) /* Avoid warnings redeclaring built-ins which have not been explicitly declared. */ if (DECL_ANTICIPATED (olddecl)) - return NULL_TREE; + { + if (TREE_PUBLIC (newdecl) + && CP_DECL_CONTEXT (newdecl) == global_namespace) + warning_at (DECL_SOURCE_LOCATION (newdecl), + OPT_Wbuiltin_declaration_mismatch, + "built-in function %qD declared as non-function", + newdecl); + return NULL_TREE; + } /* If you declare a built-in or predefined function name as static, the old definition is overridden, but optionally warn this was a @@ -1522,7 +1530,7 @@ next_arg:; warning_at (DECL_SOURCE_LOCATION (newdecl), OPT_Wbuiltin_declaration_mismatch, - "declaration of %q+#D conflicts with built-in " + "declaration of %q#D conflicts with built-in " "declaration %q#D", newdecl, olddecl); } else if ((DECL_EXTERN_C_P (newdecl) diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 3a879566487..71b2445f70f 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -6320,7 +6320,8 @@ attributes. @item -Wno-builtin-declaration-mismatch @opindex Wno-builtin-declaration-mismatch @opindex Wbuiltin-declaration-mismatch -Warn if a built-in function is declared with the wrong signature. +Warn if a built-in function is declared with the wrong signature or +as non-function. This warning is enabled by default. @item -Wno-builtin-macro-redefined diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index edf21e9e8b8..7801c03d1d3 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,12 @@ +2017-10-24 Paolo Carlini + + PR c++/82466 + * c-c++-common/Wbuiltin-declaration-mismatch-1.c: New. + * c-c++-common/Wno-builtin-declaration-mismatch-1.c: Likewise. + * g++.dg/warn/Wbuiltin_declaration_mismatch-1.C: Likewise. + * g++.dg/parse/builtin2.C: Adjust. + * g++.old-deja/g++.mike/p811.C: Likewise. + 2017-10-24 Paolo Carlini PR c++/80991 diff --git a/gcc/testsuite/c-c++-common/Wbuiltin-declaration-mismatch-1.c b/gcc/testsuite/c-c++-common/Wbuiltin-declaration-mismatch-1.c new file mode 100644 index 00000000000..63343b8bfee --- /dev/null +++ b/gcc/testsuite/c-c++-common/Wbuiltin-declaration-mismatch-1.c @@ -0,0 +1,4 @@ +/* PR c++/82466 */ +/* { dg-options "-Wbuiltin-declaration-mismatch" } */ + +int printf; /* { dg-warning "declared as non-function" } */ diff --git a/gcc/testsuite/c-c++-common/Wno-builtin-declaration-mismatch-1.c b/gcc/testsuite/c-c++-common/Wno-builtin-declaration-mismatch-1.c new file mode 100644 index 00000000000..6409412ac6a --- /dev/null +++ b/gcc/testsuite/c-c++-common/Wno-builtin-declaration-mismatch-1.c @@ -0,0 +1,4 @@ +/* PR c++/82466 */ +/* { dg-options "-Wno-builtin-declaration-mismatch" } */ + +int printf; diff --git a/gcc/testsuite/g++.dg/parse/builtin2.C b/gcc/testsuite/g++.dg/parse/builtin2.C index c524ea68416..daa80bb11b0 100644 --- a/gcc/testsuite/g++.dg/parse/builtin2.C +++ b/gcc/testsuite/g++.dg/parse/builtin2.C @@ -1,5 +1,5 @@ // PR c++/14432 -// { dg-options "" } +// { dg-options "-Wno-builtin-declaration-mismatch" } struct Y {}; Y y1; diff --git a/gcc/testsuite/g++.dg/warn/Wbuiltin_declaration_mismatch-1.C b/gcc/testsuite/g++.dg/warn/Wbuiltin_declaration_mismatch-1.C new file mode 100644 index 00000000000..713073cb421 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wbuiltin_declaration_mismatch-1.C @@ -0,0 +1,7 @@ +// PR c++/82466 +// { dg-options "-Wbuiltin-declaration-mismatch" } + +namespace N +{ + int printf; +} diff --git a/gcc/testsuite/g++.old-deja/g++.mike/p811.C b/gcc/testsuite/g++.old-deja/g++.mike/p811.C index 5c8260aa1f8..2ca04abdcba 100644 --- a/gcc/testsuite/g++.old-deja/g++.mike/p811.C +++ b/gcc/testsuite/g++.old-deja/g++.mike/p811.C @@ -1,5 +1,5 @@ // { dg-do assemble } -// { dg-options "" } +// { dg-options "-Wno-builtin-declaration-mismatch" } // This test case caused the compiler to abort at one point in time. // prms-id: 811 -- 2.30.2