Bug 59386 - [4.9 Regression] ICE on valid code at -O2 and -O3 on x86_64-linux-gnu in 64-bit mode
Summary: [4.9 Regression] ICE on valid code at -O2 and -O3 on x86_64-linux-gnu in 64-b...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.9.0
: P1 normal
Target Milestone: 4.9.0
Assignee: Jakub Jelinek
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-12-04 17:51 UTC by Zhendong Su
Modified: 2013-12-11 09:20 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work: 4.8.2
Known to fail: 4.9.0
Last reconfirmed: 2013-12-04 00:00:00


Attachments
gcc49-pr59386.patch (619 bytes, patch)
2013-12-10 17:07 UTC, Jakub Jelinek
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Zhendong Su 2013-12-04 17:51:43 UTC
The following code causes an ICE when compiled with the current gcc trunk at -O2 and -O3 on x86_64-linux-gnu in 64-bit mode (but not in 32-bit mode). 

It is a regression from 4.8.x. 


$ gcc-trunk -v
Using built-in specs.
COLLECT_GCC=gcc-trunk
COLLECT_LTO_WRAPPER=/usr/local/gcc-trunk/libexec/gcc/x86_64-unknown-linux-gnu/4.9.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../gcc-trunk/configure --prefix=/usr/local/gcc-trunk --enable-languages=c,c++ --disable-werror --enable-multilib
Thread model: posix
gcc version 4.9.0 20131204 (experimental) [trunk revision 205660] (GCC) 
$ 
$ gcc-trunk -m64 -Os -c small.c       
$ gcc-4.8 -m64 -O2 -c small.c
$ gcc-trunk -m32 -O2 -c small.c
$ 
$ gcc-trunk -m64 -O2 -c small.c
small.c: In function ‘fn2’:
small.c:31:1: error: incorrect sharing of tree nodes
 }
 ^
a.f2
# .MEM_11 = VDEF <.MEM_10>
a.f2 = D.1782;
small.c:31:1: internal compiler error: verify_gimple failed
0x9d3821 verify_gimple_in_cfg(function*)
	../../gcc-trunk/gcc/tree-cfg.c:4848
0x8fa874 execute_function_todo
	../../gcc-trunk/gcc/passes.c:1843
0x8fb273 execute_todo
	../../gcc-trunk/gcc/passes.c:1877
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <http://gcc.gnu.org/bugs.html> for instructions.
$ 


---------------------------


struct S0
{
  int f0;
};

struct S1
{
  int f1;
  struct S0 f2;
} c;

int b;

struct S0
fn1 ()
{
  struct S1 d;
  if (b) 
    for (; c.f1;)
      ;
  else
    return d.f2; 
}

struct S0
fn2 ()
{
  struct S1 a;
  a.f2 = fn1 ();
  return a.f2; 
}
Comment 1 Marek Polacek 2013-12-04 18:28:43 UTC
Confirmed.
Comment 2 Jakub Jelinek 2013-12-10 17:07:18 UTC
Created attachment 31411 [details]
gcc49-pr59386.patch

Untested fix.
Comment 3 Jakub Jelinek 2013-12-11 09:18:36 UTC
Author: jakub
Date: Wed Dec 11 09:18:33 2013
New Revision: 205883

URL: http://gcc.gnu.org/viewcvs?rev=205883&root=gcc&view=rev
Log:
	PR tree-optimization/59386
	* tree-inline.c (remap_gimple_stmt): If not id->do_not_unshare,
	unshare_expr (id->retval) before passing it to gimple_build_assign.

	* gcc.c-torture/compile/pr59386.c: New test.

Added:
    trunk/gcc/testsuite/gcc.c-torture/compile/pr59386.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree-inline.c
Comment 4 Jakub Jelinek 2013-12-11 09:20:32 UTC
Fixed.