public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* C++ PATCHes for bootstrap/68346, 68361
@ 2015-11-17 18:16 Jason Merrill
  2015-11-17 21:41 ` Jason Merrill
  0 siblings, 1 reply; 2+ messages in thread
From: Jason Merrill @ 2015-11-17 18:16 UTC (permalink / raw)
  To: gcc-patches List

[-- Attachment #1: Type: text/plain, Size: 463 bytes --]

A couple of bootstrap issues on some targets:

68346: My earlier change to avoid folding the arguments to 
warn_tautological_cmp wasn't quite right, either.  This patch folds 
within the function, at the place where we are interested in a constant 
value.

68361: The way we were trying to suppress -Wparentheses before wasn't 
effective enough.  Let's actually turn off the flag around the relevant 
convert call.

Tested x86_64-pc-linux-gnu, applying to trunk.

[-- Attachment #2: 68361.patch --]
[-- Type: text/x-patch, Size: 1069 bytes --]

commit 56ca181e3d438fb9b95c865fde6e77f5335c791a
Author: Jason Merrill <jason@redhat.com>
Date:   Tue Nov 17 10:51:24 2015 -0500

    	PR bootstrap/68361
    	* cvt.c (cp_convert_and_check): Use warning_sentinel to suppress
    	-Wparentheses.

diff --git a/gcc/cp/cvt.c b/gcc/cp/cvt.c
index 0231efc..ebca004 100644
--- a/gcc/cp/cvt.c
+++ b/gcc/cp/cvt.c
@@ -644,7 +644,7 @@ cp_convert_and_check (tree type, tree expr, tsubst_flags_t complain)
       else
 	{
 	  /* Avoid bogus -Wparentheses warnings.  */
-	  TREE_NO_WARNING (folded) = true;
+	  warning_sentinel w (warn_parentheses);
 	  folded_result = cp_convert (type, folded, tf_none);
 	}
       folded_result = fold_simple (folded_result);
diff --git a/gcc/testsuite/g++.dg/warn/Wparentheses-28.C b/gcc/testsuite/g++.dg/warn/Wparentheses-28.C
new file mode 100644
index 0000000..f6636cb
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/Wparentheses-28.C
@@ -0,0 +1,14 @@
+// PR bootstrap/68361
+// { dg-options -Wparentheses }
+
+struct A
+{
+  int p: 2;
+};
+
+A a, b;
+
+int main()
+{
+  bool t = (a.p = b.p);
+}

[-- Attachment #3: 68346.patch --]
[-- Type: text/x-patch, Size: 1319 bytes --]

commit 7489a9400cffa4c1010debaf2d86dcd286ce1cfd
Author: Jason Merrill <jason@redhat.com>
Date:   Tue Nov 17 12:56:00 2015 -0500

    	PR bootstrap/68346
    
    	* c-common.c (warn_tautological_cmp): Fold before checking for
    	constants.

diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c
index 06d857c..f50ca48 100644
--- a/gcc/c-family/c-common.c
+++ b/gcc/c-family/c-common.c
@@ -1924,7 +1924,7 @@ warn_tautological_cmp (location_t loc, enum tree_code code, tree lhs, tree rhs)
 
   /* We do not warn for constants because they are typical of macro
      expansions that test for features, sizeof, and similar.  */
-  if (CONSTANT_CLASS_P (lhs) || CONSTANT_CLASS_P (rhs))
+  if (CONSTANT_CLASS_P (fold (lhs)) || CONSTANT_CLASS_P (fold (rhs)))
     return;
 
   /* Don't warn for e.g.
diff --git a/gcc/testsuite/g++.dg/warn/Wtautological-compare2.C b/gcc/testsuite/g++.dg/warn/Wtautological-compare2.C
new file mode 100644
index 0000000..9d9060d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/Wtautological-compare2.C
@@ -0,0 +1,11 @@
+// PR bootstrap/68346
+// { dg-options -Wtautological-compare }
+
+#define INVALID_REGNUM			(~(unsigned int) 0)
+#define PIC_OFFSET_TABLE_REGNUM INVALID_REGNUM
+
+int main()
+{
+  if ((unsigned) PIC_OFFSET_TABLE_REGNUM != INVALID_REGNUM)
+    __builtin_abort();
+}

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: C++ PATCHes for bootstrap/68346, 68361
  2015-11-17 18:16 C++ PATCHes for bootstrap/68346, 68361 Jason Merrill
@ 2015-11-17 21:41 ` Jason Merrill
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2015-11-17 21:41 UTC (permalink / raw)
  To: gcc-patches List

[-- Attachment #1: Type: text/plain, Size: 857 bytes --]

On 11/17/2015 01:15 PM, Jason Merrill wrote:
> A couple of bootstrap issues on some targets:
>
> 68346: My earlier change to avoid folding the arguments to
> warn_tautological_cmp wasn't quite right, either.  This patch folds
> within the function, at the place where we are interested in a constant
> value.

I also noticed that we weren't leaving any indication of the cast in the 
trees, which also would have avoided the warning.  With delayed folding 
there really should be one, so I added it.  Which caused a crash in the 
LITERAL_ZERO_P code.  Which is obsolete now, so I've removed it.  Which 
required my code to immediately fold negation of a constant to avoid 
folding -0 into 0; while I was looking at that I also limited it to 
folding only when the numeric literal immediately follows the -.

Tested x86_64-pc-linux-gnu, applying to trunk.



[-- Attachment #2: 68346-2.patch --]
[-- Type: text/x-patch, Size: 825 bytes --]

commit e7b8c5439a004bfb41bc67af1175b3b2f6abaa03
Author: Jason Merrill <jason@redhat.com>
Date:   Tue Nov 17 12:56:37 2015 -0500

    	PR bootstrap/68346
    
    	* typeck.c (build_static_cast_1): Force a NOP when converting to
    	the same type.

diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index b7395cf..5f7d4bb 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -6668,7 +6668,13 @@ build_static_cast_1 (tree type, tree expr, bool c_cast_p,
 	 If T is a reference type, the result is an lvalue; otherwise,
 	 the result is an rvalue.  */
       if (TREE_CODE (type) != REFERENCE_TYPE)
-	result = rvalue (result);
+	{
+	  result = rvalue (result);
+
+	  if (result == expr && SCALAR_TYPE_P (type))
+	    /* Leave some record of the cast.  */
+	    result = build_nop (type, expr);
+	}
       return result;
     }
 

[-- Attachment #3: lit-zero.patch --]
[-- Type: text/x-patch, Size: 6019 bytes --]

commit f5ac737442dacc96f28ba4f508628ee356ecd046
Author: Jason Merrill <jason@redhat.com>
Date:   Tue Nov 17 13:08:45 2015 -0500

    	LITERAL_ZERO_P obsoleted by delayed folding.
    
    	* cp-tree.h (LITERAL_ZERO_P): Remove.
    	* parser.c (cp_parser_postfix_expression, literal_zeros)
    	(cp_parser_parenthesized_expression_list): Don't mess with it.

diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 84437b4..160bf1e 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -4517,10 +4517,6 @@ more_aggr_init_expr_args_p (const aggr_init_expr_arg_iterator *iter)
 #define SIZEOF_EXPR_TYPE_P(NODE) \
   TREE_LANG_FLAG_0 (SIZEOF_EXPR_CHECK (NODE))
 
-/* True if INTEGER_CST is a zero literal seen in function argument list.  */
-#define LITERAL_ZERO_P(NODE) \
-  (INTEGER_CST_CHECK (NODE)->base.nothrow_flag)
-
 /* An enumeration of the kind of tags that C++ accepts.  */
 enum tag_types {
   none_type = 0, /* Not a tag type.  */
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index c5f9530..0e1116b 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -1976,7 +1976,7 @@ static tree cp_parser_postfix_open_square_expression
 static tree cp_parser_postfix_dot_deref_expression
   (cp_parser *, enum cpp_ttype, tree, bool, cp_id_kind *, location_t);
 static vec<tree, va_gc> *cp_parser_parenthesized_expression_list
-  (cp_parser *, int, bool, bool, bool *, bool = false);
+  (cp_parser *, int, bool, bool, bool *);
 /* Values for the second parameter of cp_parser_parenthesized_expression_list.  */
 enum { non_attr = 0, normal_attr = 1, id_attr = 2 };
 static void cp_parser_pseudo_destructor_name
@@ -6502,8 +6502,7 @@ cp_parser_postfix_expression (cp_parser *parser, bool address_p, bool cast_p,
 	    args = (cp_parser_parenthesized_expression_list
 		    (parser, non_attr,
 		     /*cast_p=*/false, /*allow_expansion_p=*/true,
-		     /*non_constant_p=*/NULL,
-		     /*want_literal_zero_p=*/warn_memset_transposed_args));
+		     /*non_constant_p=*/NULL));
 	    if (is_builtin_constant_p)
 	      {
 		parser->integral_constant_expression_p
@@ -6577,22 +6576,14 @@ cp_parser_postfix_expression (cp_parser *parser, bool address_p, bool cast_p,
 		    && DECL_BUILT_IN_CLASS (postfix_expression) == BUILT_IN_NORMAL
 		    && DECL_FUNCTION_CODE (postfix_expression) == BUILT_IN_MEMSET
 		    && vec_safe_length (args) == 3
+		    && TREE_CODE ((*args)[2]) == INTEGER_CST
 		    && integer_zerop ((*args)[2])
-		    && LITERAL_ZERO_P ((*args)[2])
-		    && !(integer_zerop ((*args)[1])
-			 && LITERAL_ZERO_P ((*args)[1])))
+		    && !(TREE_CODE ((*args)[1]) == INTEGER_CST
+			 && integer_zerop ((*args)[1])))
 		  warning (OPT_Wmemset_transposed_args,
 			   "%<memset%> used with constant zero length "
 			   "parameter; this could be due to transposed "
 			   "parameters");
-
-		/* Replace LITERAL_ZERO_P INTEGER_CSTs with normal ones
-		   to avoid leaking those into folder and middle-end.  */
-		unsigned int i;
-		tree arg;
-		FOR_EACH_VEC_SAFE_ELT (args, i, arg)
-		  if (TREE_CODE (arg) == INTEGER_CST && LITERAL_ZERO_P (arg))
-		    (*args)[i] = build_int_cst (TREE_TYPE (arg), 0);
 	      }
 
 	    if (TREE_CODE (postfix_expression) == COMPONENT_REF)
@@ -7085,10 +7076,6 @@ cp_parser_postfix_dot_deref_expression (cp_parser *parser,
   return postfix_expression;
 }
 
-/* Cache of LITERAL_ZERO_P constants.  */
-
-static GTY(()) tree literal_zeros[itk_none];
-
 /* Parse a parenthesized expression-list.
 
    expression-list:
@@ -7113,18 +7100,14 @@ static GTY(()) tree literal_zeros[itk_none];
    plain identifier argument, normal_attr for an attribute that wants
    an expression, or non_attr if we aren't parsing an attribute list.  If
    NON_CONSTANT_P is non-NULL, *NON_CONSTANT_P indicates whether or
-   not all of the expressions in the list were constant.
-   WANT_LITERAL_ZERO_P is true if the caller is interested in
-   LITERAL_ZERO_P INTEGER_CSTs.  FIXME: once we don't fold everything
-   immediately, this can be removed.  */
+   not all of the expressions in the list were constant.  */
 
 static vec<tree, va_gc> *
 cp_parser_parenthesized_expression_list (cp_parser* parser,
 					 int is_attribute_list,
 					 bool cast_p,
                                          bool allow_expansion_p,
-					 bool *non_constant_p,
-					 bool want_literal_zero_p)
+					 bool *non_constant_p)
 {
   vec<tree, va_gc> *expression_list;
   bool fold_expr_p = is_attribute_list != non_attr;
@@ -7187,51 +7170,8 @@ cp_parser_parenthesized_expression_list (cp_parser* parser,
 		  *non_constant_p = true;
 	      }
 	    else
-	      {
-		expr = NULL_TREE;
-		cp_token *tok = cp_lexer_peek_token (parser->lexer);
-		switch (tok->type)
-		  {
-		  case CPP_NUMBER:
-		  case CPP_CHAR:
-		  case CPP_WCHAR:
-		  case CPP_CHAR16:
-		  case CPP_CHAR32:
-		  case CPP_UTF8CHAR:
-		    /* If a parameter is literal zero alone, remember it
-		       for -Wmemset-transposed-args warning.  */
-		    if (integer_zerop (tok->u.value)
-			&& !TREE_OVERFLOW (tok->u.value)
-			&& want_literal_zero_p
-			&& (cp_lexer_peek_nth_token (parser->lexer, 2)->type
-			    == CPP_COMMA
-			    || cp_lexer_peek_nth_token (parser->lexer, 2)->type
-			       == CPP_CLOSE_PAREN))
-		      {
-			unsigned int i;
-			for (i = 0; i < itk_none; ++i)
-			  if (TREE_TYPE (tok->u.value) == integer_types[i])
-			    break;
-			if (i < itk_none && literal_zeros[i])
-			  expr = literal_zeros[i];
-			else
-			  {
-			    expr = copy_node (tok->u.value);
-			    LITERAL_ZERO_P (expr) = 1;
-			    if (i < itk_none)
-			      literal_zeros[i] = expr;
-			  }
-			/* Consume the 0 token (or '\0', 0LL etc.).  */
-			cp_lexer_consume_token (parser->lexer);
-		      }
-		    break;
-		  default:
-		    break;
-		  }
-		if (expr == NULL_TREE)
-		  expr = cp_parser_assignment_expression (parser, /*pidk=*/NULL,
-							  cast_p);
-	      }
+	      expr = cp_parser_assignment_expression (parser, /*pidk=*/NULL,
+						      cast_p);
 
 	    if (fold_expr_p)
 	      expr = instantiate_non_dependent_expr (expr);

[-- Attachment #4: neg-fold.patch --]
[-- Type: text/x-patch, Size: 2319 bytes --]

commit c81beb805efe0dbe25880bafc13567a6ca67a918
Author: Jason Merrill <jason@redhat.com>
Date:   Tue Nov 17 13:53:22 2015 -0500

    	Don't fold -(constant) or -0.
    
    	* parser.c (cp_parser_unary_expression): Fold -constant here.
    	* typeck.c (cp_build_unary_op): Not here.

diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 286c8db..c5f9530 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -7662,6 +7662,8 @@ cp_parser_unary_expression (cp_parser *parser, cp_id_kind * pidk,
 
       /* Consume the operator token.  */
       token = cp_lexer_consume_token (parser->lexer);
+      enum cpp_ttype op_ttype = cp_lexer_peek_token (parser->lexer)->type;
+
       /* Parse the cast-expression.  */
       cast_expression
 	= cp_parser_cast_expression (parser,
@@ -7693,8 +7695,25 @@ cp_parser_unary_expression (cp_parser *parser, cp_id_kind * pidk,
 	  non_constant_p = unary_operator == PREINCREMENT_EXPR
 			   ? NIC_PREINCREMENT : NIC_PREDECREMENT;
 	  /* Fall through.  */
-	case UNARY_PLUS_EXPR:
 	case NEGATE_EXPR:
+	  /* Immediately fold negation of a constant, unless the constant is 0
+	     (since -0 == 0) or it would overflow.  */
+	  if (unary_operator == NEGATE_EXPR && op_ttype == CPP_NUMBER
+	      && CONSTANT_CLASS_P (cast_expression)
+	      && !integer_zerop (cast_expression)
+	      && !TREE_OVERFLOW (cast_expression))
+	    {
+	      tree folded = fold_build1 (unary_operator,
+					 TREE_TYPE (cast_expression),
+					 cast_expression);
+	      if (CONSTANT_CLASS_P (folded) && !TREE_OVERFLOW (folded))
+		{
+		  expression = folded;
+		  break;
+		}
+	    }
+	  /* Fall through.  */
+	case UNARY_PLUS_EXPR:
 	case TRUTH_NOT_EXPR:
 	  expression = finish_unary_op_expr (loc, unary_operator,
 					     cast_expression, complain);
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index 6541e97..b7395cf 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -5768,10 +5768,6 @@ cp_build_unary_op (enum tree_code code, tree xarg, int noconvert,
 	    /* Make sure the result is not an lvalue: a unary plus or minus
 	       expression is always a rvalue.  */
 	    arg = rvalue (arg);
-
-	    if (code == NEGATE_EXPR && CONSTANT_CLASS_P (arg))
-	      /* Immediately fold negation of a constant.  */
-	      return fold_build1 (code, TREE_TYPE (arg), arg);
 	  }
       }
       break;

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-11-17 21:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-17 18:16 C++ PATCHes for bootstrap/68346, 68361 Jason Merrill
2015-11-17 21:41 ` Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).