Bug 18040 - [4.0 Regression] ICE in for_each_index, at tree-ssa-loop-im.c:178
Summary: [4.0 Regression] ICE in for_each_index, at tree-ssa-loop-im.c:178
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.0.0
: P2 critical
Target Milestone: 4.0.0
Assignee: Andrew Pinski
URL:
Keywords: ice-on-valid-code, patch
Depends on: 8171
Blocks:
  Show dependency treegraph
 
Reported: 2004-10-17 12:36 UTC by Andreas Jaeger
Modified: 2004-12-12 16:46 UTC (History)
3 users (show)

See Also:
Host: i586-linux-gnu
Target: i586-linux-gnu
Build: i586-linux-gnu
Known to work: 3.4.2
Known to fail: 4.0.0
Last reconfirmed: 2004-12-02 04:35:13


Attachments
Preprocessed and compressed source file (152.10 KB, application/octet-stream)
2004-10-17 12:37 UTC, Andreas Jaeger
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Andreas Jaeger 2004-10-17 12:36:20 UTC
Compiling boost I get the following ICE:

/usr/lib/gcc/i586-suse-linux/4.0.0/cc1plus -fpreprocessed function.ii -quiet
-dumpbase function.cpp -mtune=pentium -auxbase-strip
bin/boost/libs/python/build/libboost_python.so/gcc/release/shared-linkable-true/function.o
-O3 -Wall -Wno-inline -version -ftemplate-depth-100 -finline-functions -fPIC -o
function.s
GNU C++ version 4.0.0 20041013 (experimental) (SUSE Linux) (i586-suse-linux)
        compiled by GNU C version 4.0.0 20041013 (experimental) (SUSE Linux).
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
function.ii: In member function `void
boost::python::objects::function::argument_error(PyObject*, PyObject*) const':
function.ii:63053: internal compiler error: in for_each_index, at
tree-ssa-loop-im.c:178
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.
Comment 1 Andreas Jaeger 2004-10-17 12:37:28 UTC
Created attachment 7368 [details]
Preprocessed and compressed source file
Comment 2 Kazu Hirata 2004-10-17 13:06:07 UTC
Confirmed.
Comment 3 Giovanni Bajo 2004-10-17 13:34:54 UTC
Kazu, make sure the fill the missing fields when confirming a bug. Especially 
the regression status is very important.
Comment 4 Andrew Pinski 2004-10-17 14:47:54 UTC
This is a bug in the IV-OPTS (reducing the testcase right now).
Comment 5 Zdenek Dvorak 2004-10-17 16:01:36 UTC
Does not seem to be directly caused by ivopts.  The statement
on that ivopts fail looks like

x_1 = ((cast) variable).field

which is not a valid gimple.  I am investigating further.
Comment 6 Andrew Pinski 2004-10-17 16:11:43 UTC
Here is the reduced testcase to make your investigation easier:
typedef struct _object PyObject;
int PyObject_IsTrue(PyObject *);

class object;
typedef PyObject* (object::*bool_type)() const;

struct object_base
{
    operator bool_type() const;
    ~object_base();
    PyObject* ptr() const;
};
struct object : public object_base
{
    object();
    template <class T>
    explicit object(T const& x) ;
};

inline object_base::operator bool_type() const
{
    const object &x = *static_cast<object const*>(this);
    return PyObject_IsTrue(x.ptr()) ? &object::ptr : 0;
}

void f(const char *);

void argument_error (void)
{
    for (unsigned n = 0; n < 100; ++n)
    {
	object kv("");
	if (kv)
	  f("");
    }
}
Comment 7 Andrew Pinski 2004-10-17 16:17:10 UTC
The bug shows up in .sra:
  <L3>:;
!   D.1674 = (struct 
    {
      object:: * __pfn;
      int __delta;
!   }) iftmp.0;
!   D.1675_16 = D.1674.__pfn;
    if (D.1675_16 != 0B) goto <L5>; else goto <L10>;
  
  <L5>:;
--- ...,... ----
 
+   # SR.18_51 = PHI <SR.18_58(5), SR.18_60(4)>;
+   # SR.17_6 = PHI <SR.17_57(5), SR.17_59(4)>;
  <L3>:;
!   SR.20_53 = ((struct 
    {
      object:: * __pfn;
      int __delta;
!   }) iftmp.0).__delta;
!   iftmp.0.__delta = SR.18_51;
!   iftmp.0.__pfn = SR.17_6;
!   SR.19_56 = ((struct 
!   {
!     object:: * __pfn;
!     int __delta;
!   }) iftmp.0).__pfn;
!   D.1675_16 = SR.19_56;
    if (D.1675_16 != 0B) goto <L5>; else goto <L10>;
  
Comment 8 Zdenek Dvorak 2004-10-17 16:23:18 UTC
The problem is that is_gimple_addressable uses handled_component_p that allows
casts.  I am testing a patch for this.
Comment 9 Andrew Pinski 2004-10-17 16:29:57 UTC
Here is something which is slightly smaller:
int PyObject_IsTrue();
struct object_base
{
    void ptr() const;
};
struct object : public object_base
{
  typedef void (object::*bool_type)() const;
  inline operator bool_type() const { return PyObject_IsTrue() ? &object_base::ptr : 0; }
};
void f();
void g (void)
{
    for (unsigned n = 0; n < 100; ++n)
    {
	object kv;
	if (kv)
	  f();
    }
}
Comment 10 Zdenek Dvorak 2004-10-17 19:18:56 UTC
Patch:

http://gcc.gnu.org/ml/gcc-patches/2004-10/msg01398.html
Comment 11 Andrew Pinski 2004-10-17 22:06:13 UTC
Could someone tell me why the cast is there for the testcase in the first place it seems wrong (except 
that we are converting between void (object_base::*)() and void (object::*)(). )
Comment 12 Andrew Pinski 2004-10-17 22:17:02 UTC
The front-end is doing something funny for this example where there should be no cast, it is still 
creating a "void (object_base::*)() const" type.
int PyObject_IsTrue();
struct object_base
{
    void ptr() const;
};
struct object : public object_base
{
  typedef void (object::*bool_type)() const;
  inline operator bool_type() const { return PyObject_IsTrue() ? &object::ptr : 0; }
};
void f();
void g (void)
{
    for (unsigned n = 0; n < 100; ++n)
    {
        object kv;
        if (kv)
          f();
    }
}

If I add a cast such as:
  inline operator bool_type() const { return PyObject_IsTrue() ? (bool_type) &object::ptr : 0; }
It works and we only produce bool_type instead of what we produced before so part of this is front-end 
issue and a tree-opt issue also for the case I gave in comment #9.
Comment 13 Andrew Pinski 2004-10-17 22:19:38 UTC
Here is another example which works:
int PyObject_IsTrue();
struct object_base
{
    void ptr() const;
};
struct object : public object_base
{
  void ptr1() const;
  typedef void (object::*bool_type)() const;
  inline operator bool_type() const { return PyObject_IsTrue() ? &object_base::ptr : &object::ptr1; }
};
void f();
void g (void)
{
    for (unsigned n = 0; n < 100; ++n)
    {
        object kv;
        if (kv)
          f();
    }
}

And another which does not:
int PyObject_IsTrue();
struct object_base
{
    void ptr() const;
  void ptr1() const;
};
struct object : public object_base
{
  typedef void (object::*bool_type)() const;
  inline operator bool_type() const { return PyObject_IsTrue() ? &object_base::ptr : &object::ptr1; }
};
void f();
void g (void)
{
    for (unsigned n = 0; n < 100; ++n)
    {
        object kv;
        if (kv)
          f();
    }
}
Comment 14 Andrew Pinski 2004-11-27 21:20:30 UTC
Even though this ICE is caused by IV-OPTS, it has nothing to do with IV-OPTS, IVOPTS is finding invalid 
gimple which is produced by SRA because of handled_component_p.
Comment 15 Andrew Pinski 2004-12-10 16:54:19 UTC
Newest patch here: <http://gcc.gnu.org/ml/gcc-patches/2004-12/msg00755.html>.
Comment 16 Andrew Pinski 2004-12-12 03:05:08 UTC
Updated patch: <http://gcc.gnu.org/ml/gcc-patches/2004-12/msg00842.html>.
Comment 17 CVS Commits 2004-12-12 16:45:32 UTC
Subject: Bug 18040

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	pinskia@gcc.gnu.org	2004-12-12 16:45:20

Modified files:
	gcc            : ChangeLog expr.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/g++.dg/opt: ptrmem6.C 

Log message:
	2004-12-12  Andrew Pinski  <pinskia@physics.uc.edu>
	
	PR tree-opt/18040
	* g++.dg/opt/ptrmem6.C: New test.
	
	2004-12-12  Andrew Pinski  <pinskia@physics.uc.edu>
	
	PR tree-opt/18040
	* expr.c (get_inner_reference): Remove NON_LVALUE_EXPR, NOP_EXPR,
	CONVERT_EXPR cases.
	(handled_component_p): Likewise.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.6789&r2=2.6790
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/expr.c.diff?cvsroot=gcc&r1=1.758&r2=1.759
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.4739&r2=1.4740
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/opt/ptrmem6.C.diff?cvsroot=gcc&r1=NONE&r2=1.1

Comment 18 Andrew Pinski 2004-12-12 16:46:03 UTC
Fixed.