Bug 60640 - [4.9 Regression] ICE edge points to wrong declaration / verify_cgraph_node failed
Summary: [4.9 Regression] ICE edge points to wrong declaration / verify_cgraph_node fa...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: ipa (show other bugs)
Version: 4.9.0
: P1 normal
Target Milestone: 4.9.0
Assignee: Martin Jambor
URL: http://gcc.gnu.org/ml/gcc-patches/201...
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2014-03-24 20:45 UTC by Tobias Burnus
Modified: 2014-04-07 09:59 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2014-03-25 00:00:00


Attachments
Reduced C++ testfile.ii, compile with -O3 (1.20 KB, text/plain)
2014-03-24 20:45 UTC, Tobias Burnus
Details
Possible fix (3.95 KB, patch)
2014-03-26 18:16 UTC, Martin Jambor
Details | Diff
Miscompiled run time testcase (486 bytes, text/plain)
2014-04-01 12:35 UTC, Martin Jambor
Details
Proposed patch for the 4.8 branch (1.59 KB, patch)
2014-04-02 16:11 UTC, Martin Jambor
Details | Diff
Proposed patch for the 4.7 branch (1.58 KB, patch)
2014-04-02 16:12 UTC, Martin Jambor
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2014-03-24 20:45:51 UTC
Created attachment 32438 [details]
Reduced C++ testfile.ii, compile with -O3

Follow-up to PR59176

ICE with -O3 in verify_cgraph_node. (-O2 is fine.)

(In reply to David Binderman from PR59176 comment #15)
> Created attachment 32434 [details]
> gzipped C++ source code

 (In reply to Martin Jambor from PR59176 comment #17)
> Although the ICE message is the same, this is most certainly a
> different bug as it happens at a different time during the compilation
> process.  I will look it at it some more tomorrow.
Comment 1 Martin Jambor 2014-03-25 15:05:49 UTC
Confirmed, mine.
Comment 2 Martin Jambor 2014-03-26 18:16:14 UTC
Created attachment 32459 [details]
Possible fix

The problem is that IPA-CP skips thunks when it redirects edges to the
new clones it produces.

I am currently testing this patch which duplicates thunks when
redirecting edges.  It is quite possible it will have issues.  In any
event, Honza, do you have any comments?
Comment 3 Jakub Jelinek 2014-03-28 12:17:26 UTC
Reduced testcase:
struct A {};
struct E { ~E (); };
struct B { virtual unsigned foo () const; };
struct C { virtual void foo (); };
struct D : public A { D (A *); };
struct I : public D { A i; I (int) : D (0) {} };
struct F : E { virtual unsigned foo (bool) const; };
template <class T>
struct G : public T {};
struct J : C, public F {};
struct K : public J { unsigned foo (bool) const { return 0; } };

struct H : B
{
  H (A);
  unsigned foo () const { return bar ().foo (0); }
  const F &bar () const { return h; }
  G<K> h;
};

template <class T>
void
baz ()
{
  I f (0);
  T d (f);
}

void
test ()
{
  baz<H> ();
}

Regressed with r205019.
Comment 4 Jakub Jelinek 2014-03-28 12:38:43 UTC
That is still too big, here is a smaller one:
struct B { virtual unsigned f () const; };
struct C { virtual void f (); };
struct F { virtual unsigned f (bool) const; ~F (); };
struct J : C, F {};
struct G : J { unsigned f (bool) const { return 0; } };
struct H : B
{
  H (int);
  unsigned f () const { return ((const F &) h).f (0); }
  G h;
};
H h (0);
Comment 5 Jakub Jelinek 2014-03-28 12:44:28 UTC
(In reply to Jakub Jelinek from comment #4)
> That is still too big, here is a smaller one:
> struct B { virtual unsigned f () const; };
> struct C { virtual void f (); };
> struct F { virtual unsigned f (bool) const; ~F (); };
> struct J : C, F {};
> struct G : J { unsigned f (bool) const { return 0; } };
> struct H : B
> {
>   H (int);
>   unsigned f () const { return ((const F &) h).f (0); }
>   G h;
> };
> H h (0);

Though, on this reduced testcase the ICE started with r176424, i.e. making it a 4.7/4.8/4.9 Regression on that testcase.
Comment 6 Martin Jambor 2014-03-28 17:33:56 UTC
I added the newest testcase to the patch a proposed it on the mailing list:

http://gcc.gnu.org/ml/gcc-patches/2014-03/msg01640.html
Comment 7 Jakub Jelinek 2014-03-28 18:13:41 UTC
(In reply to Martin Jambor from comment #6)
> I added the newest testcase to the patch a proposed it on the mailing list:
> 
> http://gcc.gnu.org/ml/gcc-patches/2014-03/msg01640.html

I still see the old testcase only there ;).
Comment 8 Martin Jambor 2014-04-01 12:35:18 UTC
Created attachment 32513 [details]
Miscompiled run time testcase

(In reply to Jakub Jelinek from comment #7)
> 
> I still see the old testcase only there ;).

Yeah, I forgot to refresh the patch, but I do have it in my copy.  I'm
also adding this one.
Comment 9 Martin Jambor 2014-04-01 13:02:21 UTC
This one has them all, in addition to fixing a real problem:

http://gcc.gnu.org/ml/gcc-patches/2014-04/msg00016.html
Comment 10 Martin Jambor 2014-04-02 16:11:14 UTC
Created attachment 32523 [details]
Proposed patch for the 4.8 branch

Independent of the trunk fix, I'm going to propose this simple patch
which disables propagation through thunks for the 4.8 branch.  It
passes bootstrap and testsuite on x86_64-linux.
Comment 11 Martin Jambor 2014-04-02 16:12:22 UTC
Created attachment 32524 [details]
Proposed patch for the 4.7 branch

Independent of the trunk fix, I'm going to propose this simple patch
which disables propagation through thunks for the 4.7 branch.  It
passes bootstrap and testsuite on x86_64-linux.
Comment 12 Martin Jambor 2014-04-04 14:11:39 UTC
Author: jamborm
Date: Fri Apr  4 14:11:06 2014
New Revision: 209097

URL: http://gcc.gnu.org/viewcvs?rev=209097&root=gcc&view=rev
Log:
2014-04-04  Martin Jambor  <mjambor@suse.cz>

	PR ipa/60640
        * cgraph.h (cgraph_clone_node): New parameter added to declaration.
        Adjust all callers.
	* cgraph.c (clone_of_p): Also return true if thunks match.
	(verify_edge_corresponds_to_fndecl): Removed extraneous call to
	cgraph_function_or_thunk_node and an obsolete comment.
        * cgraphclones.c (build_function_type_skip_args): Moved upwards in the
        file.
        (build_function_decl_skip_args): Likewise.
	(set_new_clone_decl_and_node_flags): New function.
        (duplicate_thunk_for_node): Likewise.
        (redirect_edge_duplicating_thunks): Likewise.
        (cgraph_clone_node): New parameter args_to_skip, pass it to
        redirect_edge_duplicating_thunks which is called instead of
        cgraph_redirect_edge_callee.
        (cgraph_create_virtual_clone): Pass args_to_skip to cgraph_clone_node,
	moved setting of a lot of flags to set_new_clone_decl_and_node_flags.

testsuite/
        * g++.dg/ipa/pr60640-1.C: New test.
        * g++.dg/ipa/pr60640-2.C: Likewise.
        * g++.dg/ipa/pr60640-3.C: Likewise.
        * g++.dg/ipa/pr60640-4.C: Likewise.


Added:
    trunk/gcc/testsuite/g++.dg/ipa/pr60640-1.C
    trunk/gcc/testsuite/g++.dg/ipa/pr60640-2.C
    trunk/gcc/testsuite/g++.dg/ipa/pr60640-3.C
    trunk/gcc/testsuite/g++.dg/ipa/pr60640-4.C
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/cgraph.c
    trunk/gcc/cgraph.h
    trunk/gcc/cgraphclones.c
    trunk/gcc/ipa-inline-transform.c
    trunk/gcc/ipa-inline.c
    trunk/gcc/lto-cgraph.c
    trunk/gcc/testsuite/ChangeLog
Comment 13 Martin Jambor 2014-04-04 15:33:27 UTC
Fixed on trunk with
http://gcc.gnu.org/ml/gcc-patches/2014-04/msg00208.html

I have posted the patch for the 4.8 branch:
http://gcc.gnu.org/ml/gcc-patches/2014-04/msg00213.html

and also for the 4.7 branch:
http://gcc.gnu.org/ml/gcc-patches/2014-04/msg00215.html
Comment 14 Martin Jambor 2014-04-07 09:36:42 UTC
Author: jamborm
Date: Mon Apr  7 09:36:10 2014
New Revision: 209180

URL: http://gcc.gnu.org/viewcvs?rev=209180&root=gcc&view=rev
Log:
2014-04-07  Martin Jambor  <mjambor@suse.cz>

	PR ipa/60640
	* ipa-cp.c (propagate_constants_accross_call): Do not propagate
	accross thunks.

testsuite/
        * g++.dg/ipa/pr60640-1.C: New test.
        * g++.dg/ipa/pr60640-2.C: Likewise.
        * g++.dg/ipa/pr60640-3.C: Likewise.


Added:
    branches/gcc-4_8-branch/gcc/testsuite/g++.dg/ipa/pr60640-1.C
    branches/gcc-4_8-branch/gcc/testsuite/g++.dg/ipa/pr60640-2.C
    branches/gcc-4_8-branch/gcc/testsuite/g++.dg/ipa/pr60640-3.C
Modified:
    branches/gcc-4_8-branch/gcc/ChangeLog
    branches/gcc-4_8-branch/gcc/ipa-cp.c
    branches/gcc-4_8-branch/gcc/testsuite/ChangeLog
Comment 15 Martin Jambor 2014-04-07 09:55:27 UTC
Author: jamborm
Date: Mon Apr  7 09:54:55 2014
New Revision: 209181

URL: http://gcc.gnu.org/viewcvs?rev=209181&root=gcc&view=rev
Log:
2014-04-07  Martin Jambor  <mjambor@suse.cz>

	PR ipa/60640
	* ipa-cp.c (propagate_constants_accross_call): Do not propagate
	accross thunks.

testsuite/
        * g++.dg/ipa/pr60640-1.C: New test.
        * g++.dg/ipa/pr60640-2.C: Likewise.
        * g++.dg/ipa/pr60640-3.C: Likewise.


Added:
    branches/gcc-4_7-branch/gcc/testsuite/g++.dg/ipa/pr60640-1.C
    branches/gcc-4_7-branch/gcc/testsuite/g++.dg/ipa/pr60640-2.C
    branches/gcc-4_7-branch/gcc/testsuite/g++.dg/ipa/pr60640-3.C
Modified:
    branches/gcc-4_7-branch/gcc/ChangeLog
    branches/gcc-4_7-branch/gcc/ipa-cp.c
    branches/gcc-4_7-branch/gcc/testsuite/ChangeLog
Comment 16 Martin Jambor 2014-04-07 09:59:18 UTC
Fixed everywhere.