Skip to content

Commit

Permalink
sl/symproc: improve handling of integer overflows
Browse files Browse the repository at this point in the history
This commit makes test-024[67] work properly with gcc-4.6.4.
  • Loading branch information
kdudka committed Nov 2, 2015
1 parent 653bcd6 commit 85da657
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
19 changes: 15 additions & 4 deletions build-aux/gcc-4.7.3.patch
@@ -1,8 +1,19 @@
vra/tests-overall/test-0062.c.ref | 12 +++---------
vra/tests-overall/test-0071.c.ref | 12 +++---------
vra/tests-overall/test-0072.c.ref | 28 ++++++++++++++--------------
3 files changed, 20 insertions(+), 32 deletions(-)
tests/predator-regre/test-0247.err.oom | 2 +-
vra/tests-overall/test-0062.c.ref | 12 +++---------
vra/tests-overall/test-0071.c.ref | 12 +++---------
vra/tests-overall/test-0072.c.ref | 28 ++++++++++++++--------------
4 files changed, 21 insertions(+), 33 deletions(-)

diff --git a/tests/predator-regre/test-0247.err.oom b/tests/predator-regre/test-0247.err.oom
index 333f328..32ceb5b 100644
--- a/tests/predator-regre/test-0247.err.oom
+++ b/tests/predator-regre/test-0247.err.oom
@@ -1,4 +1,4 @@
-test-0247.c:13: error: dereference of NULL value with offset 4294967296B
+test-0247.c:13: error: dereference of NULL value
test-0247.c:13: error: dereference of NULL value with offset 4B
test-0247.c:13: error: dereference of NULL value with offset 8B
test-0247.c:13: error: dereference of NULL value with offset 12B
diff --git a/vra/tests-overall/test-0062.c.ref b/vra/tests-overall/test-0062.c.ref
index 21f404a..943dd94 100644
--- a/vra/tests-overall/test-0062.c.ref
Expand Down
13 changes: 13 additions & 0 deletions sl/symproc.cc
Expand Up @@ -736,6 +736,13 @@ TValId integralEncoder(
if (isUnsigned) {
CL_DEBUG_MSG(loc, "converting negative number to unsigned");
rng += IR::rngFromNum(loLimit);
if (rng.lo < IR::Int0) {
// more than one addition needed (we have to divide)
const IR::TInt num = IR::Int1 + (rng.lo / loLimit);
rng += IR::rngFromNum(num * loLimit);
CL_BREAK_IF(rng.lo < IR::Int0);
}

loLimit = IR::Int0;
}
if (rng.lo < -loLimit) {
Expand All @@ -750,6 +757,12 @@ TValId integralEncoder(
if (isUnsigned) {
CL_DEBUG_MSG(loc, "wrapping an unsigned number");
rng -= IR::rngFromNum(hiLimit);
if (hiLimit <= rng.hi) {
// more than one subtraction needed (we have to divide)
const IR::TInt num = IR::Int1 + (rng.hi / hiLimit);
rng -= IR::rngFromNum(num * hiLimit);
CL_BREAK_IF(hiLimit <= rng.hi);
}
}
if (hiLimit <= rng.hi) {
CL_WARN_MSG(loc, "possible overflow of " << sig << " integer");
Expand Down
2 changes: 1 addition & 1 deletion switch-host-gcc.sh
Expand Up @@ -16,7 +16,7 @@ usage() {
build of host GCC. The host GCC needs to be built with the support for GCC
plug-ins. The recommended version of host GCC is 4.9.3 but Predator can be
loaded also into older versions of GCC (plug-ins are supported since 4.5.0).
For host GCC 4.6.x and older, please use the compatibility patches in the
For host GCC 4.7.x and older, please use the compatibility patches in the
build-aux directory.
GCC_HOST is a gcc(1) executable file that is built with the support for
Expand Down

0 comments on commit 85da657

Please sign in to comment.