public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [patch] Fix PR C++/82872
@ 2017-12-21 15:52 Eric Botcazou
  2017-12-21 15:53 ` Jason Merrill
  0 siblings, 1 reply; 2+ messages in thread
From: Eric Botcazou @ 2017-12-21 15:52 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 1468 bytes --]

Hi,

this is an ICE in the C++ FE on an offsetof construct with __PTRDIFF_MAX__ and 
it happens only with this specific index:

In file included from pr82872.c:4:
pr82872.c: In function 'size_t foo()':
pr82872.c:10:10: internal compiler error: in ignore_overflows, at cp/cvt.c:583
   return offsetof (struct S, a[__PTRDIFF_MAX__]);
          ^~~~~~~~
0x65ef7f ignore_overflows
        /home/eric/svn/gcc/gcc/cp/cvt.c:583
0x661bcc ocp_convert(tree_node*, tree_node*, int, int, int)
        /home/eric/svn/gcc/gcc/cp/cvt.c:817
0x6636e0 convert(tree_node*, tree_node*)
        /home/eric/svn/gcc/gcc/cp/cvt.c:1580
0x882b62 fold_offsetof(tree_node*)
        /home/eric/svn/gcc/gcc/c-family/c-common.c:6282
0x801c0c finish_offsetof(tree_node*, tree_node*, unsigned int)
        /home/eric/svn/gcc/gcc/cp/semantics.c:4041
0x74596b cp_parser_builtin_offsetof
        /home/eric/svn/gcc/gcc/cp/parser.c:9828

The C++ FE is quite picky about constant integer overflow during conversion 
operations and checks that they can only _introduce_ overflows and never make 
them disappear, the latter case occuring here in convert_to_integer_1.

Tested on x86_64-suse-linux, OK for the mainline?


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  Eric Botcazou  <ebotcazou@adacore.com>

	* c-c++-common/pr82872.c: New test.

-- 
Eric Botcazou

[-- Attachment #2: pr82872.c --]
[-- Type: text/x-csrc, Size: 165 bytes --]

/* 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__]);
}

[-- Attachment #3: pr82872.diff --]
[-- Type: text/x-patch, Size: 469 bytes --]

Index: convert.c
===================================================================
--- convert.c	(revision 255850)
+++ convert.c	(working copy)
@@ -671,7 +671,7 @@ convert_to_integer_1 (tree type, tree ex
     {
     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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [patch] Fix PR C++/82872
  2017-12-21 15:52 [patch] Fix PR C++/82872 Eric Botcazou
@ 2017-12-21 15:53 ` Jason Merrill
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2017-12-21 15:53 UTC (permalink / raw)
  To: Eric Botcazou; +Cc: gcc-patches List

OK.

On Thu, Dec 21, 2017 at 10:51 AM, Eric Botcazou <ebotcazou@adacore.com> wrote:
> Hi,
>
> this is an ICE in the C++ FE on an offsetof construct with __PTRDIFF_MAX__ and
> it happens only with this specific index:
>
> In file included from pr82872.c:4:
> pr82872.c: In function 'size_t foo()':
> pr82872.c:10:10: internal compiler error: in ignore_overflows, at cp/cvt.c:583
>    return offsetof (struct S, a[__PTRDIFF_MAX__]);
>           ^~~~~~~~
> 0x65ef7f ignore_overflows
>         /home/eric/svn/gcc/gcc/cp/cvt.c:583
> 0x661bcc ocp_convert(tree_node*, tree_node*, int, int, int)
>         /home/eric/svn/gcc/gcc/cp/cvt.c:817
> 0x6636e0 convert(tree_node*, tree_node*)
>         /home/eric/svn/gcc/gcc/cp/cvt.c:1580
> 0x882b62 fold_offsetof(tree_node*)
>         /home/eric/svn/gcc/gcc/c-family/c-common.c:6282
> 0x801c0c finish_offsetof(tree_node*, tree_node*, unsigned int)
>         /home/eric/svn/gcc/gcc/cp/semantics.c:4041
> 0x74596b cp_parser_builtin_offsetof
>         /home/eric/svn/gcc/gcc/cp/parser.c:9828
>
> The C++ FE is quite picky about constant integer overflow during conversion
> operations and checks that they can only _introduce_ overflows and never make
> them disappear, the latter case occuring here in convert_to_integer_1.
>
> Tested on x86_64-suse-linux, OK for the mainline?
>
>
> 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  Eric Botcazou  <ebotcazou@adacore.com>
>
>         * c-c++-common/pr82872.c: New test.
>
> --
> Eric Botcazou

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-12-21 15:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-21 15:52 [patch] Fix PR C++/82872 Eric Botcazou
2017-12-21 15:53 ` Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).