summaryrefslogtreecommitdiff
path: root/gcc/fold-const.c
diff options
context:
space:
mode:
authorrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>2011-05-27 13:13:28 +0000
committerrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>2011-05-27 13:13:28 +0000
commitca356addae64845ddaa7af2c2aef23c99fb48151 (patch)
tree5a01789e8423444f6b3623d0f6a43454d41ffb54 /gcc/fold-const.c
parent52d7e28c26c1f136df0ee1a1993c9be371d52462 (diff)
downloadgcc-ca356addae64845ddaa7af2c2aef23c99fb48151.tar.gz
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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@174330 138bc75d-0d04-0410-961f-82ee72b054a4
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 ebb1d34d5f4..9a3f8cb0fec 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. */