aboutsummaryrefslogtreecommitdiff
path: root/gcc/fold-const.c
diff options
context:
space:
mode:
authorRichard Guenther <rguenther@suse.de>2011-05-27 13:13:28 +0000
committerRichard Biener <rguenth@gcc.gnu.org>2011-05-27 13:13:28 +0000
commitc2299dfe5337c92723ad8d6c92a41731badc6a0a (patch)
tree5a01789e8423444f6b3623d0f6a43454d41ffb54 /gcc/fold-const.c
parenta95b23b4290ffaa95614a10eb13123251bcd7e90 (diff)
downloadgcc-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
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r--gcc/fold-const.c18
1 files changed, 11 insertions, 7 deletions
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. */