From 1ebd2b2c9407796cd526137038b9b885f68ffb4d Mon Sep 17 00:00:00 2001 From: Martin Sebor Date: Thu, 24 Jun 2021 15:35:20 -0600 Subject: c: add support for per-location warning groups. gcc/ChangeLog: * tree.h (warning_suppressed_at, copy_warning, warning_suppressed_p, suppress_warning): New functions. gcc/c/ChangeLog: * c-decl.c (pop_scope): Replace direct uses of TREE_NO_WARNING with warning_suppressed_p, suppress_warning, and copy_no_warning. (diagnose_mismatched_decls): Same. (duplicate_decls): Same. (grokdeclarator): Same. (finish_function): Same. (c_write_global_declarations_1): Same. * c-fold.c (c_fully_fold_internal): Same. * c-parser.c (c_parser_expr_no_commas): Same. (c_parser_postfix_expression): Same. * c-typeck.c (array_to_pointer_conversion): Same. (function_to_pointer_conversion): Same. (default_function_array_conversion): Same. (convert_lvalue_to_rvalue): Same. (default_conversion): Same. (build_indirect_ref): Same. (build_function_call_vec): Same. (build_atomic_assign): Same. (build_unary_op): Same. (c_finish_return): Same. (emit_side_effect_warnings): Same. (c_finish_stmt_expr): Same. (c_omp_clause_copy_ctor): Same. --- gcc/c/c-decl.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) (limited to 'gcc/c/c-decl.c') diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c index 7cd13a5..983d65e 100644 --- a/gcc/c/c-decl.c +++ b/gcc/c/c-decl.c @@ -1295,7 +1295,7 @@ pop_scope (void) case VAR_DECL: /* Warnings for unused variables. */ if ((!TREE_USED (p) || !DECL_READ_P (p)) - && !TREE_NO_WARNING (p) + && !warning_suppressed_p (p, OPT_Wunused_but_set_variable) && !DECL_IN_SYSTEM_HEADER (p) && DECL_NAME (p) && !DECL_ARTIFICIAL (p) @@ -2159,8 +2159,8 @@ diagnose_mismatched_decls (tree newdecl, tree olddecl, if (DECL_IN_SYSTEM_HEADER (newdecl) || DECL_IN_SYSTEM_HEADER (olddecl) - || TREE_NO_WARNING (newdecl) - || TREE_NO_WARNING (olddecl)) + || warning_suppressed_p (newdecl, OPT_Wpedantic) + || warning_suppressed_p (olddecl, OPT_Wpedantic)) return true; /* Allow OLDDECL to continue in use. */ if (variably_modified_type_p (newtype, NULL)) @@ -2956,7 +2956,7 @@ duplicate_decls (tree newdecl, tree olddecl) if (!diagnose_mismatched_decls (newdecl, olddecl, &newtype, &oldtype)) { /* Avoid `unused variable' and other warnings for OLDDECL. */ - TREE_NO_WARNING (olddecl) = 1; + suppress_warning (olddecl, OPT_Wunused); return false; } @@ -7543,10 +7543,7 @@ grokdeclarator (const struct c_declarator *declarator, FIELD_DECL, declarator->u.id.id, type); DECL_NONADDRESSABLE_P (decl) = bitfield; if (bitfield && !declarator->u.id.id) - { - TREE_NO_WARNING (decl) = 1; - DECL_PADDING_P (decl) = 1; - } + DECL_PADDING_P (decl) = 1; if (size_varies) C_DECL_VARIABLE_SIZE (decl) = 1; @@ -10244,7 +10241,7 @@ finish_function (location_t end_loc) && targetm.warn_func_return (fndecl) && warning (OPT_Wreturn_type, "no return statement in function returning non-void")) - TREE_NO_WARNING (fndecl) = 1; + suppress_warning (fndecl, OPT_Wreturn_type); /* Complain about parameters that are only set, but never otherwise used. */ if (warn_unused_but_set_parameter) @@ -10259,7 +10256,7 @@ finish_function (location_t end_loc) && !DECL_READ_P (decl) && DECL_NAME (decl) && !DECL_ARTIFICIAL (decl) - && !TREE_NO_WARNING (decl)) + && !warning_suppressed_p (decl, OPT_Wunused_but_set_parameter)) warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wunused_but_set_parameter, "parameter %qD set but not used", decl); @@ -12126,19 +12123,20 @@ c_write_global_declarations_1 (tree globals) { if (C_DECL_USED (decl)) { + /* TODO: Add OPT_Wundefined-inline. */ if (pedwarn (input_location, 0, "%q+F used but never defined", decl)) - TREE_NO_WARNING (decl) = 1; + suppress_warning (decl /* OPT_Wundefined-inline. */); } /* For -Wunused-function warn about unused static prototypes. */ else if (warn_unused_function && ! DECL_ARTIFICIAL (decl) - && ! TREE_NO_WARNING (decl)) + && ! warning_suppressed_p (decl, OPT_Wunused_function)) { if (warning (OPT_Wunused_function, "%q+F declared % but never defined", decl)) - TREE_NO_WARNING (decl) = 1; + suppress_warning (decl, OPT_Wunused_function); } } -- cgit v1.1