Re: [PATCH 3/13] v2 Use new per-location warning APIs in C front end

2021-06-24 Thread Martin Sebor via Gcc-patches

On 6/23/21 11:09 PM, Jeff Law wrote:



On 6/4/2021 3:41 PM, Martin Sebor via Gcc-patches wrote:

The attached patch replaces the uses of TREE_NO_WARNING in the C front
end with the new suppress_warning(), warning_suppressed_p(), and
copy_warning() APIs.

gcc-no-warning-c.diff

Add support for per-location warning groups.

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.

OK once prereqs are approved.


I've retested this on top of the first patch and pushed r12-1802.

Martin


Re: [PATCH 3/13] v2 Use new per-location warning APIs in C front end

2021-06-23 Thread Jeff Law via Gcc-patches




On 6/4/2021 3:41 PM, Martin Sebor via Gcc-patches wrote:

The attached patch replaces the uses of TREE_NO_WARNING in the C front
end with the new suppress_warning(), warning_suppressed_p(), and
copy_warning() APIs.

gcc-no-warning-c.diff

Add support for per-location warning groups.

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.

OK once prereqs are approved.
jeff



[PING][PATCH 3/13] v2 Use new per-location warning APIs in C front end

2021-06-21 Thread Martin Sebor via Gcc-patches

Ping: https://gcc.gnu.org/pipermail/gcc-patches/2021-June/571974.html

I'm looking for a review of the mostly mechanical C front end changes
to the new suppress_warning() API.

On 6/4/21 3:41 PM, Martin Sebor wrote:

The attached patch replaces the uses of TREE_NO_WARNING in the C front
end with the new suppress_warning(), warning_suppressed_p(), and
copy_warning() APIs.




[PATCH 3/13] v2 Use new per-location warning APIs in C front end

2021-06-04 Thread Martin Sebor via Gcc-patches

The attached patch replaces the uses of TREE_NO_WARNING in the C front
end with the new suppress_warning(), warning_suppressed_p(), and
copy_warning() APIs.
Add support for per-location warning groups.

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.

diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c
index 28f851b9d0b..adfdd56d49d 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))
@@ -2953,7 +2953,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;
 }
 
@@ -7540,10 +7540,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;
@@ -10232,7 +10229,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)
@@ -10247,7 +10244,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);
@@ -12114,19 +12111,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);
 	}
 	}
 
diff --git a/gcc/c/c-fold.c b/gcc/c/c-fold.c
index 68c74cc1eb2..0ebcb469d28 100644
--- a/gcc/c/c-fold.c
+++ b/gcc/c/c-fold.c
@@ -154,7 +154,7 @@ c_fully_fold_internal (tree expr, bool in_init, bool *maybe_const_operands,
   tree orig_op0, orig_op1, orig_op2;
   bool op0_const = true, op1_const = true, op2_const = true;
   bool op0_const_self = true, op1_const_self = true, op2_const_self = true;
-  bool nowarning = TREE_NO_WARNING (expr);
+  bool nowarning = warning_suppressed_p (expr, OPT_Woverflow);
   bool unused_p;
   bool op0_lval = false;
   source_range old_range;
@@ -670,13 +670,13 @@ c_fully_fold_internal (tree expr, bool in_init, bool *maybe_const_operands,
  out:
   /* Some folding may introduce NON_LVALUE_E