From 6ffc0c0cf5ada5d74da5c0b68fade4b5ec0e944a Mon Sep 17 00:00:00 2001 From: Eric Botcazou Date: Thu, 21 Dec 2017 16:22:04 +0000 Subject: [PATCH] re PR c++/82872 (ICE in ignore_overflows on __PTRDIFF_MAX__ index) PR c++/82872 * convert.c (convert_to_integer_1) : Do not return the shared zero if the input has overflowed. From-SVN: r255944 --- gcc/ChangeLog | 6 ++++++ gcc/convert.c | 2 +- gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/c-c++-common/pr82872.c | 11 +++++++++++ 4 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/c-c++-common/pr82872.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index b1846acfde5..d364df4dd45 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2017-12-21 Eric Botcazou + + PR c++/82872 + * convert.c (convert_to_integer_1) : Do not return the + shared zero if the input has overflowed. + 2017-12-21 Kyrylo Tkachov * config/arm/driver-arm.c (arm_cpu_table): Specify dotprod diff --git a/gcc/convert.c b/gcc/convert.c index 0045c12ed31..25aa5adf880 100644 --- a/gcc/convert.c +++ b/gcc/convert.c @@ -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 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 932ff87b7ff..a60791172e8 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2017-12-21 Eric Botcazou + + * c-c++-common/pr82872.c: New test. + 2017-12-21 Jakub Jelinek 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 index 00000000000..745d6225585 --- /dev/null +++ b/gcc/testsuite/c-c++-common/pr82872.c @@ -0,0 +1,11 @@ +/* PR c++/82872 */ +/* { dg-do compile } */ + +#include + +struct S { int i, a[1]; }; + +size_t foo (void) +{ + return offsetof (struct S, a[__PTRDIFF_MAX__]); +} -- 2.30.2