Bug 47370 - [4.6 Regression] error: invalid first operand of MEM_REF
Summary: [4.6 Regression] error: invalid first operand of MEM_REF
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.6.0
: P3 normal
Target Milestone: 4.6.0
Assignee: Richard Biener
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-01-20 03:49 UTC by John Regehr
Modified: 2011-01-20 14:42 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2011-01-20 08:19:09


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description John Regehr 2011-01-20 03:49:21 UTC
regehr@home:~/volatile/bugs/tmp346$ current-gcc -O2 -c small.c

small.c: In function ‘func_115’:
small.c:27:1: error: invalid first operand of MEM_REF
&l_233[0]
small.c:18:3: note: in statement
# .MEM_6 = VDEF <.MEM_1(D)>
MEM[(struct S0 *)&l_233[0]] = l_111$f4_5;

small.c:27:1: internal compiler error: verify_stmts failed
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.

regehr@home:~/volatile/bugs/tmp346$ current-gcc -v

Using built-in specs.
COLLECT_GCC=current-gcc
COLLECT_LTO_WRAPPER=/mnt/z/z/compiler-install/gcc-r169046-install/libexec/gcc/i686-pc-linux-gnu/4.6.0/lto-wrapper
Target: i686-pc-linux-gnu
Configured with: ../configure --with-libelf=/usr/local --enable-lto --prefix=/mnt/z/z/compiler-install/gcc-r169046-install --program-prefix=r169046- --enable-languages=c,c++
Thread model: posix
gcc version 4.6.0 20110120 (experimental) (GCC) 

regehr@home:~/volatile/bugs/tmp346$ cat small.c


struct S0
{
  int f4;
};

void func_23 (void)
{
  int i;
  for (i = 0; i < 1;) 
    ;
}

struct S0 func_105 (void)
{
  struct S0 l_111 = {
    99
  };
  return l_111;
}

void func_115 (void)
{
  struct S0 l_233[1];
  l_233[0] = func_105 ();
  func_105 ();
  func_23 ();
}
Comment 1 Jakub Jelinek 2011-01-20 08:19:09 UTC
Tiny bit reduced:

struct S { int s; };

void
foo (void)
{
  for (;;)
    ;
}

struct S
bar (void)
{
  struct S s = { 99 };
  return s;
}

void
baz (void)
{
  struct S s[1];
  s[0] = bar ();
  bar ();
  foo ();
}

Only happens with -m32.  My bet is this goes wrong during inlining.
We have
MEM[(struct S *)&<retval>] = s$s_5;
stmt where &RESULT_DECL satisfies is_gimple_mem_ref_addr.
But after inlining this becomes
MEM[(struct S *)&s[0]] = s$s_5;
and ADDR_EXPR of ARRAY_REF is not is_gimple_mem_ref_addr, so I suppose the inliner needs to fix this up somewhere.
Comment 2 Richard Biener 2011-01-20 10:42:27 UTC
Mine.
Comment 3 Richard Biener 2011-01-20 14:42:23 UTC
Author: rguenth
Date: Thu Jan 20 14:42:20 2011
New Revision: 169055

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=169055
Log:
2011-01-20  Richard Guenther  <rguenther@suse.de>

	PR middle-end/47370
	* tree-inline.c (remap_gimple_op_r): Recurse manually for
	the pointer operand of MEM_REFs.

	* gcc.dg/torture/pr47370.c: New testcase.

Added:
    trunk/gcc/testsuite/gcc.dg/torture/pr47370.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree-inline.c
Comment 4 Richard Biener 2011-01-20 14:42:32 UTC
Fixed.