Bug 16460 - [4.0 Regression] ICE when compiling glibc (ld-ctype.c)
Summary: [4.0 Regression] ICE when compiling glibc (ld-ctype.c)
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.0.0
: P2 critical
Target Milestone: 4.0.0
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-valid-code
: 16534 16993 (view as bug list)
Depends on:
Blocks:
 
Reported: 2004-07-09 20:25 UTC by Ulrich Drepper
Modified: 2004-09-20 20:48 UTC (History)
5 users (show)

See Also:
Host: i686-redhat-linux
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2004-09-10 08:15:24


Attachments
preprocessed sources for ICE (48.15 KB, text/plain)
2004-07-09 20:27 UTC, Ulrich Drepper
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Ulrich Drepper 2004-07-09 20:25:44 UTC
I get an ICE when compiling glibc with the current (2004-7-9) mainline compiler.
 I'll attach the preprocessed sources.  This is the message:

programs/ld-ctype.c: In function `ctype_finish':
programs/ld-ctype.c:3059: internal compiler error: in expand_call_inline, at
tree-inline.c:1482


-O2 is needed, -O alone doesn't cause the problem.  No other options are needed.
Comment 1 Ulrich Drepper 2004-07-09 20:27:49 UTC
Created attachment 6719 [details]
preprocessed sources for ICE

gcc35 -c ld-ctype.i -O2

is sufficient.
Comment 2 Drea Pinski 2004-07-09 23:49:16 UTC
Confirmed but I have not reduced the testcase yet.
      /* We have missing edge in the callgraph.  This can happen in one case
         where previous inlining turned indirect call into direct call by
         constant propagating arguments.  In all other cases we hit a bug
         (incorrect node sharing is most common reason for missing edges.  */
      if (!dest->needed)
        abort ();
Comment 3 Drea Pinski 2004-07-10 01:48:06 UTC
Here are some minized testcases from a mailing:
<http://gcc.gnu.org/ml/gcc-patches/2004-07/msg00937.html>
static inline int g(void) {
  auto int h(void) __attribute__((noinline));
  int h(void) { return 1; }
  return h();
}
int f(void) { return g(); }
---------------------
static inline int g(int i) {
  auto inline int h(void);
  auto int h2(void) __attribute__((noinline));
  int h(void) { return i+1; }
  int h2(void) { return h(); }
  return h2();
}
int f(void) { return g(1); }
int f2(void) { return g(1); }
Comment 4 Drea Pinski 2004-07-14 08:46:57 UTC
*** Bug 16534 has been marked as a duplicate of this bug. ***
Comment 5 Drea Pinski 2004-08-12 00:20:41 UTC
*** Bug 16993 has been marked as a duplicate of this bug. ***
Comment 6 Drea Pinski 2004-08-21 01:51:51 UTC
: Search converges between 2004-07-02-trunk (#477) and 2004-07-04-trunk (#478).
Comment 7 Andreas Jaeger 2004-09-09 06:51:59 UTC
The same error occurs also on Linux/x86-64.
Comment 8 Drea Pinski 2004-09-10 08:15:20 UTC
My second simplied example fails still at -O2:
pr16460.c: In function `f':
pr16460.c:9: error: Missing callgraph edge for call expr:
 <call_expr 0xf6eca0f0
    type <integer_type 0xf6ec6414 int public SI
        size <integer_cst 0xf6ec33a8 constant invariant 32>
        unit size <integer_cst 0xf6ec30d8 constant invariant 4>
        align 32 symtab 0 alias set -1 precision 32 min <integer_cst 0xf6ec3378 -2147483648> max 
<integer_cst 0xf6ec3390 2147483647>
        pointer_to_this <pointer_type 0xf6eb39f8>>
    side-effects
    arg 0 <addr_expr 0xf6ec2380
        type <pointer_type 0xf6e3215c type <function_type 0xf6eb66cc>
            unsigned SI size <integer_cst 0xf6ec33a8 32> unit size <integer_cst 0xf6ec30d8 4>
            align 32 symtab 0 alias set 5>
        invariant
        arg 0 <function_decl 0xf6e2db54 h2 type <function_type 0xf6eb66cc>
            addressable asm_written used nothrow static decl_5 QI file pr16460.c line 6 context 
<function_decl 0xf6e2d7b4 g> attributes <tree_list 0xf6e31cc0> result <result_decl 0xf6e32074> 
initial <error_mark 0xf6ec14c0>
            (mem:QI (symbol_ref:SI ("h2.1122") [flags 0x3] <function_decl 0xf6e2db54 h2>) [0 S1 A8])>>
    arg 2 <addr_expr 0xf6ec2500
        type <pointer_type 0xf6e32658 type <record_type 0xf6e32570 FRAME.g>
            unsigned SI size <integer_cst 0xf6ec33a8 32> unit size <integer_cst 0xf6ec30d8 4>
            align 32 symtab 0 alias set -1>
        invariant
        arg 0 <var_decl 0xf6e325e4 FRAME.6 type <record_type 0xf6e32570 FRAME.g>
            addressable used ignored BLK file pr16460.c line 8
            size <integer_cst 0xf6ec36f0 constant invariant 128>
            unit size <integer_cst 0xf6ec3708 constant invariant 16>
            align 32 context <function_decl 0xf6e2d7b4 g> chain <var_decl 0xf6e32244 T.0>>>
    pr16460.c:7>
g/7: (inline copy in f/5) 24 insns tree local inlinable
  called by: f/5 (inlined)
  calls: __builtin_init_trampoline/4
pr16460.c:9: internal compiler error: verify_cgraph_node failed.
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.
Comment 9 Jan Hubicka 2004-09-10 08:19:04 UTC
Subject: Re:  [3.5 Regression] ICE when compiling glibc (ld-ctype.c)

> 
> ------- Additional Comments From pinskia at gcc dot gnu dot org  2004-09-10 08:15 -------
> My second simplied example fails still at -O2:
> pr16460.c: In function `f':
> pr16460.c:9: error: Missing callgraph edge for call expr:

I've been debugging this once already in the past.  We get invalid node
sharing for CALL_EXPRs, I will try to debug again where it comes from.

Honza
>  <call_expr 0xf6eca0f0
>     type <integer_type 0xf6ec6414 int public SI
>         size <integer_cst 0xf6ec33a8 constant invariant 32>
>         unit size <integer_cst 0xf6ec30d8 constant invariant 4>
>         align 32 symtab 0 alias set -1 precision 32 min <integer_cst 0xf6ec3378 -2147483648> max 
> <integer_cst 0xf6ec3390 2147483647>
>         pointer_to_this <pointer_type 0xf6eb39f8>>
>     side-effects
>     arg 0 <addr_expr 0xf6ec2380
>         type <pointer_type 0xf6e3215c type <function_type 0xf6eb66cc>
>             unsigned SI size <integer_cst 0xf6ec33a8 32> unit size <integer_cst 0xf6ec30d8 4>
>             align 32 symtab 0 alias set 5>
>         invariant
>         arg 0 <function_decl 0xf6e2db54 h2 type <function_type 0xf6eb66cc>
>             addressable asm_written used nothrow static decl_5 QI file pr16460.c line 6 context 
> <function_decl 0xf6e2d7b4 g> attributes <tree_list 0xf6e31cc0> result <result_decl 0xf6e32074> 
> initial <error_mark 0xf6ec14c0>
>             (mem:QI (symbol_ref:SI ("h2.1122") [flags 0x3] <function_decl 0xf6e2db54 h2>) [0 S1 A8])>>
>     arg 2 <addr_expr 0xf6ec2500
>         type <pointer_type 0xf6e32658 type <record_type 0xf6e32570 FRAME.g>
>             unsigned SI size <integer_cst 0xf6ec33a8 32> unit size <integer_cst 0xf6ec30d8 4>
>             align 32 symtab 0 alias set -1>
>         invariant
>         arg 0 <var_decl 0xf6e325e4 FRAME.6 type <record_type 0xf6e32570 FRAME.g>
>             addressable used ignored BLK file pr16460.c line 8
>             size <integer_cst 0xf6ec36f0 constant invariant 128>
>             unit size <integer_cst 0xf6ec3708 constant invariant 16>
>             align 32 context <function_decl 0xf6e2d7b4 g> chain <var_decl 0xf6e32244 T.0>>>
>     pr16460.c:7>
> g/7: (inline copy in f/5) 24 insns tree local inlinable
>   called by: f/5 (inlined)
>   calls: __builtin_init_trampoline/4
> pr16460.c:9: internal compiler error: verify_cgraph_node failed.
> Please submit a full bug report,
> with preprocessed source if appropriate.
> See <URL:http://gcc.gnu.org/bugs.html> for instructions.
> 
> -- 
>            What    |Removed                     |Added
> ----------------------------------------------------------------------------
>    Last reconfirmed|2004-07-10 01:48:06         |2004-09-10 08:15:24
>                date|                            |
> 
> 
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16460
> 
> ------- You are receiving this mail because: -------
> You are on the CC list for the bug, or are watching someone who is.
Comment 10 Jan Hubicka 2004-09-10 10:34:15 UTC
Subject: Re:  [3.5 Regression] ICE when compiling glibc (ld-ctype.c)

Hi,
the problem is that we can now inline nested functions across the
boundary of outer function but remove_node kills proactively all the
nested functions when it is done with the outer scope.

I am testing the attached patch.  I actually tried to kill nestedness of
datastructure part of cgraph as suggested by rth other time, but we have
quite a few use of this in the unnesting code itself and few other
places so it looks more convenient to kill it once we are done with
unnesting.

Richard, does this seem sane?  I probably should do that in
unnest_function_tree so it is done at the time unnesting really happens
instead of waiting for the end of compilation.  I will do this change
before putting in the patch if this approach looks sane to you.

Honza

static inline int g(int i) {
  auto inline int h(void);
  auto int h2(void) __attribute__((noinline));
  int h(void) { return i+1; }
  int h2(void) { return h(); }
  return h2();
}
int f(void) { return g(1); }
int f2(void) { return g(1); }

2004-09-10  Jan Hubicka  <jh@suse.cz>
	middle-end/16460
	* cgraphunit.c (decide_is_function_needed): Do not use node->origin.
	(cgraph_finalize_compilation_unit): Kill nestedness datastructure no longer
	important for the backend.

Index: cgraphunit.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cgraphunit.c,v
retrieving revision 1.79
diff -c -3 -p -r1.79 cgraphunit.c
*** cgraphunit.c	10 Sep 2004 08:56:35 -0000	1.79
--- cgraphunit.c	10 Sep 2004 10:27:52 -0000
*************** static FILE *cgraph_dump_file;
*** 220,226 ****
  static bool
  decide_is_function_needed (struct cgraph_node *node, tree decl)
  {
!   struct cgraph_node *origin;
  
    /* If we decided it was needed before, but at the time we didn't have
       the body of the function available, then it's still needed.  We have
--- 220,226 ----
  static bool
  decide_is_function_needed (struct cgraph_node *node, tree decl)
  {
!   tree origin;
  
    /* If we decided it was needed before, but at the time we didn't have
       the body of the function available, then it's still needed.  We have
*************** decide_is_function_needed (struct cgraph
*** 260,267 ****
      return false;
    /* Nested functions of extern inline function shall not be emit unless
       we inlined the origin.  */
!   for (origin = node->origin; origin; origin = origin->origin)
!     if (DECL_EXTERNAL (origin->decl))
        return false;
    /* We want to emit COMDAT functions only when absolutely necessary.  */
    if (DECL_COMDAT (decl))
--- 260,268 ----
      return false;
    /* Nested functions of extern inline function shall not be emit unless
       we inlined the origin.  */
!   for (origin = decl_function_context (decl);
!        origin; origin = decl_function_context (origin))
!     if (DECL_EXTERNAL (origin))
        return false;
    /* We want to emit COMDAT functions only when absolutely necessary.  */
    if (DECL_COMDAT (decl))
*************** cgraph_finalize_compilation_unit (void)
*** 692,697 ****
--- 693,703 ----
        struct cgraph_edge *edge;
        tree decl = cgraph_nodes_queue->decl;
  
+       /* We performed unnesting, so kill the no longer neccesary data.  */
+       node->origin = NULL;
+       node->next_nested = NULL;
+       node->nested = NULL;
+ 
        node = cgraph_nodes_queue;
        cgraph_nodes_queue = cgraph_nodes_queue->next_needed;
        node->next_needed = NULL;
Comment 11 Richard Henderson 2004-09-10 19:07:01 UTC
Subject: Re:  [3.5 Regression] ICE when compiling glibc (ld-ctype.c)

On Fri, Sep 10, 2004 at 12:34:10PM +0200, Jan Hubicka wrote:
> Richard, does this seem sane?  I probably should do that in
> unnest_function_tree so it is done at the time unnesting really happens
> instead of waiting for the end of compilation.  I will do this change
> before putting in the patch if this approach looks sane to you.

I think I would prefer that.  Provide a function in cgraph*.c to
perform the cgraph_node manipulation, and call that from the end
of tree-nested.c.


r~
Comment 12 Jan Hubicka 2004-09-10 23:59:02 UTC
Subject: Re:  [3.5 Regression] ICE when compiling glibc (ld-ctype.c)

> 
> ------- Additional Comments From rth at redhat dot com  2004-09-10 19:07 -------
> Subject: Re:  [3.5 Regression] ICE when compiling glibc (ld-ctype.c)
> 
> On Fri, Sep 10, 2004 at 12:34:10PM +0200, Jan Hubicka wrote:
> > Richard, does this seem sane?  I probably should do that in
> > unnest_function_tree so it is done at the time unnesting really happens
> > instead of waiting for the end of compilation.  I will do this change
> > before putting in the patch if this approach looks sane to you.
> 
> I think I would prefer that.  Provide a function in cgraph*.c to
> perform the cgraph_node manipulation, and call that from the end
> of tree-nested.c.

Yeah, sure, I didn't intend to commit the patch in the current form, I
just got short of time and I was unsure if you don't have different
approach in mind.
I will create updated version, thanks.

Honza
> 
> 
> r~
> 
> 
> -- 
> 
> 
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16460
> 
> ------- You are receiving this mail because: -------
> You are on the CC list for the bug, or are watching someone who is.
Comment 13 GCC Commits 2004-09-20 20:38:35 UTC
Subject: Bug 16460

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	hubicka@gcc.gnu.org	2004-09-20 20:38:29

Modified files:
	gcc            : cgraph.c cgraph.h cgraphunit.c cse.c reload1.c 
	                 tree-nested.c ChangeLog 
	gcc/ada        : ChangeLog utils.c 
	gcc/fortran    : ChangeLog trans-decl.c 

Log message:
	PR middle-end/16460
	
	* cgraph.c (cgraph_unnest_node): New function.
	(c_finalize): Rename to ....
	(c_warn_unused_result_recursivly): ... this one; do only the warning
	(finish_function): Finalize the toplevel function; do not lower nested tree.
	* cgraph.h (cgraph_unnest_node): Declare.
	* cgraphunit.c (decide_is_function_needed): Do not use cgraph
	nestedness datastructure.
	* cse.c (cse_insn): Do not cprop nonlocal LABEL_REFs.
	* reload1.c (set_label_offsets): Fix call of set_label_offsets.
	* tree-nested.c (finlize_nesting_tree_1):  Use un-nesting code.
	
	* utils.c (gnat_finalize): Remove.
	(end_subprog_body): Directly call cgraph_finalize_function;
	do not lower the nested functions.
	
	* trans-decl.c (build_entry_thunks): Finalize the function; do not lower
	tree.
	(gfc_generate_function_code): Likewise.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cgraph.c.diff?cvsroot=gcc&r1=1.57&r2=1.58
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cgraph.h.diff?cvsroot=gcc&r1=1.37&r2=1.38
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cgraphunit.c.diff?cvsroot=gcc&r1=1.83&r2=1.84
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cse.c.diff?cvsroot=gcc&r1=1.313&r2=1.314
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/reload1.c.diff?cvsroot=gcc&r1=1.446&r2=1.447
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/tree-nested.c.diff?cvsroot=gcc&r1=2.18&r2=2.19
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.5534&r2=2.5535
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ada/ChangeLog.diff?cvsroot=gcc&r1=1.564&r2=1.565
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ada/utils.c.diff?cvsroot=gcc&r1=1.82&r2=1.83
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/fortran/ChangeLog.diff?cvsroot=gcc&r1=1.211&r2=1.212
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/fortran/trans-decl.c.diff?cvsroot=gcc&r1=1.43&r2=1.44

Comment 14 Drea Pinski 2004-09-20 20:48:04 UTC
Fixed.