From 9f30dff0eed2813ead7a2e2927e0eb8c333baf8b Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Tue, 21 Mar 2017 09:10:30 +0100 Subject: [PATCH] re PR middle-end/67338 (fold-const sanitizer runtime error in roundup_loc) PR c/67338 * fold-const.c (round_up_loc): Negate divisor in unsigned type to avoid UB. * gcc.dg/pr67338.c: New test. From-SVN: r246305 --- gcc/ChangeLog | 6 ++++++ gcc/fold-const.c | 2 +- gcc/testsuite/ChangeLog | 3 +++ gcc/testsuite/gcc.dg/pr67338.c | 4 ++++ 4 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/pr67338.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index afb4a523472..59be61f58e0 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2017-03-21 Jakub Jelinek + + PR c/67338 + * fold-const.c (round_up_loc): Negate divisor in unsigned type to + avoid UB. + 2017-03-20 Segher Boessenkool PR rtl-optimization/79910 diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 12445aa6e44..1a9a264fc26 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -14250,7 +14250,7 @@ round_up_loc (location_t loc, tree value, unsigned int divisor) overflow_p = TREE_OVERFLOW (value); val += divisor - 1; - val &= - (int) divisor; + val &= (int) -divisor; if (val == 0) overflow_p = true; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index c2dc55a42ef..69cf11200da 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,8 @@ 2017-03-21 Jakub Jelinek + PR c/67338 + * gcc.dg/pr67338.c: New test. + PR c++/35878 * g++.dg/init/pr35878_1.C: Rewrite directives to scan optimized dump instead of assembler. diff --git a/gcc/testsuite/gcc.dg/pr67338.c b/gcc/testsuite/gcc.dg/pr67338.c new file mode 100644 index 00000000000..0fdc3024e8e --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr67338.c @@ -0,0 +1,4 @@ +/* PR c/67338 */ +/* { dg-do compile { target *-*-linux* *-*-gnu* } } */ + +struct S { __attribute__((aligned (1 << 28))) double a; }; -- 2.30.2