public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Fix PR70941
@ 2016-05-06  7:37 Richard Biener
  2016-05-06 15:25 ` Jakub Jelinek
  0 siblings, 1 reply; 2+ messages in thread
From: Richard Biener @ 2016-05-06  7:37 UTC (permalink / raw)
  To: gcc-patches


The following completes the fix for PR67921 now that we have a testcase
for the non-pointer case.

Bootstrapped and tested on x86_64-unknown-linux-gnu, applied.

Richard.

2016-05-06  Richard Biener  <rguenther@suse.de>

	PR middle-end/70941
	* fold-const.c (split_tree): Always convert to the original type
	before negating.

	* gcc.dg/torture/pr70941.c: New testcase.

Index: gcc/fold-const.c
===================================================================
*** gcc/fold-const.c	(revision 235942)
--- gcc/fold-const.c	(working copy)
*************** split_tree (location_t loc, tree in, tre
*** 836,846 ****
  	*minus_litp = *litp, *litp = 0;
        if (neg_conp_p)
  	*conp = negate_expr (*conp);
!       if (neg_var_p)
  	{
! 	  /* Convert to TYPE before negating a pointer type expr.  */
! 	  if (var && POINTER_TYPE_P (TREE_TYPE (var)))
! 	    var = fold_convert_loc (loc, type, var);
  	  var = negate_expr (var);
  	}
      }
--- 836,845 ----
  	*minus_litp = *litp, *litp = 0;
        if (neg_conp_p)
  	*conp = negate_expr (*conp);
!       if (neg_var_p && var)
  	{
! 	  /* Convert to TYPE before negating.  */
! 	  var = fold_convert_loc (loc, type, var);
  	  var = negate_expr (var);
  	}
      }
*************** split_tree (location_t loc, tree in, tre
*** 863,872 ****
        else if (*minus_litp)
  	*litp = *minus_litp, *minus_litp = 0;
        *conp = negate_expr (*conp);
!       /* Convert to TYPE before negating a pointer type expr.  */
!       if (var && POINTER_TYPE_P (TREE_TYPE (var)))
! 	var = fold_convert_loc (loc, type, var);
!       var = negate_expr (var);
      }
  
    return var;
--- 862,873 ----
        else if (*minus_litp)
  	*litp = *minus_litp, *minus_litp = 0;
        *conp = negate_expr (*conp);
!       if (var)
! 	{
! 	  /* Convert to TYPE before negating.  */
! 	  var = fold_convert_loc (loc, type, var);
! 	  var = negate_expr (var);
! 	}
      }
  
    return var;
Index: gcc/testsuite/gcc.dg/torture/pr70941.c
===================================================================
*** gcc/testsuite/gcc.dg/torture/pr70941.c	(revision 0)
--- gcc/testsuite/gcc.dg/torture/pr70941.c	(revision 0)
***************
*** 0 ****
--- 1,14 ----
+ /* { dg-do run } */
+ /* { dg-require-effective-target int32plus } */
+ 
+ extern void abort (void);
+ 
+ char a = 0, b = 0, c = 0, d = 0;
+ 
+ int main()
+ {
+   a = -(b - 405418259) - ((d && c) ^ 2040097152);
+   if (a != -109)
+     abort();
+   return 0;
+ }

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

* Re: [PATCH] Fix PR70941
  2016-05-06  7:37 [PATCH] Fix PR70941 Richard Biener
@ 2016-05-06 15:25 ` Jakub Jelinek
  0 siblings, 0 replies; 2+ messages in thread
From: Jakub Jelinek @ 2016-05-06 15:25 UTC (permalink / raw)
  To: Richard Biener; +Cc: gcc-patches

On Fri, May 06, 2016 at 09:37:46AM +0200, Richard Biener wrote:
> 
> The following completes the fix for PR67921 now that we have a testcase
> for the non-pointer case.
> 
> Bootstrapped and tested on x86_64-unknown-linux-gnu, applied.

The testcase (for obvious reasons) fails on -funsigned-char defaulting
targets.  Plus, just theoretically, if int is 32-bits or larger, but
char is not 8-bit, it could fail as well.

Fixed thusly, committed as obvious.

2016-05-06  Jakub Jelinek  <jakub@redhat.com>

	PR middle-end/70941
	* gcc.dg/torture/pr70941.c (abort): Remove prototype.
	(a, b, c, d): Change type from char to signed char.
	(main): Compare against (signed char) -1634678893 instead of
	hardcoded -109.  Use __builtin_abort instead of abort.

--- gcc/testsuite/gcc.dg/torture/pr70941.c.jj	2016-05-06 15:09:06.000000000 +0200
+++ gcc/testsuite/gcc.dg/torture/pr70941.c	2016-05-06 17:11:25.000000000 +0200
@@ -1,14 +1,12 @@
 /* { dg-do run } */
 /* { dg-require-effective-target int32plus } */
 
-extern void abort (void);
-
-char a = 0, b = 0, c = 0, d = 0;
+signed char a = 0, b = 0, c = 0, d = 0;
 
 int main()
 {
   a = -(b - 405418259) - ((d && c) ^ 2040097152);
-  if (a != -109)
-    abort();
+  if (a != (signed char) -1634678893)
+    __builtin_abort ();
   return 0;
 }


	Jakub

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

end of thread, other threads:[~2016-05-06 15:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-06  7:37 [PATCH] Fix PR70941 Richard Biener
2016-05-06 15:25 ` Jakub Jelinek

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).