summaryrefslogtreecommitdiff
path: root/libcpp
diff options
context:
space:
mode:
authorjsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4>2013-12-10 01:23:37 +0000
committerjsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4>2013-12-10 01:23:37 +0000
commite7d8908f32677b7b1344a5984a042023965a98e1 (patch)
tree17fee4f3cb77d383b7ed61dc4891d6ab12174ac5 /libcpp
parentf7d6f2680376abc3fb4130ce1636bc2a5f2257f9 (diff)
downloadgcc-e7d8908f32677b7b1344a5984a042023965a98e1.tar.gz
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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@205846 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libcpp')
-rw-r--r--libcpp/ChangeLog6
-rw-r--r--libcpp/expr.c17
2 files changed, 22 insertions, 1 deletions
diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog
index c3391b4959d..4a06d0c3a63 100644
--- a/libcpp/ChangeLog
+++ b/libcpp/ChangeLog
@@ -1,3 +1,9 @@
+2013-12-09 Joseph Myers <joseph@codesourcery.com>
+
+ PR preprocessor/55715
+ * expr.c (num_binary_op): Implement subtraction directly rather
+ than with negation and falling through into addition case.
+
2013-11-18 Bill Schmidt <wschmidt@linux.vnet.ibm.com>
* lex.c (search_line_fast): Correct for little endian.
diff --git a/libcpp/expr.c b/libcpp/expr.c
index c0098073ab8..1e17b005dee 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;