]> gcc.gnu.org Git - gcc.git/commitdiff
c/95141 - fix bogus integer overflow warning
authorRichard Biener <rguenther@suse.de>
Tue, 19 May 2020 05:58:33 +0000 (07:58 +0200)
committerRichard Biener <rguenther@suse.de>
Wed, 20 May 2020 07:39:49 +0000 (09:39 +0200)
This fixes an integer overflow warning that ultimatively happens because
of TREE_OVERFLOW propagating through transforms and the existing guard
against this,

375           if (TREE_OVERFLOW_P (ret)
376               && !TREE_OVERFLOW_P (op0)
377               && !TREE_OVERFLOW_P (op1))
378             overflow_warning (EXPR_LOC_OR_LOC (expr, input_location,

being insufficient.  Rather than trying to use sth like walk_tree to
exhaustively walk operands (with the possibility of introducing
quadraticness when folding larger expressions recursively) the
following amends the above with an ad-hoc test for a binary op0
with a possibly constant op1.

2020-05-30  Richard Biener  <rguenther@suse.de>

PR c/95141
gcc/c
* c-fold.c (c_fully_fold_internal): Enhance guard on
overflow_warning.

gcc/testsuite
* gcc.dg/pr95141.c: New testcase.

gcc/ChangeLog
gcc/c/c-fold.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr95141.c [new file with mode: 0644]

index fdaa94ae8b94ae84aebf3f36ea087c9d49a2c487..3133b3c4ef1091bd8492c8377013920b9bbac045 100644 (file)
@@ -1,3 +1,9 @@
+2020-05-30  Richard Biener  <rguenther@suse.de>
+
+       PR c/95141
+       * c-fold.c (c_fully_fold_internal): Enhance guard on
+       overflow_warning.
+
 2020-05-20  Kito Cheng  <kito.cheng@sifive.com>
 
        PR target/90811
index 63becfeaf2c1535fa3dd49c12519b941bed5dc71..bd21d2470511ff34473112664e50a66789f97e9b 100644 (file)
@@ -374,6 +374,7 @@ c_fully_fold_internal (tree expr, bool in_init, bool *maybe_const_operands,
        ret = fold (expr);
       if (TREE_OVERFLOW_P (ret)
          && !TREE_OVERFLOW_P (op0)
+         && !(BINARY_CLASS_P (op0) && TREE_OVERFLOW_P (TREE_OPERAND (op0, 1)))
          && !TREE_OVERFLOW_P (op1))
        overflow_warning (EXPR_LOC_OR_LOC (expr, input_location), ret, expr);
       if (code == LSHIFT_EXPR
index 48671f1105a2baa3c8e03db7b2b1e38f159c445d..401025718ee1d8935a5f5c8081430fc0dc3284b1 100644 (file)
@@ -1,3 +1,8 @@
+2020-05-30  Richard Biener  <rguenther@suse.de>
+
+       PR c/95141
+       * gcc.dg/pr95141.c: New testcase.
+
 2020-05-19  Alex Coplan  <alex.coplan@arm.com>
 
        PR target/94591
diff --git a/gcc/testsuite/gcc.dg/pr95141.c b/gcc/testsuite/gcc.dg/pr95141.c
new file mode 100644 (file)
index 0000000..b6cbba2
--- /dev/null
@@ -0,0 +1,8 @@
+/* { dg-do compile } */
+
+#include <stdint.h>
+
+uint64_t test(uint8_t IA1)
+{
+  return (uint8_t)(IA1 & 158) & 1UL; /* { dg-bogus "integer overflow" } */
+}
This page took 0.129074 seconds and 5 git commands to generate.