re PR c++/82872 (ICE in ignore_overflows on __PTRDIFF_MAX__ index)
authorEric Botcazou <ebotcazou@adacore.com>
Thu, 21 Dec 2017 16:22:04 +0000 (16:22 +0000)
committerEric Botcazou <ebotcazou@gcc.gnu.org>
Thu, 21 Dec 2017 16:22:04 +0000 (16:22 +0000)
PR c++/82872
* convert.c (convert_to_integer_1) <POINTER_TYPE>: Do not return the
shared zero if the input has overflowed.

From-SVN: r255944

gcc/ChangeLog
gcc/convert.c
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/pr82872.c [new file with mode: 0644]

index b1846acfde5c3052db52235f9fa173af42b29b97..d364df4dd45fdbed02226b2ec48291ef23d4ed49 100644 (file)
@@ -1,3 +1,9 @@
+2017-12-21  Eric Botcazou  <ebotcazou@adacore.com>
+
+       PR c++/82872
+       * convert.c (convert_to_integer_1) <POINTER_TYPE>: Do not return the
+       shared zero if the input has overflowed.
+
 2017-12-21  Kyrylo Tkachov  <kyrylo.tkachov@arm.com>
 
        * config/arm/driver-arm.c (arm_cpu_table): Specify dotprod
index 0045c12ed312e12413c74e82ad5772dfec9b04e0..25aa5adf88026267974e26f71f094fca10ca0f2c 100644 (file)
@@ -671,7 +671,7 @@ convert_to_integer_1 (tree type, tree expr, bool dofold)
     {
     case POINTER_TYPE:
     case REFERENCE_TYPE:
-      if (integer_zerop (expr))
+      if (integer_zerop (expr) && !TREE_OVERFLOW (expr))
        return build_int_cst (type, 0);
 
       /* Convert to an unsigned integer of the correct width first, and from
index 932ff87b7ff9dbc6a885f818ca674c7742d8d9d2..a60791172e8629924b221a8b0bb78db2be69ae55 100644 (file)
@@ -1,3 +1,7 @@
+2017-12-21  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * c-c++-common/pr82872.c: New test.
+
 2017-12-21  Jakub Jelinek  <jakub@redhat.com>
 
        PR rtl-optimization/82973
diff --git a/gcc/testsuite/c-c++-common/pr82872.c b/gcc/testsuite/c-c++-common/pr82872.c
new file mode 100644 (file)
index 0000000..745d622
--- /dev/null
@@ -0,0 +1,11 @@
+/* PR c++/82872 */
+/* { dg-do compile } */
+
+#include <stddef.h>
+
+struct S { int i, a[1]; };
+
+size_t foo (void)
+{
+  return offsetof (struct S, a[__PTRDIFF_MAX__]);
+}