public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Fix PR49189
@ 2011-05-27 14:01 Richard Guenther
  2011-05-27 16:42 ` Eric Botcazou
  0 siblings, 1 reply; 2+ messages in thread
From: Richard Guenther @ 2011-05-27 14:01 UTC (permalink / raw)
  To: gcc-patches


This fixes PR49189 by re-installing the non-folding of
conversions of comparison results.

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

Richard.

2011-05-27  Richard Guenther  <rguenther@suse.de>

	PR middle-end/49189
	* fold-const.c (fold_unary_loc): Do not re-fold folding conversions
	of comparisons.

	* gnat.dg/bit_packed_array5.adb: New testcase.
	* gnat.dg/bit_packed_array5.ads: Likewise.

Index: gcc/fold-const.c
===================================================================
*** gcc/fold-const.c	(revision 174326)
--- gcc/fold-const.c	(working copy)
*************** fold_unary_loc (location_t loc, enum tre
*** 7660,7674 ****
        if (COMPARISON_CLASS_P (op0))
  	{
  	  /* If we have (type) (a CMP b) and type is an integral type, return
! 	     new expression involving the new type.  */
  	  if (INTEGRAL_TYPE_P (type))
! 	    return fold_build2_loc (loc, TREE_CODE (op0), type,
! 				    TREE_OPERAND (op0, 0),
! 				    TREE_OPERAND (op0, 1));
  	  else
! 	    return fold_build3_loc (loc, COND_EXPR, type, op0,
! 				    fold_convert (type, boolean_true_node),
! 				    fold_convert (type, boolean_false_node));
  	}
  
        /* Handle cases of two conversions in a row.  */
--- 7660,7678 ----
        if (COMPARISON_CLASS_P (op0))
  	{
  	  /* If we have (type) (a CMP b) and type is an integral type, return
! 	     new expression involving the new type.  Canonicalize
! 	     (type) (a CMP b) to (a CMP b) ? (type) true : (type) false for
! 	     non-integral type.
! 	     Do not fold the result as that would not simplify further, also
! 	     folding again results in recursions.  */
  	  if (INTEGRAL_TYPE_P (type))
! 	    return build2_loc (loc, TREE_CODE (op0), type,
! 			       TREE_OPERAND (op0, 0),
! 			       TREE_OPERAND (op0, 1));
  	  else
! 	    return build3_loc (loc, COND_EXPR, type, op0,
! 			       fold_convert (type, boolean_true_node),
! 			       fold_convert (type, boolean_false_node));
  	}
  
        /* Handle cases of two conversions in a row.  */
Index: gcc/testsuite/gnat.dg/bit_packed_array5.adb
===================================================================
*** gcc/testsuite/gnat.dg/bit_packed_array5.adb	(revision 0)
--- gcc/testsuite/gnat.dg/bit_packed_array5.adb	(revision 0)
***************
*** 0 ****
--- 1,21 ----
+ with System;
+ 
+ package body Bit_Packed_Array5 is
+ 
+    function Inv (Word : Word_Type) return Word_Type is
+       W : Word_Type := Word;
+       pragma Volatile (W);
+ 
+       A_W : constant System.Address := W'Address;
+ 
+       V : Short_Bit_Array_Type;
+       for V'Address use A_W;
+       pragma Volatile (V);
+    begin
+       for I in V'Range loop
+           V (I) := not V (I);
+       end loop;
+       return W;
+    end;
+ 
+ end Bit_Packed_Array5;
Index: gcc/testsuite/gnat.dg/bit_packed_array5.ads
===================================================================
*** gcc/testsuite/gnat.dg/bit_packed_array5.ads	(revision 0)
--- gcc/testsuite/gnat.dg/bit_packed_array5.ads	(revision 0)
***************
*** 0 ****
--- 1,16 ----
+ -- { dg-do compile }
+ 
+ package Bit_Packed_Array5 is
+ 
+    type Bit_Array is array (Integer range <>) of Boolean;
+    pragma Pack (Bit_Array);
+ 
+    type Short_Bit_Array_Type is new Bit_Array (0 .. 15);
+    for Short_Bit_Array_Type'Size use 16;
+ 
+    type Word_Type is range 0 .. 65535;
+    for Word_Type'Size use 16;
+ 
+    function Inv (Word : Word_Type) return Word_Type;
+ 
+ end Bit_Packed_Array5;

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

* Re: [PATCH] Fix PR49189
  2011-05-27 14:01 [PATCH] Fix PR49189 Richard Guenther
@ 2011-05-27 16:42 ` Eric Botcazou
  0 siblings, 0 replies; 2+ messages in thread
From: Eric Botcazou @ 2011-05-27 16:42 UTC (permalink / raw)
  To: Richard Guenther; +Cc: gcc-patches

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

> 2011-05-27  Richard Guenther  <rguenther@suse.de>
>
> 	PR middle-end/49189
> 	* fold-const.c (fold_unary_loc): Do not re-fold folding conversions
> 	of comparisons.
>
> 	* gnat.dg/bit_packed_array5.adb: New testcase.
> 	* gnat.dg/bit_packed_array5.ads: Likewise.

Thanks a lot!  I managed to mess up the dg stuff... fixed thusly, applied.


2011-05-27  Eric Botcazou  <ebotcazou@adacore.com>

	* gnat.dg/bit_packed_array5.ads: Move dg directive to...
	* gnat.dg/bit_packed_array5.adb: ...here.


-- 
Eric Botcazou

[-- Attachment #2: p.diff --]
[-- Type: text/x-diff, Size: 634 bytes --]

Index: gnat.dg/bit_packed_array5.adb
===================================================================
--- gnat.dg/bit_packed_array5.adb	(revision 174335)
+++ gnat.dg/bit_packed_array5.adb	(working copy)
@@ -1,3 +1,5 @@
+-- { dg-do compile }
+
 with System;
 
 package body Bit_Packed_Array5 is
Index: gnat.dg/bit_packed_array5.ads
===================================================================
--- gnat.dg/bit_packed_array5.ads	(revision 174335)
+++ gnat.dg/bit_packed_array5.ads	(working copy)
@@ -1,5 +1,3 @@
--- { dg-do compile }
-
 package Bit_Packed_Array5 is
 
    type Bit_Array is array (Integer range <>) of Boolean;

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

end of thread, other threads:[~2011-05-27 14:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-05-27 14:01 [PATCH] Fix PR49189 Richard Guenther
2011-05-27 16:42 ` Eric Botcazou

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