public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/60003] New: [4.9 regression] wrong code with __builtin_setjmp/__builtin_longjmp and inlining
@ 2014-01-30 22:47 ebotcazou at gcc dot gnu.org
  2014-01-30 23:10 ` [Bug tree-optimization/60003] " jakub at gcc dot gnu.org
                   ` (12 more replies)
  0 siblings, 13 replies; 14+ messages in thread
From: ebotcazou at gcc dot gnu.org @ 2014-01-30 22:47 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60003

            Bug ID: 60003
           Summary: [4.9 regression] wrong code with
                    __builtin_setjmp/__builtin_longjmp and inlining
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: major
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ebotcazou at gcc dot gnu.org
                CC: jakub at gcc dot gnu.org
        Depends on: 59920

Created attachment 31995
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=31995&action=edit
Testcase

This is a fallout of the fix for PR tree-opt/59920: the attached testcase
passes at -0O but fails at -O1 (and interestingly passes at -O2) on
x86-64/Linux.  This is apparently related to inlining, see the comment in the
testcase.

Severity is "major" because this breaks the SJLJ exception scheme in Ada, which
has been rock-solid for about a decade.


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug tree-optimization/60003] [4.9 regression] wrong code with __builtin_setjmp/__builtin_longjmp and inlining
  2014-01-30 22:47 [Bug tree-optimization/60003] New: [4.9 regression] wrong code with __builtin_setjmp/__builtin_longjmp and inlining ebotcazou at gcc dot gnu.org
@ 2014-01-30 23:10 ` jakub at gcc dot gnu.org
  2014-01-31  9:00 ` jakub at gcc dot gnu.org
                   ` (11 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: jakub at gcc dot gnu.org @ 2014-01-30 23:10 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60003

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2014-01-30
   Target Milestone|---                         |4.9.0
     Ever confirmed|0                           |1

--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Thanks for the report, will have a look tomorrow.


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug tree-optimization/60003] [4.9 regression] wrong code with __builtin_setjmp/__builtin_longjmp and inlining
  2014-01-30 22:47 [Bug tree-optimization/60003] New: [4.9 regression] wrong code with __builtin_setjmp/__builtin_longjmp and inlining ebotcazou at gcc dot gnu.org
  2014-01-30 23:10 ` [Bug tree-optimization/60003] " jakub at gcc dot gnu.org
@ 2014-01-31  9:00 ` jakub at gcc dot gnu.org
  2014-01-31  9:23 ` jakub at gcc dot gnu.org
                   ` (10 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: jakub at gcc dot gnu.org @ 2014-01-31  9:00 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60003

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Ah, I see what's going on.  eliminate_unnecessary_calls in dce calls
clear_special_calls.  Before my patch, __builtin_setjmp lowering would add a
dummy non-local label to the function, so that while dce would clear
cfun->calls_setjmp, cfun->has_nonlocal_label would be still set, but with my
patch that is no longer happening, so stmt_can_make_abnormal_goto is always
false during inlining and the corresponding edges aren't added.

So, either e.g. tree-cfg.c could just set cfun->has_nonlocal_label when it sees
a __builtin_setjmp_receiver (or say gimple-low.c when lowering __builtin_setjmp
could set it) to restore status quo.

Or I wonder, is there any special reason to avoid cfun->calls_setjmp when you
actually call setjmp?  Like say make __builtin_setjmp_receiver
ECF_RETURNS_TWICE, or just special casing it in notice_special_calls and in the
inliner (which just should call notice_special_calls)?


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug tree-optimization/60003] [4.9 regression] wrong code with __builtin_setjmp/__builtin_longjmp and inlining
  2014-01-30 22:47 [Bug tree-optimization/60003] New: [4.9 regression] wrong code with __builtin_setjmp/__builtin_longjmp and inlining ebotcazou at gcc dot gnu.org
  2014-01-30 23:10 ` [Bug tree-optimization/60003] " jakub at gcc dot gnu.org
  2014-01-31  9:00 ` jakub at gcc dot gnu.org
@ 2014-01-31  9:23 ` jakub at gcc dot gnu.org
  2014-01-31  9:32 ` ebotcazou at gcc dot gnu.org
                   ` (9 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: jakub at gcc dot gnu.org @ 2014-01-31  9:23 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60003

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Created attachment 31997
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=31997&action=edit
gcc49-pr60003-1.patch

Untested quick hack to set cfun->has_nonlocal_label, seems to work on this
testcase.


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug tree-optimization/60003] [4.9 regression] wrong code with __builtin_setjmp/__builtin_longjmp and inlining
  2014-01-30 22:47 [Bug tree-optimization/60003] New: [4.9 regression] wrong code with __builtin_setjmp/__builtin_longjmp and inlining ebotcazou at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2014-01-31  9:23 ` jakub at gcc dot gnu.org
@ 2014-01-31  9:32 ` ebotcazou at gcc dot gnu.org
  2014-01-31  9:36 ` jakub at gcc dot gnu.org
                   ` (8 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: ebotcazou at gcc dot gnu.org @ 2014-01-31  9:32 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60003

--- Comment #4 from Eric Botcazou <ebotcazou at gcc dot gnu.org> ---
> Ah, I see what's going on.  eliminate_unnecessary_calls in dce calls
> clear_special_calls.  Before my patch, __builtin_setjmp lowering would add a
> dummy non-local label to the function, so that while dce would clear
> cfun->calls_setjmp, cfun->has_nonlocal_label would be still set, but with my
> patch that is no longer happening, so stmt_can_make_abnormal_goto is always
> false during inlining and the corresponding edges aren't added.

OK, thanks for analysis.

> So, either e.g. tree-cfg.c could just set cfun->has_nonlocal_label when it
> sees a __builtin_setjmp_receiver (or say gimple-low.c when lowering
> __builtin_setjmp could set it) to restore status quo.

At the RTL level, cfun->has_nonlocal_label is set when __builtin_setjmp_setup
is expanded (in expand_builtin_setjmp_setup) so I think that we should do the
same at the Tree level.  My preference would be for gimple-low.c but no strong
opinion.

> Or I wonder, is there any special reason to avoid cfun->calls_setjmp when
> you actually call setjmp?  Like say make __builtin_setjmp_receiver
> ECF_RETURNS_TWICE, or just special casing it in notice_special_calls and in
> the inliner (which just should call notice_special_calls)?

Historically cfun->calls_setjmp is a big hammer that disables optimization
passes, which was unnecessary for __builtin_setjmp because everything is
exposed in the IL.  Nowadays the distinction with the regular setjmp is less
clear, but I think that we should lean towards clearing cfun->calls_setjmp
rather than setting it, or else reducing its impact on optimization passes.


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug tree-optimization/60003] [4.9 regression] wrong code with __builtin_setjmp/__builtin_longjmp and inlining
  2014-01-30 22:47 [Bug tree-optimization/60003] New: [4.9 regression] wrong code with __builtin_setjmp/__builtin_longjmp and inlining ebotcazou at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2014-01-31  9:32 ` ebotcazou at gcc dot gnu.org
@ 2014-01-31  9:36 ` jakub at gcc dot gnu.org
  2014-01-31  9:38 ` jakub at gcc dot gnu.org
                   ` (7 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: jakub at gcc dot gnu.org @ 2014-01-31  9:36 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60003

--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Created attachment 31998
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=31998&action=edit
gcc49-pr60003-2.patch

Untested variant which makes __builtin_setjmp_receiver a returns twice
function.
For some strange reason this doesn't work, the test hangs.


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug tree-optimization/60003] [4.9 regression] wrong code with __builtin_setjmp/__builtin_longjmp and inlining
  2014-01-30 22:47 [Bug tree-optimization/60003] New: [4.9 regression] wrong code with __builtin_setjmp/__builtin_longjmp and inlining ebotcazou at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2014-01-31  9:36 ` jakub at gcc dot gnu.org
@ 2014-01-31  9:38 ` jakub at gcc dot gnu.org
  2014-01-31  9:46 ` jakub at gcc dot gnu.org
                   ` (6 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: jakub at gcc dot gnu.org @ 2014-01-31  9:38 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60003

--- Comment #6 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Created attachment 31999
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=31999&action=edit
gcc49-pr60003-3.patch

Untested third variant, which just makes sure cfun->calls_setjmp is set even
for __builtin_setjmp_receiver.  This one seems to work for the testcase.


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug tree-optimization/60003] [4.9 regression] wrong code with __builtin_setjmp/__builtin_longjmp and inlining
  2014-01-30 22:47 [Bug tree-optimization/60003] New: [4.9 regression] wrong code with __builtin_setjmp/__builtin_longjmp and inlining ebotcazou at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  2014-01-31  9:38 ` jakub at gcc dot gnu.org
@ 2014-01-31  9:46 ` jakub at gcc dot gnu.org
  2014-01-31  9:58 ` ebotcazou at gcc dot gnu.org
                   ` (5 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: jakub at gcc dot gnu.org @ 2014-01-31  9:46 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60003

--- Comment #7 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
(In reply to Eric Botcazou from comment #4)
> > So, either e.g. tree-cfg.c could just set cfun->has_nonlocal_label when it
> > sees a __builtin_setjmp_receiver (or say gimple-low.c when lowering
> > __builtin_setjmp could set it) to restore status quo.
> 
> At the RTL level, cfun->has_nonlocal_label is set when
> __builtin_setjmp_setup is expanded (in expand_builtin_setjmp_setup) so I
> think that we should do the same at the Tree level.  My preference would be
> for gimple-low.c but no strong opinion.

Ok, so you prefer the first patch?  Now to write some comment explaining why...

> > Or I wonder, is there any special reason to avoid cfun->calls_setjmp when
> > you actually call setjmp?  Like say make __builtin_setjmp_receiver
> > ECF_RETURNS_TWICE, or just special casing it in notice_special_calls and in
> > the inliner (which just should call notice_special_calls)?
> 
> Historically cfun->calls_setjmp is a big hammer that disables optimization
> passes, which was unnecessary for __builtin_setjmp because everything is
> exposed in the IL.  Nowadays the distinction with the regular setjmp is less
> clear, but I think that we should lean towards clearing cfun->calls_setjmp
> rather than setting it, or else reducing its impact on optimization passes.

At GIMPLE level indeed, cfun->calls_setjmp is now purely about whether the
abnormal edges are constructed or not, the tree-tailcall.c use probably could
go.
For normal setjmp calls (and fork etc.) we do nothing though at the RTL level
though, so cfun->calls_setjmp is probably still needed there.


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug tree-optimization/60003] [4.9 regression] wrong code with __builtin_setjmp/__builtin_longjmp and inlining
  2014-01-30 22:47 [Bug tree-optimization/60003] New: [4.9 regression] wrong code with __builtin_setjmp/__builtin_longjmp and inlining ebotcazou at gcc dot gnu.org
                   ` (6 preceding siblings ...)
  2014-01-31  9:46 ` jakub at gcc dot gnu.org
@ 2014-01-31  9:58 ` ebotcazou at gcc dot gnu.org
  2014-01-31 10:21 ` jakub at gcc dot gnu.org
                   ` (4 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: ebotcazou at gcc dot gnu.org @ 2014-01-31  9:58 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60003

--- Comment #8 from Eric Botcazou <ebotcazou at gcc dot gnu.org> ---
> Ok, so you prefer the first patch?  Now to write some comment explaining
> why...

Yes, I'm very fond of one-liners. :-)  You can say that the label taken by
__builtin_setjmp is treated as a non-local label by the middle-end.


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug tree-optimization/60003] [4.9 regression] wrong code with __builtin_setjmp/__builtin_longjmp and inlining
  2014-01-30 22:47 [Bug tree-optimization/60003] New: [4.9 regression] wrong code with __builtin_setjmp/__builtin_longjmp and inlining ebotcazou at gcc dot gnu.org
                   ` (7 preceding siblings ...)
  2014-01-31  9:58 ` ebotcazou at gcc dot gnu.org
@ 2014-01-31 10:21 ` jakub at gcc dot gnu.org
  2014-01-31 10:41 ` rguenth at gcc dot gnu.org
                   ` (3 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: jakub at gcc dot gnu.org @ 2014-01-31 10:21 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60003

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |jakub at gcc dot gnu.org

--- Comment #9 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Created attachment 32000
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=32000&action=edit
gcc49-pr60003.patch

Ok, so this is what I'm going to bootstrap/regtest.


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug tree-optimization/60003] [4.9 regression] wrong code with __builtin_setjmp/__builtin_longjmp and inlining
  2014-01-30 22:47 [Bug tree-optimization/60003] New: [4.9 regression] wrong code with __builtin_setjmp/__builtin_longjmp and inlining ebotcazou at gcc dot gnu.org
                   ` (8 preceding siblings ...)
  2014-01-31 10:21 ` jakub at gcc dot gnu.org
@ 2014-01-31 10:41 ` rguenth at gcc dot gnu.org
  2014-02-01  8:41 ` jakub at gcc dot gnu.org
                   ` (2 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: rguenth at gcc dot gnu.org @ 2014-01-31 10:41 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60003

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P1


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug tree-optimization/60003] [4.9 regression] wrong code with __builtin_setjmp/__builtin_longjmp and inlining
  2014-01-30 22:47 [Bug tree-optimization/60003] New: [4.9 regression] wrong code with __builtin_setjmp/__builtin_longjmp and inlining ebotcazou at gcc dot gnu.org
                   ` (9 preceding siblings ...)
  2014-01-31 10:41 ` rguenth at gcc dot gnu.org
@ 2014-02-01  8:41 ` jakub at gcc dot gnu.org
  2014-02-01  9:08 ` jakub at gcc dot gnu.org
  2014-02-04 10:51 ` dominiq at lps dot ens.fr
  12 siblings, 0 replies; 14+ messages in thread
From: jakub at gcc dot gnu.org @ 2014-02-01  8:41 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60003

--- Comment #10 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Author: jakub
Date: Sat Feb  1 08:40:31 2014
New Revision: 207382

URL: http://gcc.gnu.org/viewcvs?rev=207382&root=gcc&view=rev
Log:
    PR tree-optimization/60003
    * gimple-low.c (lower_builtin_setjmp): Set cfun->has_nonlocal_label.
    * profile.c (branch_prob): Use gimple_call_builtin_p
    to check for BUILT_IN_SETJMP_RECEIVER.
    * tree-inline.c (copy_bb): Call notice_special_calls.

    * gcc.c-torture/execute/pr60003.c: New test.

Added:
    trunk/gcc/testsuite/gcc.c-torture/execute/pr60003.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/gimple-low.c
    trunk/gcc/profile.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree-inline.c


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug tree-optimization/60003] [4.9 regression] wrong code with __builtin_setjmp/__builtin_longjmp and inlining
  2014-01-30 22:47 [Bug tree-optimization/60003] New: [4.9 regression] wrong code with __builtin_setjmp/__builtin_longjmp and inlining ebotcazou at gcc dot gnu.org
                   ` (10 preceding siblings ...)
  2014-02-01  8:41 ` jakub at gcc dot gnu.org
@ 2014-02-01  9:08 ` jakub at gcc dot gnu.org
  2014-02-04 10:51 ` dominiq at lps dot ens.fr
  12 siblings, 0 replies; 14+ messages in thread
From: jakub at gcc dot gnu.org @ 2014-02-01  9:08 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60003

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #11 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Fixed.


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug tree-optimization/60003] [4.9 regression] wrong code with __builtin_setjmp/__builtin_longjmp and inlining
  2014-01-30 22:47 [Bug tree-optimization/60003] New: [4.9 regression] wrong code with __builtin_setjmp/__builtin_longjmp and inlining ebotcazou at gcc dot gnu.org
                   ` (11 preceding siblings ...)
  2014-02-01  9:08 ` jakub at gcc dot gnu.org
@ 2014-02-04 10:51 ` dominiq at lps dot ens.fr
  12 siblings, 0 replies; 14+ messages in thread
From: dominiq at lps dot ens.fr @ 2014-02-04 10:51 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60003

Dominique d'Humieres <dominiq at lps dot ens.fr> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dominiq at lps dot ens.fr

--- Comment #12 from Dominique d'Humieres <dominiq at lps dot ens.fr> ---
*** Bug 60006 has been marked as a duplicate of this bug. ***


^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2014-02-04 10:51 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-01-30 22:47 [Bug tree-optimization/60003] New: [4.9 regression] wrong code with __builtin_setjmp/__builtin_longjmp and inlining ebotcazou at gcc dot gnu.org
2014-01-30 23:10 ` [Bug tree-optimization/60003] " jakub at gcc dot gnu.org
2014-01-31  9:00 ` jakub at gcc dot gnu.org
2014-01-31  9:23 ` jakub at gcc dot gnu.org
2014-01-31  9:32 ` ebotcazou at gcc dot gnu.org
2014-01-31  9:36 ` jakub at gcc dot gnu.org
2014-01-31  9:38 ` jakub at gcc dot gnu.org
2014-01-31  9:46 ` jakub at gcc dot gnu.org
2014-01-31  9:58 ` ebotcazou at gcc dot gnu.org
2014-01-31 10:21 ` jakub at gcc dot gnu.org
2014-01-31 10:41 ` rguenth at gcc dot gnu.org
2014-02-01  8:41 ` jakub at gcc dot gnu.org
2014-02-01  9:08 ` jakub at gcc dot gnu.org
2014-02-04 10:51 ` dominiq at lps dot ens.fr

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).