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.
Confirmed.
I can't reproduce this with ToT.
Still reproducible on powerpc-darwin with 4.2.0 20060608.
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...?
Here's a reduced testcase without nested functions: ==================================== void* jmpbuf[6]; void foo() { __builtin_setjmp (jmpbuf); } int main() { return 0; } ====================================
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...
Is it possible that #28493 is a symptom of the same problem? Does anyone build the darwin compiler with SjLj exceptions?
(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).
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... :-/
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. */
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
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
Fixed on the trunk.
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
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
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.