Bug 16864

Summary: [4.0 Regression] Segmentation fault during tree tail call elimination
Product: gcc Reporter: Daniel Berlin <dberlin>
Component: tree-optimizationAssignee: Zdenek Dvorak <rakdver>
Status: RESOLVED FIXED    
Severity: normal CC: gcc-bugs
Priority: P2 Keywords: ice-on-valid-code, patch
Version: 4.0.0   
Target Milestone: 4.0.0   
Host: i686-pc-linux-gnu Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu Known to work:
Known to fail: Last reconfirmed: 2004-08-03 20:49:02
Attachments: Minimal testcase for this bug

Description Daniel Berlin 2004-08-03 20:06:02 UTC
The attached testcase causes a segmentation fault in tree tailcall elimination. 
It looks like it expects local1 (a static), to have a default_def, which it 
doesn't
Comment 1 Daniel Berlin 2004-08-03 20:06:51 UTC
Created attachment 6874 [details]
Minimal testcase for this bug
Comment 2 Daniel Berlin 2004-08-03 20:10:05 UTC
Sorry, thought Zdenek wrote the tailcall part 
Comment 3 Zdenek Dvorak 2004-08-04 12:27:38 UTC
Actually I believe the code in question is mine.

This patch should fix the problem, I will send it to gcc-patches once
it passes testing.

Index: tree-tailcall.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-tailcall.c,v
retrieving revision 2.19
diff -c -3 -p -r2.19 tree-tailcall.c
*** tree-tailcall.c     28 Jul 2004 05:13:09 -0000      2.19
--- tree-tailcall.c     4 Aug 2004 12:24:55 -0000
*************** eliminate_tail_call (struct tailcall *t)
*** 730,736 ****
        if (!phi)
        {
          tree name = var_ann (param)->default_def;
!         tree new_name = make_ssa_name (param, SSA_NAME_DEF_STMT (name));

          var_ann (param)->default_def = new_name;
          phi = create_phi_node (name, first);
--- 730,746 ----
        if (!phi)
        {
          tree name = var_ann (param)->default_def;
!         tree new_name;
!
!         if (!name)
!           {
!             /* It may happen that the tag does not have a default_def in case
!                when all uses of it are dominated by a MUST_DEF.  This however
!                means that it is not necessary to add a phi node for this
!                tag.  */
!             continue;
!           }
!         new_name = make_ssa_name (param, SSA_NAME_DEF_STMT (name));

          var_ann (param)->default_def = new_name;
          phi = create_phi_node (name, first);
Comment 4 GCC Commits 2004-08-05 08:42:01 UTC
Subject: Bug 16864

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	rakdver@gcc.gnu.org	2004-08-05 08:41:57

Modified files:
	gcc            : ChangeLog tree-tailcall.c 

Log message:
	PR tree-optimization/16864
	* tree-tailcall.c (eliminate_tail_call): Do not create phi nodes
	for ssa names without default_def.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.4808&r2=2.4809
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/tree-tailcall.c.diff?cvsroot=gcc&r1=2.19&r2=2.20

Comment 5 Zdenek Dvorak 2004-08-05 08:42:22 UTC
Fixed.