re PR middle-end/67338 (fold-const sanitizer runtime error in roundup_loc)
authorJakub Jelinek <jakub@redhat.com>
Tue, 21 Mar 2017 08:10:30 +0000 (09:10 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 21 Mar 2017 08:10:30 +0000 (09:10 +0100)
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
gcc/fold-const.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr67338.c [new file with mode: 0644]

index afb4a52347224814f2326a12797548518ac7638b..59be61f58e0a6d7e9e0755b6da3de5d14af5e793 100644 (file)
@@ -1,3 +1,9 @@
+2017-03-21  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c/67338
+       * fold-const.c (round_up_loc): Negate divisor in unsigned type to
+       avoid UB.
+
 2017-03-20  Segher Boessenkool  <segher@kernel.crashing.org>
 
        PR rtl-optimization/79910
index 12445aa6e44f2bd63960626489adab3f056a96f1..1a9a264fc260c9ddf5fa0a8d3b246939566ecb38 100644 (file)
@@ -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;
 
index c2dc55a42efd3ef75d73b56d62f1dba14a20e7ee..69cf11200da2cdf7db19ff83709d5d9ccf4ecdcf 100644 (file)
@@ -1,5 +1,8 @@
 2017-03-21  Jakub Jelinek  <jakub@redhat.com>
 
+       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 (file)
index 0000000..0fdc302
--- /dev/null
@@ -0,0 +1,4 @@
+/* PR c/67338 */
+/* { dg-do compile { target *-*-linux* *-*-gnu* } } */
+
+struct S { __attribute__((aligned (1 << 28))) double a; };