re PR middle-end/81705 (UBSAN: yet another false positive)
authorRichard Biener <rguenther@suse.de>
Fri, 4 Aug 2017 10:33:39 +0000 (10:33 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Fri, 4 Aug 2017 10:33:39 +0000 (10:33 +0000)
2017-08-04  Richard Biener  <rguenther@suse.de>

PR middle-end/81705
* fold-const.c (fold_binary_loc): Properly restrict
minus_var0 && minus_var1 case when associating undefined overflow
entities.

* c-c++-common/ubsan/pr81705.c: New testcase.

From-SVN: r250866

gcc/ChangeLog
gcc/fold-const.c
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/ubsan/pr81705.c [new file with mode: 0644]

index 921430208447e1457342107be4497ddd233a072e..d9c0b0a357969b8c4a8b6b729ad7a7a05222ed16 100644 (file)
@@ -1,3 +1,10 @@
+2017-08-04  Richard Biener  <rguenther@suse.de>
+
+       PR middle-end/81705
+       * fold-const.c (fold_binary_loc): Properly restrict
+       minus_var0 && minus_var1 case when associating undefined overflow
+       entities.
+
 2017-08-04  Tom de Vries  <tom@codesourcery.com>
 
        * omp-simd-clone.c (simd_clone_adjust): Add missing edge probability.
index ed6c289a64b535ba6952ce78097fc6ea9bce75f0..53428b89454e766ab6f536f120b3424e596c0cb8 100644 (file)
@@ -9592,12 +9592,13 @@ fold_binary_loc (location_t loc,
          if (POINTER_TYPE_P (atype)
              || (INTEGRAL_TYPE_P (atype) && !TYPE_OVERFLOW_WRAPS (atype)))
            {
-             if (var0 && var1)
+             if ((var0 && var1) || (minus_var0 && minus_var1))
                {
                  /* ???  If split_tree would handle NEGATE_EXPR we could
-                    simplify this down to the var0/minus_var1 cases.  */
-                 tree tmp0 = var0;
-                 tree tmp1 = var1;
+                    simply reject these cases and the allowed cases would
+                    be the var0/minus_var1 ones.  */
+                 tree tmp0 = var0 ? var0 : minus_var0;
+                 tree tmp1 = var1 ? var1 : minus_var1;
                  bool one_neg = false;
 
                  if (TREE_CODE (tmp0) == NEGATE_EXPR)
index 1033cc7b1c36427189b783ddb822d65dc75788e3..f5ec59d754bfe740112dfa3f9d9f66418ee3628f 100644 (file)
@@ -1,3 +1,8 @@
+2017-08-04  Richard Biener  <rguenther@suse.de>
+
+       PR middle-end/81705
+       * c-c++-common/ubsan/pr81705.c: New testcase.
+
 2017-08-03  Bill Schmidt  <wschmidt@linux.vnet.ibm.com>
 
        * gcc.target/powerpc/bfp/scalar-cmp-exp-eq-2.c: Adjust for error
diff --git a/gcc/testsuite/c-c++-common/ubsan/pr81705.c b/gcc/testsuite/c-c++-common/ubsan/pr81705.c
new file mode 100644 (file)
index 0000000..081c741
--- /dev/null
@@ -0,0 +1,12 @@
+/* { dg-do run } */
+/* { dg-options "-fsanitize=undefined -fsanitize-undefined-trap-on-error" } */
+
+int var_4 = -1716607962;
+int var_14 = 943738830;
+volatile int a;
+int main()
+{
+  //  (-(-1716607962) - 516151698) - -(9403738830)
+  a = (-var_4 - 516151698) - -var_14;
+  return 0;
+}