diff options
author | Richard Guenther <rguenther@suse.de> | 2011-05-27 13:13:28 +0000 |
---|---|---|
committer | Richard Biener <rguenth@gcc.gnu.org> | 2011-05-27 13:13:28 +0000 |
commit | c2299dfe5337c92723ad8d6c92a41731badc6a0a (patch) | |
tree | 5a01789e8423444f6b3623d0f6a43454d41ffb54 | |
parent | a95b23b4290ffaa95614a10eb13123251bcd7e90 (diff) | |
download | gcc-c2299dfe5337c92723ad8d6c92a41731badc6a0a.zip gcc-c2299dfe5337c92723ad8d6c92a41731badc6a0a.tar.gz gcc-c2299dfe5337c92723ad8d6c92a41731badc6a0a.tar.bz2 |
re PR middle-end/49189 (infinite recursion in constant folder)
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.
From-SVN: r174330
-rw-r--r-- | gcc/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/fold-const.c | 18 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/testsuite/gnat.dg/bit_packed_array5.adb | 21 | ||||
-rw-r--r-- | gcc/testsuite/gnat.dg/bit_packed_array5.ads | 16 |
5 files changed, 60 insertions, 7 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 9574435..6271933 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +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. + 2011-05-27 Bernd Schmidt <bernds@codesourcery.com> * haifa-sched.c (sched_scan_info): Remove. diff --git a/gcc/fold-const.c b/gcc/fold-const.c index ebb1d34..9a3f8cb 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -7660,15 +7660,19 @@ fold_unary_loc (location_t loc, enum tree_code code, tree type, tree op0) 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. */ + 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 fold_build2_loc (loc, TREE_CODE (op0), type, - TREE_OPERAND (op0, 0), - TREE_OPERAND (op0, 1)); + return 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)); + 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. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index a6ce74b..2bf68b3 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2011-05-27 Richard Guenther <rguenther@suse.de> + + PR middle-end/49189 + * gnat.dg/bit_packed_array5.adb: New testcase. + * gnat.dg/bit_packed_array5.ads: Likewise. + 2011-05-26 Jason Merrill <jason@redhat.com> * g++.dg/cpp0x/friend1.C: New. diff --git a/gcc/testsuite/gnat.dg/bit_packed_array5.adb b/gcc/testsuite/gnat.dg/bit_packed_array5.adb new file mode 100644 index 0000000..de574fb --- /dev/null +++ b/gcc/testsuite/gnat.dg/bit_packed_array5.adb @@ -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; diff --git a/gcc/testsuite/gnat.dg/bit_packed_array5.ads b/gcc/testsuite/gnat.dg/bit_packed_array5.ads new file mode 100644 index 0000000..8d335f0 --- /dev/null +++ b/gcc/testsuite/gnat.dg/bit_packed_array5.ads @@ -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; |