Bug 19666 - [3.3 Regression] Trouble with prt-to-members: rejects-valid/ICE in fold_convert
Summary: [3.3 Regression] Trouble with prt-to-members: rejects-valid/ICE in fold_convert
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.4.4
: P2 normal
Target Milestone: 3.4.4
Assignee: Not yet assigned to anyone
URL:
Keywords: monitored, rejects-valid
Depends on:
Blocks:
 
Reported: 2005-01-28 09:30 UTC by Jakub Jelinek
Modified: 2005-05-02 11:03 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work: 3.2.3 4.0.0 3.4.4
Known to fail: 3.3 3.3.5 3.4.0 3.4.3
Last reconfirmed: 2005-02-26 18:42:52


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jakub Jelinek 2005-01-28 09:30:30 UTC
struct L { void *a; };
struct S {
  static S *foo (L *x)
  {
    return (S *) ((char *) x - (unsigned long) &(((S *) 0)->*&S::a));
  }
  L a;
};

causes ICE in fold_convert (abort at the very end of the function).
Works fine with G++ 3.2.3-RH and HEAD.
Breakpoint 2, fold_convert (type=0x2a97b66d00, arg=0x2a97d65c60) at
../../gcc/fold-const.c:1917
1917      abort ();
(gdb) p debug_tree(type)
 <integer_type 0x2a97b66d00 long int DI
    size <integer_cst 0x2a97b64930 type <integer_type 0x2a97b78410 bit_size_type>
constant 64>
    unit size <integer_cst 0x2a97b64a80 type <integer_type 0x2a97b78340 long
unsigned int> constant 8>
    align 64 symtab 0 alias set -1 precision 64 min <integer_cst 0x2a97b64a20
-9223372036854775808> max <integer_cst 0x2a97b64a50 9223372036854775807>>
$1 = void
(gdb) p debug_tree(arg)
 <negate_expr 0x2a97d65c60
    type <offset_type 0x2a97d63820
        type <record_type 0x2a97d58680 L type_1 type_5 DI
            size <integer_cst 0x2a97b749c0 constant 64>
            unit size <integer_cst 0x2a97b74a80 constant 8>
            align 64 symtab 0 alias set -1 fields <field_decl 0x2a97d589c0 a>
            X() X(constX&) this=(X&) n_parents 0 use_template=0 interface-unknown
            member-functions <tree_vec 0x2a97d5d980
                elt 0 <overload 0x2a97d50fc0>
                elt 2 <function_decl 0x2a97d5fa90 operator=>
                elt 3 <overload 0x2a97d61040>
                elt 4 <overload 0x2a97d61000>>
            pointer_to_this <pointer_type 0x2a97d58750> reference_to_this
<reference_type 0x2a97d5f680> chain <type_decl 0x2a97d58820 L>>
        DI size <integer_cst 0x2a97b749c0 64> unit size <integer_cst 0x2a97b74a80
8>
        align 64 symtab 0 alias set -1 basetype <record_type 0x2a97d604e0 S>>
    constant
    arg 0 <ptrmem_cst 0x2a97d658a0 type <offset_type 0x2a97d63820>
        constant>>
$2 = void
Comment 1 Steven Bosscher 2005-01-28 09:49:15 UTC
Hmm, what target, what options did you use? 
Comment 2 Jakub Jelinek 2005-01-28 10:01:59 UTC
Any target I have tried, any options.
It fails at least on {i386,x86_64,ppc,ppc64,s390,s390x}-redhat-linux,
with -O{0,1,2,3,s}.
Comment 3 Andrew Pinski 2005-01-28 14:06:06 UTC
Started to be rejected (on the mainline at the time):
: Search converges between 2003-07-23-trunk (#302) and 2003-07-24-trunk (#303).

Started to ICE:
: Search converges between 2004-02-02-3.4 (#1) and 2004-03-01-3.4 (#2).
: Search converges between 2004-02-01-trunk (#445) and 2004-03-01-trunk (#446).

Started to pass on the mainline:
: Search converges between 2004-06-08-trunk (#463) and 2004-06-10-trunk (#464).



Comment 4 Andrew Pinski 2005-01-28 14:07:25 UTC
I think this patch fixes the problem but I don't have time to back port it:
2004-06-08  Andrew Pinski  <pinskia@physics.uc.edu>

        * fold-const.c (fold_convert): Treat OFFSET_TYPE like
        POINTER_TYPE and INTEGER_TYPE.
Comment 5 Volker Reichelt 2005-02-10 22:38:57 UTC
Here's a reduced example without casts and dereferencing the null-pointer:

====================================
struct A
{
    int i;
};

int foo(A *p)
{
    return &p->i - &(p->*&A::i);
}
====================================

This valid code snippet is rejected on the 3.3 branch.
It causes an ICE in fold_convert on the 3.4 branch.
Comment 6 Jakub Jelinek 2005-02-11 09:55:33 UTC
Patch here: <http://gcc.gnu.org/ml/gcc-patches/2005-02/msg00494.html>
Comment 7 CVS Commits 2005-02-11 21:10:23 UTC
Subject: Bug 19666

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	jakub@gcc.gnu.org	2005-02-11 21:10:16

Modified files:
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/g++.dg/other: ptrmem6.C 

Log message:
	PR c++/19666
	2004-06-08  Andrew Pinski  <pinskia@physics.uc.edu>
	* fold-const.c (fold_convert): Treat OFFSET_TYPE like
	POINTER_TYPE and INTEGER_TYPE.
	
	* gcc/testsuite/g++.dg/other/ptrmem6.C: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.5018&r2=1.5019
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/other/ptrmem6.C.diff?cvsroot=gcc&r1=NONE&r2=1.1

Comment 8 CVS Commits 2005-02-11 21:13:01 UTC
Subject: Bug 19666

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_4-branch
Changes by:	jakub@gcc.gnu.org	2005-02-11 21:12:56

Modified files:
	gcc            : ChangeLog fold-const.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/g++.dg/other: ptrmem6.C 

Log message:
	PR c++/19666
	2004-06-08  Andrew Pinski  <pinskia@physics.uc.edu>
	* fold-const.c (fold_convert): Treat OFFSET_TYPE like
	POINTER_TYPE and INTEGER_TYPE.
	
	* gcc/testsuite/g++.dg/other/ptrmem6.C: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=2.2326.2.797&r2=2.2326.2.798
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/fold-const.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.322.2.15&r2=1.322.2.16
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.3389.2.360&r2=1.3389.2.361
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/other/ptrmem6.C.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.2.1

Comment 9 Andrew Pinski 2005-02-11 21:15:55 UTC
Fixed in the 3.4 branch, it is a rejects valid for the 3.3 branch but most likely will not get fixed there as 
many different places call convert instead of fold_convert on the 3.3 branch compared to the 3.4/4.0.
Comment 10 Gabriel Dos Reis 2005-04-30 14:46:38 UTC
fixed in 3.4.4.  Won't fix for 3.3.6
Comment 11 Gabriel Dos Reis 2005-04-30 16:33:16 UTC
Fixed in 3.4.3.  Won't fix for 3.3.6.
Comment 12 Volker Reichelt 2005-05-02 11:03:17 UTC
The snippet from comment #5 crashes in gcc 3.4.3.
Really fixed in 3.4.4.