diff options
author | rguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4> | 2014-07-28 08:47:38 +0000 |
---|---|---|
committer | rguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4> | 2014-07-28 08:47:38 +0000 |
commit | 2069f8e125ae1dc7bb290dde2a04c64d213f12b9 (patch) | |
tree | 50c7abb69f3b2210ca85d4268d2632528cf587c0 | |
parent | 427fa425045eb4955c3b061401980ae511921f2a (diff) | |
download | gcc-2069f8e125ae1dc7bb290dde2a04c64d213f12b9.tar.gz |
2014-07-28 Richard Biener <rguenther@suse.de>
PR middle-end/52478
* optabs.c (gen_int_libfunc): For -ftrapv libfuncs make
sure to register SImode ones, not only >= word_mode ones.
* expr.c (expand_expr_real_2): When expanding -ftrapv
binops do not use OPTAB_LIB_WIDEN.
* gcc.dg/torture/ftrapv-1.c: New testcase.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@213117 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r-- | gcc/ChangeLog | 8 | ||||
-rw-r--r-- | gcc/expr.c | 4 | ||||
-rw-r--r-- | gcc/optabs.c | 8 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/torture/ftrapv-1.c | 37 |
5 files changed, 59 insertions, 3 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 56d3b250a03..fcb95b1a9cb 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2014-07-28 Richard Biener <rguenther@suse.de> + + PR middle-end/52478 + * optabs.c (gen_int_libfunc): For -ftrapv libfuncs make + sure to register SImode ones, not only >= word_mode ones. + * expr.c (expand_expr_real_2): When expanding -ftrapv + binops do not use OPTAB_LIB_WIDEN. + 2014-07-28 Richard Sandiford <rdsandiford@googlemail.com> PR middle-end/61919 diff --git a/gcc/expr.c b/gcc/expr.c index d8328eebfbf..de0da345198 100644 --- a/gcc/expr.c +++ b/gcc/expr.c @@ -9212,7 +9212,9 @@ expand_expr_real_2 (sepops ops, rtx target, enum machine_mode tmode, if (modifier == EXPAND_STACK_PARM) target = 0; temp = expand_binop (mode, this_optab, op0, op1, target, - unsignedp, OPTAB_LIB_WIDEN); + unsignedp, + trapv_binoptab_p (this_optab) + ? OPTAB_LIB : OPTAB_LIB_WIDEN); gcc_assert (temp); /* Bitwise operations do not need bitfield reduction as we expect their operands being properly truncated. */ diff --git a/gcc/optabs.c b/gcc/optabs.c index 7ee84c4348c..c7bd9d07485 100644 --- a/gcc/optabs.c +++ b/gcc/optabs.c @@ -5559,13 +5559,17 @@ gen_int_libfunc (optab optable, const char *opname, char suffix, enum machine_mode mode) { int maxsize = 2 * BITS_PER_WORD; + int minsize = BITS_PER_WORD; if (GET_MODE_CLASS (mode) != MODE_INT) return; if (maxsize < LONG_LONG_TYPE_SIZE) maxsize = LONG_LONG_TYPE_SIZE; - if (GET_MODE_CLASS (mode) != MODE_INT - || GET_MODE_BITSIZE (mode) < BITS_PER_WORD + if (minsize > INT_TYPE_SIZE + && (trapv_binoptab_p (optable) + || trapv_unoptab_p (optable))) + minsize = INT_TYPE_SIZE; + if (GET_MODE_BITSIZE (mode) < minsize || GET_MODE_BITSIZE (mode) > maxsize) return; gen_libfunc (optable, opname, suffix, mode); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 68499d9eed0..014896c627c 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,10 @@ 2014-07-28 Richard Biener <rguenther@suse.de> + PR middle-end/52478 + * gcc.dg/torture/ftrapv-1.c: New testcase. + +2014-07-28 Richard Biener <rguenther@suse.de> + PR tree-optimization/61921 * gfortran.dg/pr61921.f90: New testcase. diff --git a/gcc/testsuite/gcc.dg/torture/ftrapv-1.c b/gcc/testsuite/gcc.dg/torture/ftrapv-1.c new file mode 100644 index 00000000000..4fdccd887ae --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/ftrapv-1.c @@ -0,0 +1,37 @@ +/* { dg-do run } */ +/* { dg-additional-options "-ftrapv" } */ +/* { dg-require-effective-target trapping } */ +/* { dg-require-fork } */ + +#include <stdlib.h> +#include <unistd.h> +#include <sys/types.h> +#include <sys/wait.h> + +/* Verify SImode operations properly trap. PR middle-end/52478 */ + +/* Disallow inlining/cloning which would constant propagate and trigger + unrelated bugs. */ + +int __attribute__((noinline,noclone)) +iaddv (int a, int b) +{ + return a + b; +} + +int main(void) +{ + pid_t child = fork (); + int status = 0; + if (child == 0) + { + volatile int x = iaddv (__INT_MAX__, 1); + exit (0); + } + else if (child == -1) + return 0; + if (wait (&status) == child + && status == 0) + abort (); + return 0; +} |