From 396e67d21a3194da9d036bdb67e74edfd1030d3f Mon Sep 17 00:00:00 2001 From: Eric Botcazou Date: Thu, 28 May 2015 15:45:08 +0000 Subject: utils.c (max_size): Add special code to deal with the subtraction of a "negative" value in an... * gcc-interface/utils.c (max_size) : Add special code to deal with the subtraction of a "negative" value in an unsigned type. From-SVN: r223837 --- gcc/ada/gcc-interface/utils.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'gcc/ada/gcc-interface/utils.c') diff --git a/gcc/ada/gcc-interface/utils.c b/gcc/ada/gcc-interface/utils.c index 7615d2d..0871c3c 100644 --- a/gcc/ada/gcc-interface/utils.c +++ b/gcc/ada/gcc-interface/utils.c @@ -3443,9 +3443,23 @@ max_size (tree exp, bool max_p) if ((code == MINUS_EXPR || code == PLUS_EXPR) && TREE_CODE (lhs) == INTEGER_CST && TREE_OVERFLOW (lhs) - && !TREE_CONSTANT (rhs)) + && TREE_CODE (rhs) != INTEGER_CST) return lhs; + /* If we are going to subtract a "negative" value in an unsigned type, + do the operation as an addition of the negated value, in order to + avoid creating a spurious overflow below. */ + if (code == MINUS_EXPR + && TYPE_UNSIGNED (type) + && TREE_CODE (rhs) == INTEGER_CST + && !TREE_OVERFLOW (rhs) + && tree_int_cst_sign_bit (rhs) != 0) + { + rhs = fold_build1 (NEGATE_EXPR, type, rhs); + code = PLUS_EXPR; + } + + /* We need to detect overflows so we call size_binop here. */ return size_binop (code, lhs, rhs); } -- cgit v1.1