Patchwork [C++] Fixes for duplicate warnings regressions [1/2]

login
register
mail settings
Submitter Paolo Carlini
Date Nov. 10, 2013, 10:26 a.m.
Message ID <527F5F45.5050806@oracle.com>
Download mbox | patch
Permalink /patch/290037/
State New
Headers show

Comments

Paolo Carlini - Nov. 10, 2013, 10:26 a.m.
Hi,

this is the issue with -Waddress caused by the fix for c++/56930. I'm 
handling it as already described, that is by adding a bool parameter to 
c_common_truthvalue_conversion.

Tested x86_64-linux.

Thanks!
Paolo.

//////////////////////
/c-family
2013-11-11  Paolo Carlini  <paolo.carlini@oracle.com>

	* c-common.c (c_common_truthvalue_conversion): Add bool parameter.
	* c-common.h (c_common_truthvalue_conversion): Adjust declaration.

/cp
2013-11-11  Paolo Carlini  <paolo.carlini@oracle.com>

	* typeck.c (cp_truthvalue_conversion): Add tsubst_flags_t
	parameter.
	* cp-tree.h (cp_truthvalue_conversion): Adjust declaration.
	* cvt.c (cp_convert_and_check): The second time call cp_convert
	with tf_none to avoid duplicate -Waddress warnings.
	(ocp_convert): Adjust.
	* init.c (expand_cleanup_for_base): Likewise.
	* rtti.c (build_dynamic_cast_1): Likewise.

/c
2013-11-11  Paolo Carlini  <paolo.carlini@oracle.com>

	* c-typeck.c (c_objc_common_truthvalue_conversion): Update 
	c_common_truthvalue_conversion call.

/objc
2013-11-11  Paolo Carlini  <paolo.carlini@oracle.com>

	* objc-next-runtime-abi-01.c (next_sjlj_build_enter_and_setjmp):
	Update c_common_truthvalue_conversion call.
	(next_sjlj_build_catch_list): Likewise.
	(next_sjlj_build_try_catch_finally): Likewise.
	* objc-act.c (objc_finish_foreach_loop): Likewise.
	(objc_finish_foreach_loop): Likewise.
Jason Merrill - Nov. 23, 2013, 7:12 p.m.
On 11/10/2013 05:26 AM, Paolo Carlini wrote:
> this is the issue with -Waddress caused by the fix for c++/56930. I'm
> handling it as already described, that is by adding a bool parameter to
> c_common_truthvalue_conversion.

Why not handle this by making that warning respect 
c_inhibit_evaluation_warnings?

Jason

Patch

Index: c/c-typeck.c
===================================================================
--- c/c-typeck.c	(revision 204620)
+++ c/c-typeck.c	(working copy)
@@ -11001,7 +11001,7 @@  c_objc_common_truthvalue_conversion (location_t lo
   else
     /* ??? Should we also give an error for vectors rather than leaving
        those to give errors later?  */
-    expr = c_common_truthvalue_conversion (location, expr);
+    expr = c_common_truthvalue_conversion (location, expr, /*complain=*/true);
 
   if (TREE_CODE (expr) == INTEGER_CST && int_operands && !int_const)
     {
Index: c-family/c-common.c
===================================================================
--- c-family/c-common.c	(revision 204620)
+++ c-family/c-common.c	(working copy)
@@ -4495,7 +4495,8 @@  decl_with_nonnull_addr_p (const_tree expr)
    The resulting type should always be `truthvalue_type_node'.  */
 
 tree
-c_common_truthvalue_conversion (location_t location, tree expr)
+c_common_truthvalue_conversion (location_t location, tree expr,
+				bool complain)
 {
   switch (TREE_CODE (expr))
     {
@@ -4518,9 +4519,11 @@  tree
 	return expr;
       expr = build2 (TREE_CODE (expr), truthvalue_type_node,
 		     c_common_truthvalue_conversion (location,
-						     TREE_OPERAND (expr, 0)),
+						     TREE_OPERAND (expr, 0),
+						     complain),
 		     c_common_truthvalue_conversion (location,
-						     TREE_OPERAND (expr, 1)));
+						     TREE_OPERAND (expr, 1),
+						     complain));
       goto ret;
 
     case TRUTH_NOT_EXPR:
@@ -4528,7 +4531,8 @@  tree
 	return expr;
       expr = build1 (TREE_CODE (expr), truthvalue_type_node,
 		     c_common_truthvalue_conversion (location,
-						     TREE_OPERAND (expr, 0)));
+						     TREE_OPERAND (expr, 0),
+						     complain));
       goto ret;
 
     case ERROR_MARK:
@@ -4558,11 +4562,12 @@  tree
  	tree inner = TREE_OPERAND (expr, 0);
 	if (decl_with_nonnull_addr_p (inner))
 	  {
-	    /* Common Ada/Pascal programmer's mistake.  */
-	    warning_at (location,
-			OPT_Waddress,
-			"the address of %qD will always evaluate as %<true%>",
-			inner);
+	    if (complain)
+	      /* Common Ada/Pascal programmer's mistake.  */
+	      warning_at (location,
+			  OPT_Waddress,
+			  "the address of %qD will always evaluate as %<true%>",
+			  inner);
 	    return truthvalue_true_node;
 	  }
 	break;
@@ -4573,9 +4578,11 @@  tree
 			      (TREE_SIDE_EFFECTS (TREE_OPERAND (expr, 1))
 			       ? TRUTH_OR_EXPR : TRUTH_ORIF_EXPR),
 		c_common_truthvalue_conversion (location,
-						TREE_OPERAND (expr, 0)),
+						TREE_OPERAND (expr, 0),
+						complain),
 		c_common_truthvalue_conversion (location,
-						TREE_OPERAND (expr, 1)),
+						TREE_OPERAND (expr, 1),
+						complain),
 			      0);
       goto ret;
 
@@ -4584,7 +4591,8 @@  tree
     case FLOAT_EXPR:
     case EXCESS_PRECISION_EXPR:
       /* These don't change whether an object is nonzero or zero.  */
-      return c_common_truthvalue_conversion (location, TREE_OPERAND (expr, 0));
+      return c_common_truthvalue_conversion (location, TREE_OPERAND (expr, 0),
+					     complain);
 
     case LROTATE_EXPR:
     case RROTATE_EXPR:
@@ -4595,12 +4603,13 @@  tree
 	  expr = build2 (COMPOUND_EXPR, truthvalue_type_node,
 			 TREE_OPERAND (expr, 1),
 			 c_common_truthvalue_conversion
-			 (location, TREE_OPERAND (expr, 0)));
+			 (location, TREE_OPERAND (expr, 0), complain));
 	  goto ret;
 	}
       else
 	return c_common_truthvalue_conversion (location,
-					       TREE_OPERAND (expr, 0));
+					       TREE_OPERAND (expr, 0),
+					       complain);
 
     case COND_EXPR:
       /* Distribute the conversion into the arms of a COND_EXPR.  */
@@ -4610,9 +4619,9 @@  tree
 	  tree op2 = TREE_OPERAND (expr, 2);
 	  /* In C++ one of the arms might have void type if it is throw.  */
 	  if (!VOID_TYPE_P (TREE_TYPE (op1)))
-	    op1 = c_common_truthvalue_conversion (location, op1);
+	    op1 = c_common_truthvalue_conversion (location, op1, complain);
 	  if (!VOID_TYPE_P (TREE_TYPE (op2)))
-	    op2 = c_common_truthvalue_conversion (location, op2);
+	    op2 = c_common_truthvalue_conversion (location, op2, complain);
 	  expr = fold_build3_loc (location, COND_EXPR, truthvalue_type_node,
 				  TREE_OPERAND (expr, 0), op1, op2);
 	  goto ret;
@@ -4623,9 +4632,11 @@  tree
 	  expr = build3 (COND_EXPR, truthvalue_type_node,
 			 TREE_OPERAND (expr, 0),
 			 c_common_truthvalue_conversion (location,
-							 TREE_OPERAND (expr, 1)),
+							 TREE_OPERAND (expr, 1),
+							 complain),
 			 c_common_truthvalue_conversion (location,
-							 TREE_OPERAND (expr, 2)));
+							 TREE_OPERAND (expr, 2),
+							 complain));
 	  goto ret;
 	}
 
@@ -4647,7 +4658,8 @@  tree
 	/* If this isn't narrowing the argument, we can ignore it.  */
 	if (TYPE_PRECISION (totype) >= TYPE_PRECISION (fromtype))
 	  return c_common_truthvalue_conversion (location,
-						 TREE_OPERAND (expr, 0));
+						 TREE_OPERAND (expr, 0),
+						 complain);
       }
       break;
 
@@ -4655,8 +4667,10 @@  tree
       if (!TREE_NO_WARNING (expr)
 	  && warn_parentheses)
 	{
-	  warning (OPT_Wparentheses,
-		   "suggest parentheses around assignment used as truth value");
+	  if (complain)
+	    warning (OPT_Wparentheses,
+		     "suggest parentheses around assignment used as "
+		     "truth value");
 	  TREE_NO_WARNING (expr) = 1;
 	}
       break;
@@ -4674,10 +4688,12 @@  tree
 		? TRUTH_OR_EXPR : TRUTH_ORIF_EXPR),
 	c_common_truthvalue_conversion
 	       (location,
-		build_unary_op (location, REALPART_EXPR, t, 0)),
+		build_unary_op (location, REALPART_EXPR, t, 0),
+		complain),
 	c_common_truthvalue_conversion
 	       (location,
-		build_unary_op (location, IMAGPART_EXPR, t, 0)),
+		build_unary_op (location, IMAGPART_EXPR, t, 0),
+		complain),
 	       0));
       goto ret;
     }
Index: c-family/c-common.h
===================================================================
--- c-family/c-common.h	(revision 204620)
+++ c-family/c-common.h	(working copy)
@@ -747,7 +747,7 @@  extern tree c_fully_fold (tree, bool, bool *);
 extern tree decl_constant_value_for_optimization (tree);
 extern tree c_wrap_maybe_const (tree, bool);
 extern tree c_save_expr (tree);
-extern tree c_common_truthvalue_conversion (location_t, tree);
+extern tree c_common_truthvalue_conversion (location_t, tree, bool);
 extern void c_apply_type_quals_to_decl (int, tree);
 extern tree c_sizeof_or_alignof_type (location_t, tree, bool, int);
 extern tree c_alignof_expr (location_t, tree);
Index: cp/cp-tree.h
===================================================================
--- cp/cp-tree.h	(revision 204620)
+++ cp/cp-tree.h	(working copy)
@@ -5966,7 +5966,7 @@  extern void cxx_print_error_function		(diagnostic_
 /* in typeck.c */
 extern bool cxx_mark_addressable		(tree);
 extern int string_conv_p			(const_tree, const_tree, int);
-extern tree cp_truthvalue_conversion		(tree);
+extern tree cp_truthvalue_conversion		(tree, tsubst_flags_t);
 extern tree condition_conversion		(tree);
 extern tree require_complete_type		(tree);
 extern tree require_complete_type_sfinae	(tree, tsubst_flags_t);
Index: cp/cvt.c
===================================================================
--- cp/cvt.c	(revision 204620)
+++ cp/cvt.c	(working copy)
@@ -629,7 +629,8 @@  cp_convert_and_check (tree type, tree expr, tsubst
     {
       tree folded = maybe_constant_value (expr);
       tree stripped = folded;
-      tree folded_result = cp_convert (type, folded, complain);
+      tree folded_result
+	= folded != expr ? cp_convert (type, folded, tf_none) : result;
 
       /* maybe_constant_value wraps an INTEGER_CST with TREE_OVERFLOW in a
 	 NOP_EXPR so that it isn't TREE_CONSTANT anymore.  */
@@ -782,7 +783,7 @@  ocp_convert (tree type, tree expr, int convtype, i
 	     to the underlying type first.  */
 	  if (SCOPED_ENUM_P (intype) && (convtype & CONV_STATIC))
 	    e = build_nop (ENUM_UNDERLYING_TYPE (intype), e);
-	  return cp_truthvalue_conversion (e);
+	  return cp_truthvalue_conversion (e, complain);
 	}
 
       converted = fold_if_not_in_template (convert_to_integer (type, e));
Index: cp/init.c
===================================================================
--- cp/init.c	(revision 204620)
+++ cp/init.c	(working copy)
@@ -1205,9 +1205,10 @@  expand_cleanup_for_base (tree binfo, tree flag)
 
   if (flag)
     expr = fold_build3_loc (input_location,
-			COND_EXPR, void_type_node,
-			c_common_truthvalue_conversion (input_location, flag),
-			expr, integer_zero_node);
+			    COND_EXPR, void_type_node,
+			    c_common_truthvalue_conversion
+			    (input_location, flag, /*complain=*/true),
+			    expr, integer_zero_node);
 
   finish_eh_cleanup (expr);
 }
Index: cp/rtti.c
===================================================================
--- cp/rtti.c	(revision 204620)
+++ cp/rtti.c	(working copy)
@@ -752,7 +752,7 @@  build_dynamic_cast_1 (tree type, tree expr, tsubst
 	      tree neq;
 
 	      result = save_expr (result);
-	      neq = cp_truthvalue_conversion (result);
+	      neq = cp_truthvalue_conversion (result, complain);
 	      return cp_convert (type,
 				 build3 (COND_EXPR, TREE_TYPE (result),
 					 neq, result, bad), complain);
Index: cp/typeck.c
===================================================================
--- cp/typeck.c	(revision 204620)
+++ cp/typeck.c	(working copy)
@@ -5153,7 +5153,7 @@  build_x_unary_op (location_t loc, enum tree_code c
    -1.  */
 
 tree
-cp_truthvalue_conversion (tree expr)
+cp_truthvalue_conversion (tree expr, tsubst_flags_t complain)
 {
   tree type = TREE_TYPE (expr);
   if (TYPE_PTRDATAMEM_P (type))
@@ -5165,12 +5165,14 @@  tree
 	 'if (p)' or a 'while (!p)', where p is a pointer.  */
       tree ret;
       ++c_inhibit_evaluation_warnings;
-      ret = c_common_truthvalue_conversion (input_location, expr);
+      ret = c_common_truthvalue_conversion (input_location, expr,
+					    complain & tf_warning);
       --c_inhibit_evaluation_warnings;
       return ret;
     }
   else
-    return c_common_truthvalue_conversion (input_location, expr);
+    return c_common_truthvalue_conversion (input_location, expr,
+					   complain & tf_warning);
 }
 
 /* Just like cp_truthvalue_conversion, but we want a CLEANUP_POINT_EXPR.  */
Index: objc/objc-act.c
===================================================================
--- objc/objc-act.c	(revision 204620)
+++ objc/objc-act.c	(working copy)
@@ -9832,7 +9832,7 @@  objc_finish_foreach_loop (location_t location, tre
 		       build_binary_op (location,
 					EQ_EXPR,
 					objc_foreach_batchsize_decl,
-					build_int_cst (long_unsigned_type_node, 0), 1)),
+					build_int_cst (long_unsigned_type_node, 0), 1), /*complain=*/true),
 		      false, NULL),
 		     /* Then block (we fill it in later).  */
 		     NULL_TREE,
@@ -9910,7 +9910,7 @@  objc_finish_foreach_loop (location_t location, tre
 		 build_indirect_ref (location,
 				     objc_build_component_ref (objc_foreach_enum_state_decl,
 							       get_identifier ("mutationsPtr")),
-				     RO_UNARY_STAR), 1)),
+				     RO_UNARY_STAR), 1), /*complain=*/true),
 	       false, NULL),
 	      /* Then block.  */
 	      build_function_call (input_location,
@@ -9958,7 +9958,8 @@  objc_finish_foreach_loop (location_t location, tre
 		build_binary_op (location,
 				 LT_EXPR,
 				 objc_foreach_index_decl,
-				 objc_foreach_batchsize_decl, 1)),
+				 objc_foreach_batchsize_decl, 1),
+		/*complain=*/true),
 	       false, NULL),
 	      /* Then block.  */
 	      build1 (GOTO_EXPR, void_type_node, next_object_label_decl),
@@ -10008,7 +10009,8 @@  objc_finish_foreach_loop (location_t location, tre
 		build_binary_op (location,
 				 NE_EXPR,
 				 objc_foreach_batchsize_decl,
-				 build_int_cst (long_unsigned_type_node, 0), 1)),
+				 build_int_cst (long_unsigned_type_node, 0), 1),
+		/*complain=*/true),
 	       false, NULL),
 	      /* Then block.  */
 	      build1 (GOTO_EXPR, void_type_node, next_batch_label_decl),
Index: objc/objc-next-runtime-abi-01.c
===================================================================
--- objc/objc-next-runtime-abi-01.c	(revision 204620)
+++ objc/objc-next-runtime-abi-01.c	(working copy)
@@ -2563,7 +2563,8 @@  next_sjlj_build_enter_and_setjmp (struct objc_try_
 			    objc_setjmp_decl, t);
 
   cond = build2 (COMPOUND_EXPR, TREE_TYPE (sj), enter, sj);
-  cond = c_common_truthvalue_conversion (input_location, cond);
+  cond = c_common_truthvalue_conversion (input_location, cond,
+					 /*complain=*/true);
 
   return build3 (COND_EXPR, void_type_node, cond, NULL, NULL);
 }
@@ -2633,7 +2634,8 @@  next_sjlj_build_catch_list (struct objc_try_contex
 	      args = tree_cons (NULL, t, args);
 	      t = build_function_call (input_location,
 				       objc_exception_match_decl, args);
-	      cond = c_common_truthvalue_conversion (input_location, t);
+	      cond = c_common_truthvalue_conversion (input_location, t,
+						     /*complain=*/true);
 	    }
 	  t = build3 (COND_EXPR, void_type_node, cond, body, NULL);
 	  SET_EXPR_LOCATION (t, EXPR_LOCATION (stmt));
@@ -2757,7 +2759,7 @@  next_sjlj_build_try_catch_finally (struct objc_try
   t = next_sjlj_build_try_exit (ctcp);
   t = build_stmt (input_location, COND_EXPR,
 		  c_common_truthvalue_conversion
-		    (input_location, rethrow_decl),
+		  (input_location, rethrow_decl, /*complain=*/true),
 		  NULL, t);
   SET_EXPR_LOCATION (t, cur_try_context->finally_locus);
   append_to_statement_list (t, &TREE_OPERAND (try_fin, 1));
@@ -2770,7 +2772,8 @@  next_sjlj_build_try_catch_finally (struct objc_try
 			   objc_exception_throw_decl, t);
   t = build_stmt (input_location, COND_EXPR,
 		  c_common_truthvalue_conversion (input_location,
-						  rethrow_decl),
+						  rethrow_decl,
+						  /*complain=*/true),
 		  t, NULL);
   SET_EXPR_LOCATION (t, cur_try_context->end_finally_locus);
   append_to_statement_list (t, &TREE_OPERAND (try_fin, 1));