Bug 26983 - [4.0 Regression] Missing label with builtin_setjmp/longjmp
Summary: [4.0 Regression] Missing label with builtin_setjmp/longjmp
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.1.0
: P1 normal
Target Milestone: 4.0.4
Assignee: Not yet assigned to anyone
URL: http://gcc.gnu.org/ml/gcc-patches/200...
Keywords: assemble-failure, link-failure, monitored, patch
Depends on:
Blocks:
 
Reported: 2006-04-02 02:07 UTC by hebisch
Modified: 2006-09-22 15:40 UTC (History)
3 users (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work: 3.4.4 4.2.0 4.1.2
Known to fail: 4.0.2 4.1.0
Last reconfirmed: 2006-07-27 13:25:04


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description hebisch 2006-04-02 02:07:02 UTC
The following program:

void
Object (void)
{
void * jmpbuf_1[6];
void P (void)
{
  {
    void * jmpbuf_3[6];

    if (__builtin_setjmp (&jmpbuf_3)) goto nonlocal_exit_2; else (void) 0;;
    __builtin_longjmp (&jmpbuf_1, 1);
    nonlocal_exit_2:;;
  }
}
  {
    if (__builtin_setjmp (&jmpbuf_1)) goto nonlocal_exit_0; else (void) 0;;
    P ();
    nonlocal_exit_0:;;
  }
}

int
main(void)
{
  Object ();
}

gives me:
../gcc-lin/prev-gcc/xgcc -B../gcc-lin/prev-gcc mjmp2.c/tmp/cc06O64A.o(.text+0x5a): In function `P.1525':
: undefined reference to `.L8'
collect2: ld returned 1 exit status

Using gcc-4.2-20060401. The problem also shows up with gcc-4.0.2 and
gcc-4.1.0 on amd64. Also the problem shows in the output of a
cross-compiler targetting powerpc-apple-darwin7. The original problem
was discovered in GNU Pascal on powerpc-apple-darwin7 and the program
above tries to reproduce Pascal problem. The program compiles using
gcc-3.4.4.
Comment 1 Andrew Pinski 2006-04-02 08:59:40 UTC
Confirmed.
Comment 2 Steven Bosscher 2006-06-11 08:55:49 UTC
I can't reproduce this with ToT.
Comment 3 Andrew Pinski 2006-06-11 13:35:04 UTC
Still reproducible on powerpc-darwin with 4.2.0 20060608.
Comment 4 Steven Bosscher 2006-07-25 22:52:53 UTC
In the .104.expand dump we have:

(insn 10 9 11 3 (set (reg/f:SI 63)
        (label_ref:SI 16)) -1 (nil)
    (insn_list:REG_LABEL 16 (nil)))

and

;; Start of basic block 4, registers live: (nil)
(code_label 16 15 52 4 8 "" [1 uses])


But in the .105.sibling dump, we have already lost the label and in fact the entire basic block 4.  Apparently gcc decides that the block is unreachable...?
Comment 5 Volker Reichelt 2006-07-27 13:00:06 UTC
Here's a reduced testcase without nested functions:

====================================
void* jmpbuf[6];

void foo()
{
    __builtin_setjmp (jmpbuf);
}

int main()
{
    return 0;
}
====================================
Comment 6 Steven Bosscher 2006-07-27 13:25:04 UTC
Thanks Volkert.  I had a test case like that, I should have put it in this audit trail.

I am *so* going to fix this bug.  I think...
Comment 7 Aaron Graham 2006-08-02 17:03:49 UTC
Is it possible that #28493 is a symptom of the same problem?  Does anyone build the darwin compiler with SjLj exceptions?
Comment 8 Andrew Pinski 2006-08-02 17:24:26 UTC
(In reply to comment #7)
> Is it possible that #28493 is a symptom of the same problem?  Does anyone build
> the darwin compiler with SjLj exceptions?

Why would they, dwarf-2 eh's overhead is much smaller if throws are not done than sjlj exceptions.  Also I think this is a different problem and the problem in the other PR is much older (dates back to 3.3/3.4 at least).
Comment 9 Steven Bosscher 2006-09-10 10:59:55 UTC
In GCC3, the label is not removed because it is in label_value_list.  In GCC4 we don't have that list anymore. That means we have to trust LABEL_NUSES, or we have to force preservation of the label via LABEL_PRESERVE_P.  I'm inclined to go with the former, but LABEL_NUSES is notoriously unreliable so I'm not entirely comfortable with using it... :-/


Comment 10 Steven Bosscher 2006-09-10 11:16:38 UTC
I've decided to go with LABEL_PRESERVE_P after all...

Index: builtins.c
===================================================================
--- builtins.c  (revision 116785)
+++ builtins.c  (working copy)
@@ -760,6 +760,12 @@ expand_builtin_setjmp (tree arglist, rtx

   emit_label (next_lab);

+  /* Because setjmp and longjmp are not represented in the CFG, a cfgcleanup
+     may find that the basic block starting with NEXT_LAB is unreachable.
+     The whole block, along with NEXT_LAB, would be removed.  Make sure that
+     never happens.  */
+  LABEL_PRESERVE_P (next_lab) = 1;
+
   expand_builtin_setjmp_receiver (next_lab);

   /* Set TARGET to one.  */
Comment 11 patchapp@dberlin.org 2006-09-10 18:40:21 UTC
Subject: Bug number PR26983

A patch for this bug has been added to the patch tracker.
The mailing list url for the patch is http://gcc.gnu.org/ml/gcc-patches/2006-09/msg00370.html
Comment 12 Steven Bosscher 2006-09-10 20:09:07 UTC
Subject: Bug 26983

Author: steven
Date: Sun Sep 10 20:08:58 2006
New Revision: 116826

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=116826
Log:
PR middle-end/26983

gcc/
	* builtins.c (expand_builtin_setjmp): Force next_lab to be
	preserved.

testsuite/
	* gcc.dg/pr26983.c: New test.

Added:
    trunk/gcc/testsuite/gcc.dg/pr26983.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/builtins.c
    trunk/gcc/testsuite/ChangeLog

Comment 13 Steven Bosscher 2006-09-10 20:10:05 UTC
Fixed on the trunk.
Comment 14 Roger Sayle 2006-09-21 02:13:57 UTC
Subject: Bug 26983

Author: sayle
Date: Thu Sep 21 02:13:48 2006
New Revision: 117106

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=117106
Log:
2006-09-20  Steven Bosscher  <steven@gcc.gnu.org>

	PR middle-end/26983
	Backport from mainline
	* builtins.c (expand_builtin_setjmp): Force next_lab to be
	preserved.

	* gcc.dg/pr26983.c: New test.


Added:
    branches/gcc-4_1-branch/gcc/testsuite/gcc.dg/pr26983.c
Modified:
    branches/gcc-4_1-branch/gcc/ChangeLog
    branches/gcc-4_1-branch/gcc/builtins.c
    branches/gcc-4_1-branch/gcc/testsuite/ChangeLog

Comment 15 Roger Sayle 2006-09-21 23:38:31 UTC
Subject: Bug 26983

Author: sayle
Date: Thu Sep 21 23:38:21 2006
New Revision: 117125

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=117125
Log:
2006-09-21  Steven Bosscher  <steven@gcc.gnu.org>

	PR middle-end/26983
	Backport from mainline
	* builtins.c (expand_builtin_setjmp): Force next_lab to be
	preserved.

	* gcc.dg/pr26983.c: New test.


Added:
    branches/gcc-4_0-branch/gcc/testsuite/gcc.dg/pr26983.c
Modified:
    branches/gcc-4_0-branch/gcc/ChangeLog
    branches/gcc-4_0-branch/gcc/builtins.c
    branches/gcc-4_0-branch/gcc/testsuite/ChangeLog

Comment 16 roger 2006-09-22 15:40:39 UTC
Fixed everywhere.  Eric even has an improved patch/fix for mainline, but the
backports of this change are sufficient to resolve the current PR.  Thanks
to Steven for coming up with the solution.