summaryrefslogtreecommitdiff
path: root/gcc/fold-const.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r--gcc/fold-const.c21
1 files changed, 13 insertions, 8 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 7cf132b2179..4dc4ad72e3c 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -7961,19 +7961,24 @@ fold_unary (enum tree_code code, tree type, tree op0)
/* For integral conversions with the same precision or pointer
conversions use a NOP_EXPR instead. */
- if ((INTEGRAL_TYPE_P (type) && INTEGRAL_TYPE_P (TREE_TYPE (op0))
- && TYPE_PRECISION (type) == TYPE_PRECISION (TREE_TYPE (op0))
- /* Do not muck with VIEW_CONVERT_EXPRs that convert from
- a sub-type to its base type as generated by the Ada FE. */
- && !TREE_TYPE (TREE_TYPE (op0)))
- || (POINTER_TYPE_P (type) && POINTER_TYPE_P (TREE_TYPE (op0))))
+ if ((INTEGRAL_TYPE_P (type)
+ || POINTER_TYPE_P (type))
+ && (INTEGRAL_TYPE_P (TREE_TYPE (op0))
+ || POINTER_TYPE_P (TREE_TYPE (op0)))
+ && TYPE_PRECISION (type) == TYPE_PRECISION (TREE_TYPE (op0))
+ /* Do not muck with VIEW_CONVERT_EXPRs that convert from
+ a sub-type to its base type as generated by the Ada FE. */
+ && !(INTEGRAL_TYPE_P (TREE_TYPE (op0))
+ && TREE_TYPE (TREE_TYPE (op0))))
return fold_convert (type, op0);
/* Strip inner integral conversions that do not change the precision. */
if ((TREE_CODE (op0) == NOP_EXPR
|| TREE_CODE (op0) == CONVERT_EXPR)
- && INTEGRAL_TYPE_P (TREE_TYPE (op0))
- && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (op0, 0)))
+ && (INTEGRAL_TYPE_P (TREE_TYPE (op0))
+ || POINTER_TYPE_P (TREE_TYPE (op0)))
+ && (INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (op0, 0)))
+ || POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (op0, 0))))
&& (TYPE_PRECISION (TREE_TYPE (op0))
== TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op0, 0)))))
return fold_build1 (VIEW_CONVERT_EXPR, type, TREE_OPERAND (op0, 0));