aboutsummaryrefslogtreecommitdiff
path: root/libcpp/expr.c
diff options
context:
space:
mode:
authorJoseph Myers <joseph@codesourcery.com>2013-12-10 01:23:37 +0000
committerJoseph Myers <jsm28@gcc.gnu.org>2013-12-10 01:23:37 +0000
commit3a4efce7c246b190ef35a8ce1f108f572274521f (patch)
tree17fee4f3cb77d383b7ed61dc4891d6ab12174ac5 /libcpp/expr.c
parente73d2479dd03132a1147c013426ea8e88c10d2ff (diff)
downloadgcc-3a4efce7c246b190ef35a8ce1f108f572274521f.zip
gcc-3a4efce7c246b190ef35a8ce1f108f572274521f.tar.gz
gcc-3a4efce7c246b190ef35a8ce1f108f572274521f.tar.bz2
re PR preprocessor/55715 (bogus overflow warning for #if A-B when A<0 & B==minimum integer)
PR preprocessor/55715 libcpp: * expr.c (num_binary_op): Implement subtraction directly rather than with negation and falling through into addition case. gcc/testsuite: * gcc.dg/cpp/expr-overflow-1.c: New test. From-SVN: r205846
Diffstat (limited to 'libcpp/expr.c')
-rw-r--r--libcpp/expr.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/libcpp/expr.c b/libcpp/expr.c
index c009807..1e17b00 100644
--- a/libcpp/expr.c
+++ b/libcpp/expr.c
@@ -1836,7 +1836,22 @@ num_binary_op (cpp_reader *pfile, cpp_num lhs, cpp_num rhs, enum cpp_ttype op)
/* Arithmetic. */
case CPP_MINUS:
- rhs = num_negate (rhs, precision);
+ result.low = lhs.low - rhs.low;
+ result.high = lhs.high - rhs.high;
+ if (result.low > lhs.low)
+ result.high--;
+ result.unsignedp = lhs.unsignedp || rhs.unsignedp;
+ result.overflow = false;
+
+ result = num_trim (result, precision);
+ if (!result.unsignedp)
+ {
+ bool lhsp = num_positive (lhs, precision);
+ result.overflow = (lhsp != num_positive (rhs, precision)
+ && lhsp != num_positive (result, precision));
+ }
+ return result;
+
case CPP_PLUS:
result.low = lhs.low + rhs.low;
result.high = lhs.high + rhs.high;