Bug 24135 - [4.0/4.1 Regression] nonlocal goto from nested function gets 'undefined symbol' in assembler
Summary: [4.0/4.1 Regression] nonlocal goto from nested function gets 'undefined symbo...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.0.2
: P2 normal
Target Milestone: 4.0.3
Assignee: Richard Henderson
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2005-09-29 23:47 UTC by Alexey Starovoytov
Modified: 2005-10-03 22:05 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work: 3.4.0
Known to fail: 4.0.0 4.1.0
Last reconfirmed: 2005-10-03 18:58:07


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alexey Starovoytov 2005-09-29 23:47:58 UTC
The following code compiled with just -O0 generates bad assembler with
undefined label:

int x(int a, int b)
{
  __label__ xlab;
  __label__ xlab2;

  void y(int b)
    {
       switch (b)
        {
          case 1: goto xlab;
          case 2: goto xlab;
        }
    }

  a = a + 2;

  y (b);

 xlab:;
  return a;

 xlab2:;
      a++;
  return a;

}

main (int ac)
{
  int i;
  if ((i=x (1, ac), printf("%d\n",i), i) != 2 + ac)
    abort ();

  exit (0);
}

The assembler failure looks like:
Undefined                       first referenced
 symbol                             in file
.LL9                                /var/tmp//ccLPhTcj.o
ld: fatal: Symbol referencing errors. No output written to a.out

The t04.nested tree already looks bad:
----------------------------------
y (b)
{
  voidD.28 *[3] * D.1136;
  voidD.28 *[3] * D.1138;

  switch (bD.1124)
    {
      case 1: goto <D1127>;
      case 2: goto <D1128>;
      default : goto <D1131>;
    }
  <D1127>:;
  D.1136 = &CHAIN.1D.1135->__nl_goto_bufD.1133;
  __builtin_nonlocal_goto (&<D1132>, D.1136);
  <D1128>:;
  D.1138 = &CHAIN.1D.1135->__nl_goto_bufD.1133;
  __builtin_nonlocal_goto (&<D1137>, D.1138);
  <D1131>:;
}

x (a, b)
{ 
  struct FRAME.x FRAME.0D.1134;
  intD.0 D.1129;
  voidD.28 xlabD.1122 = <<< error >>>;
  voidD.28 xlab2D.1123 = <<< error >>>;
  static voidD.28 yD.1125 (intD.0);
  
  aD.1118 = aD.1118 + 2;
  y (bD.1119) [static-chain: &FRAME.0D.1134];
  goto xlabD.1122;
  <D1137>: [non-local];
  xlabD.1122:;
  D.1129 = aD.1118;
  return D.1129;
  xlab2D.1123:;
  aD.1118 = aD.1118 + 1;
  D.1129 = aD.1118;
  return D.1129;
}
----------------------------------

The line with problems:  __builtin_nonlocal_goto (&<D1132>, D.1136);

The reference to &<D1132> is a reference to non-existent label.
This problem can be reproduced on all 4.0.* versions and 4.1-20050924 as well.
The versions 3.x are ok.

I think all hardware platforms may be affected.

Alex.
Comment 1 Andrew Pinski 2005-09-29 23:55:29 UTC
Confirmed.  We already go wrong in .nested.
Comment 2 janis187 2005-10-03 16:24:19 UTC
A regression hunt for powerpc-linux on mainline identified the merge of the
tree-ssa branch.
Comment 3 GCC Commits 2005-10-03 20:57:50 UTC
Subject: Bug 24135

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	rth@gcc.gnu.org	2005-10-03 20:57:45

Modified files:
	gcc            : ChangeLog tree-nested.c 
Added files:
	gcc/testsuite/gcc.c-torture/execute: pr24135.c 

Log message:
	PR 24135
	* tree-nested.c (convert_nl_goto_reference): Lookup a translation
	before creating a new one.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.10070&r2=2.10071
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/tree-nested.c.diff?cvsroot=gcc&r1=2.31&r2=2.32
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.c-torture/execute/pr24135.c.diff?cvsroot=gcc&r1=NONE&r2=1.1

Comment 4 GCC Commits 2005-10-03 22:02:02 UTC
Subject: Bug 24135

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-4_0-branch
Changes by:	rth@gcc.gnu.org	2005-10-03 22:01:55

Modified files:
	gcc            : ChangeLog tree-nested.c 
Added files:
	gcc/testsuite/gcc.c-torture/execute: pr24135.c 

Log message:
	PR 24135
	* tree-nested.c (convert_nl_goto_reference): Lookup a translation
	before creating a new one.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=2.7592.2.441&r2=2.7592.2.442
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/tree-nested.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=2.24.10.1&r2=2.24.10.2
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.c-torture/execute/pr24135.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=NONE&r2=1.1.2.1

Comment 5 Richard Henderson 2005-10-03 22:05:20 UTC
Fixed.