Bug 16567 - Nested function and variable-sized structure ICE
Summary: Nested function and variable-sized structure ICE
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.0.0
: P2 normal
Target Milestone: 4.0.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-07-15 14:55 UTC by Joseph S. Myers
Modified: 2004-10-15 13:51 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2004-07-15 15:10:46


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Joseph S. Myers 2004-07-15 14:55:25 UTC
The following GNU C testcase ICEs with every compiler version tested
from 2.6.3 to recent mainline.  With mainline 3.5.0 20040710 on
i686-pc-linux-gnu, the error is:

t.c: In function `nested':
t.c:12: internal compiler error: in make_decl_rtl, at varasm.c:758
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.

With 3.4.1, the error is:

t.c: In function `nested':
t.c:12: internal compiler error: in expand_expr_real, at expr.c:6638
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.

The proper fix may well involve getting rid of variable-sized structures
in GNU C, but I don't know whether the problem can be triggered with
equivalent testcases in other languages (all ICEs are in various middle-end
files).

#include <stddef.h>

extern int printf (const char *, ...);
extern void *memset (void *, int, size_t);

int bar (int (*)(), int, void *);

int
main(int argc, char **argv)
{
  struct s { int a; char b[argc]; };
  int nested (struct s x) { return x.a + sizeof(x); }
  struct s t;
  memset (&t, 0, sizeof(t));
  t.a = 123;
  printf("%d\n", bar (nested, argc, &t));
  return 0;
}
Comment 1 Wolfgang Bangerth 2004-07-15 15:10:46 UTC
Confirmed indeed. I guess we should say "don't do evil things!" :-) 
Comment 2 Wolfgang Bangerth 2004-07-15 15:17:47 UTC
BTW, the code is definitely invalid (even leaving aside the matter of 
variable-sized structures). You declare 
  int bar (int (*)(), int, void *); 
and call it with 
  int nested (struct s x) { return x.a + sizeof(x); } 
  bar (nested, argc, &t); 
Note that &nested does not satisfy the signature that bar() expects 
as first argument. It seems, however, as if we never even get to 
the point where gcc would like to check for this, it ICEs before that. 
 
Here's something that should be closer to validity: 
--------------- 
void bar (void *); 
 
int main(int argc, char **argv) { 
  struct s { char b[argc]; }; 
  int nested (struct s x) { return 0; } 
  struct s t; 
  bar ((void*)&nested); 
  return 0; 
} 
---------------- 
 
g/x> /home/bangerth/bin/gcc-3.5*/bin/gcc -c x.c 
x.c: In function `nested': 
x.c:5: internal compiler error: in make_decl_rtl, at varasm.c:758 
Please submit a full bug report, 
with preprocessed source if appropriate. 
See <URL:http://gcc.gnu.org/bugs.html> for instructions. 
 
g/x> /home/bangerth/bin/gcc-2.95.3/bin/gcc -c x.c 
x.c: In function `nested': 
x.c:5: Internal compiler error in `fix_lexical_addr', at function.c:5622 
Please submit a full bug report. 
See <URL:http://www.gnu.org/software/gcc/bugs.html> for instructions. 
 
W. 
Comment 3 Joseph S. Myers 2004-07-15 15:25:31 UTC
Subject: Re:  Nested function and variable-sized
 structure ICE

On Thu, 15 Jul 2004, bangerth at dealii dot org wrote:

> BTW, the code is definitely invalid (even leaving aside the matter of 
> variable-sized structures). You declare 
>   int bar (int (*)(), int, void *); 
> and call it with 
>   int nested (struct s x) { return x.a + sizeof(x); } 
>   bar (nested, argc, &t); 
> Note that &nested does not satisfy the signature that bar() expects 
> as first argument. It seems, however, as if we never even get to 
> the point where gcc would like to check for this, it ICEs before that. 

I deliberately declare bar's first argument with an old-style
non-prototype declaration precisely because a matching prototype can't be
written at that point - but &nested can match a simple "pointer to
function returning int"!  (The original two-file testcase
<http://gcc.gnu.org/ml/gcc/2004-07/msg00776.html> was intended to be a
valid illustration of how variable-sized arguments are part of the C ABI,
which had the unintended effect of showing the ABI to be completely
irrelevant for this code because all versions of GCC ICE on it.)

Comment 4 Andrew Pinski 2004-10-14 01:54:55 UTC
This now works on the mainline.  If I get time I will apply the testcase (otherwise someone else can do 
that plus close the bug).
Comment 5 Andrew Pinski 2004-10-15 13:49:21 UTC
Fixed: Search converges between 2004-07-16-trunk (#487) and 2004-07-17-trunk (#488).
Committed the testcase so closing.
Comment 6 GCC Commits 2004-10-15 13:49:36 UTC
Subject: Bug 16567

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	pinskia@gcc.gnu.org	2004-10-15 13:49:21

Modified files:
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gcc.c-torture/compile: nested-1.c 

Log message:
	2004-10-14  Andrew Pinski  <pinskia@physics.uc.edu>
	
	PR middle-end/16567
	* gcc.c-torture/compile/nested-1.c: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.c-torture/compile/nested-1.c.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.4454&r2=1.4455