From: Marek Polacek Date: Wed, 19 Nov 2014 12:03:04 +0000 (+0000) Subject: re PR middle-end/63879 (ICE compiling Linux Kernel fs/ext3/namei.c with -fsanitize... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=3902bce0490c5daddffa7c502d5b9ae2a4d32178;p=gcc.git re PR middle-end/63879 (ICE compiling Linux Kernel fs/ext3/namei.c with -fsanitize=undefined) PR sanitizer/63879 * fold-const.c (negate_expr_p) : Return !TYPE_OVERFLOW_SANITIZED. (fold_negate_expr) : Fold when overflow does not trap and when overflow wraps, or when SANITIZE_SI_OVERFLOW is 0. * c-c++-common/ubsan/pr63879-1.c: New test. * c-c++-common/ubsan/pr63879-2.c: New test. From-SVN: r217766 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index a4953e9b63b..0e9638888d6 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,12 @@ +2014-11-19 Marek Polacek + + PR sanitizer/63879 + * fold-const.c (negate_expr_p) : Return + !TYPE_OVERFLOW_SANITIZED. + (fold_negate_expr) : Fold when overflow + does not trap and when overflow wraps, or when SANITIZE_SI_OVERFLOW + is 0. + 2014-11-19 Ilya Tocar * collect2.c (main): Don't call fatal_error before diff --git a/gcc/fold-const.c b/gcc/fold-const.c index f6fb8af8084..9183430205b 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -408,9 +408,11 @@ negate_expr_p (tree t) && TYPE_OVERFLOW_WRAPS (type)); case FIXED_CST: - case NEGATE_EXPR: return true; + case NEGATE_EXPR: + return !TYPE_OVERFLOW_SANITIZED (type); + case REAL_CST: /* We want to canonicalize to positive real constants. Pretend that only negative ones can be easily negated. */ @@ -555,7 +557,8 @@ fold_negate_expr (location_t loc, tree t) tem = fold_negate_const (t, type); if (TREE_OVERFLOW (tem) == TREE_OVERFLOW (t) || (!TYPE_OVERFLOW_TRAPS (type) - && (flag_sanitize & SANITIZE_SI_OVERFLOW) == 0)) + && TYPE_OVERFLOW_WRAPS (type)) + || (flag_sanitize & SANITIZE_SI_OVERFLOW) == 0) return tem; break; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 35cb09ce4d3..c3f1bf1e36f 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2014-11-19 Marek Polacek + + PR sanitizer/63879 + * c-c++-common/ubsan/pr63879-1.c: New test. + * c-c++-common/ubsan/pr63879-2.c: New test. + 2014-11-19 Tom de Vries PR tree-optimization/62167 diff --git a/gcc/testsuite/c-c++-common/ubsan/pr63879-1.c b/gcc/testsuite/c-c++-common/ubsan/pr63879-1.c new file mode 100644 index 00000000000..2035849a8ce --- /dev/null +++ b/gcc/testsuite/c-c++-common/ubsan/pr63879-1.c @@ -0,0 +1,23 @@ +/* PR sanitizer/63879 */ +/* { dg-do compile } */ +/* { dg-options "-fsanitize=undefined" } */ + +struct A +{ + int inode; +} * a; +int b, c; +void +fn1 () +{ + int d = 0; + while (b) + { + if (a->inode) + d++; + a = 0; + } + c = d - 1; + for (; c >= 0; c--) + ; +} diff --git a/gcc/testsuite/c-c++-common/ubsan/pr63879-2.c b/gcc/testsuite/c-c++-common/ubsan/pr63879-2.c new file mode 100644 index 00000000000..34eb8e79d67 --- /dev/null +++ b/gcc/testsuite/c-c++-common/ubsan/pr63879-2.c @@ -0,0 +1,13 @@ +/* PR sanitizer/63879 */ +/* { dg-do compile } */ +/* { dg-options "-fsanitize=undefined" } */ + +int a; +void +fn1 () +{ + int b = 2; + for (; a;) + while (b >= 0) + b--; +}