public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/57067] New: Missing control flow edges for setjmp/longjmp
@ 2013-04-25  8:23 krebbel at gcc dot gnu.org
  2013-04-25  9:17 ` [Bug rtl-optimization/57067] " rguenth at gcc dot gnu.org
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: krebbel at gcc dot gnu.org @ 2013-04-25  8:23 UTC (permalink / raw)
  To: gcc-bugs


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

             Bug #: 57067
           Summary: Missing control flow edges for setjmp/longjmp
    Classification: Unclassified
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: krebbel@gcc.gnu.org


The fix for PR56982 adds abnormal control flow edges from function calls to a
setjmp call in the same function. Unfortunately these edges do not survive
until RTL so that the RTL passes might still do the wrong thing. 

The edges are removed in gimple_expand_cfg:

      /* At the moment not all abnormal edges match the RTL
         representation.  It is safe to remove them here as
         find_many_sub_basic_blocks will rediscover them.
         In the future we should get this fixed properly.  */
      if ((e->flags & EDGE_ABNORMAL)
          && !(e->flags & EDGE_SIBCALL))
        remove_edge (e);
      else
        ei_next (&ei);


find_many_sub_basic_blocks needs a fix to add them back as well.

I don't have a testcase for GCC head.  The testcase I have fails only with GCC
4.4: http://gcc.gnu.org/ml/gcc/2013-04/msg00237.html

In this case the RTL scheduler pass generates broken code due to the missing
control flow info.  I think this could potentially happen with GCC head as
well.


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

* [Bug rtl-optimization/57067] Missing control flow edges for setjmp/longjmp
  2013-04-25  8:23 [Bug rtl-optimization/57067] New: Missing control flow edges for setjmp/longjmp krebbel at gcc dot gnu.org
@ 2013-04-25  9:17 ` rguenth at gcc dot gnu.org
  2013-04-25 14:46 ` krebbel at gcc dot gnu.org
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: rguenth at gcc dot gnu.org @ 2013-04-25  9:17 UTC (permalink / raw)
  To: gcc-bugs


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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2013-04-25
                 CC|                            |matz at gcc dot gnu.org,
                   |                            |rguenth at gcc dot gnu.org
     Ever Confirmed|0                           |1

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> 2013-04-25 09:17:03 UTC ---
I suppose more selectively removing edges would be best.  Eventually this is
done to cater for expansions of builtin calls to non-calls?  Then maybe
those edges should be removed later, _after_ builtin expansion and
find_many_sub_basic_blocks?


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

* [Bug rtl-optimization/57067] Missing control flow edges for setjmp/longjmp
  2013-04-25  8:23 [Bug rtl-optimization/57067] New: Missing control flow edges for setjmp/longjmp krebbel at gcc dot gnu.org
  2013-04-25  9:17 ` [Bug rtl-optimization/57067] " rguenth at gcc dot gnu.org
@ 2013-04-25 14:46 ` krebbel at gcc dot gnu.org
  2013-04-25 15:11 ` rguenther at suse dot de
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: krebbel at gcc dot gnu.org @ 2013-04-25 14:46 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #2 from Andreas Krebbel <krebbel at gcc dot gnu.org> 2013-04-25 14:46:09 UTC ---
(In reply to comment #1)
> I suppose more selectively removing edges would be best.  Eventually this is
> done to cater for expansions of builtin calls to non-calls?  Then maybe
> those edges should be removed later, _after_ builtin expansion and
> find_many_sub_basic_blocks?

Wouldn't it be better to keep all the edges and fix the fallout from the RTL
passes?

Do you remember any example where this currently fails?

I've verified with GCC 4.4 that dropping the edge removal code from cfgexpand.c
together with a backport of the PR56982 patch fixes the actual problem.


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

* [Bug rtl-optimization/57067] Missing control flow edges for setjmp/longjmp
  2013-04-25  8:23 [Bug rtl-optimization/57067] New: Missing control flow edges for setjmp/longjmp krebbel at gcc dot gnu.org
  2013-04-25  9:17 ` [Bug rtl-optimization/57067] " rguenth at gcc dot gnu.org
  2013-04-25 14:46 ` krebbel at gcc dot gnu.org
@ 2013-04-25 15:11 ` rguenther at suse dot de
  2013-04-29 16:58 ` gretay at gcc dot gnu.org
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: rguenther at suse dot de @ 2013-04-25 15:11 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #3 from rguenther at suse dot de <rguenther at suse dot de> 2013-04-25 15:11:00 UTC ---
On Thu, 25 Apr 2013, krebbel at gcc dot gnu.org wrote:

> 
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57067
> 
> --- Comment #2 from Andreas Krebbel <krebbel at gcc dot gnu.org> 2013-04-25 14:46:09 UTC ---
> (In reply to comment #1)
> > I suppose more selectively removing edges would be best.  Eventually this is
> > done to cater for expansions of builtin calls to non-calls?  Then maybe
> > those edges should be removed later, _after_ builtin expansion and
> > find_many_sub_basic_blocks?
> 
> Wouldn't it be better to keep all the edges and fix the fallout from the RTL
> passes?

Yes, we should be able to prune them when expansion sees that is 
necessary.

> Do you remember any example where this currently fails?

Not sure.  Run bootstrap & testing?


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

* [Bug rtl-optimization/57067] Missing control flow edges for setjmp/longjmp
  2013-04-25  8:23 [Bug rtl-optimization/57067] New: Missing control flow edges for setjmp/longjmp krebbel at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2013-04-25 15:11 ` rguenther at suse dot de
@ 2013-04-29 16:58 ` gretay at gcc dot gnu.org
  2013-05-14 11:15 ` rguenth at gcc dot gnu.org
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: gretay at gcc dot gnu.org @ 2013-04-29 16:58 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #4 from gretay at gcc dot gnu.org 2013-04-29 16:58:34 UTC ---
Created attachment 29974
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=29974
testcase

The attached test case fails for arm-none-eabi on trunk, caused by r198096 (the
fix for PR56982). It seems related to this PR because the control flow edge
after testing the return value of malloc disappears and it is sensitive to the
setjmp() call placement.

Compile with:
/work/apr-builds/r198096/install/bin/arm-none-eabi-gcc -O1 -mcpu=cortex-a15
pr57067.c -o bad.elf
The test case should print PASS, but it prints FAIL.


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

* [Bug rtl-optimization/57067] Missing control flow edges for setjmp/longjmp
  2013-04-25  8:23 [Bug rtl-optimization/57067] New: Missing control flow edges for setjmp/longjmp krebbel at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2013-04-29 16:58 ` gretay at gcc dot gnu.org
@ 2013-05-14 11:15 ` rguenth at gcc dot gnu.org
  2013-05-17 14:03 ` gretay at gcc dot gnu.org
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: rguenth at gcc dot gnu.org @ 2013-05-14 11:15 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Richard Biener <rguenth at gcc dot gnu.org> ---
The RTL except.c:can_nonlocal_goto () function does not consider setjmp.
Does

Index: gcc/except.c
===================================================================
--- gcc/except.c        (revision 198867)
+++ gcc/except.c        (working copy)
@@ -1936,7 +1936,9 @@ insn_nothrow_p (const_rtx insn)
 bool
 can_nonlocal_goto (const_rtx insn)
 {
-  if (nonlocal_goto_handler_labels && CALL_P (insn))
+  if ((nonlocal_goto_handler_labels
+       || cfun->calls_stjmp)
+      && CALL_P (insn))
     {
       rtx note = find_reg_note (insn, REG_EH_REGION, NULL_RTX);
       if (!note || INTVAL (XEXP (note, 0)) != INT_MIN)

fix it?

For retaining edges we have to teach find_many_sub_basic_blocks to treat
abnormal outgoing edges similar to EH outgoing edges - they have to be
re-directed from the block ending in the actual call (and made
EDGE_ABNORMAL_CALL which doesn't exist on the GIMPLE CFG).

Also

          if ((e->flags & EDGE_ABNORMAL)
              && !(e->flags & EDGE_SIBCALL))
            remove_edge (e);

will happily remove an EDGE_FALLTHRU|EDGE_ABNORMAL edge.


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

* [Bug rtl-optimization/57067] Missing control flow edges for setjmp/longjmp
  2013-04-25  8:23 [Bug rtl-optimization/57067] New: Missing control flow edges for setjmp/longjmp krebbel at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2013-05-14 11:15 ` rguenth at gcc dot gnu.org
@ 2013-05-17 14:03 ` gretay at gcc dot gnu.org
  2014-12-10 12:37 ` rguenth at gcc dot gnu.org
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: gretay at gcc dot gnu.org @ 2013-05-17 14:03 UTC (permalink / raw)
  To: gcc-bugs

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

gretay at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |gretay at gcc dot gnu.org

--- Comment #6 from gretay at gcc dot gnu.org ---
I tried the proposed patch (after fixing a typo: calls_setjmp / calls_stjmp).
It causes an ICE on the attached testcase (and some regressions):

$ /work/apr-builds/pr57067/install/bin/arm-none-eabi-gcc -O1 -mcpu=cortex-a15
pr57067.c -o pr57067.elf 
pr57067.c: In function 'main':
pr57067.c:18:7: warning: incompatible implicit declaration of built-in function
'malloc' [enabled by default]
   p = malloc (0x1000);
       ^
pr57067.c:22:7: warning: incompatible implicit declaration of built-in function
'printf' [enabled by default]
       printf ("\nFAIL\n");
       ^
pr57067.c:23:7: warning: incompatible implicit declaration of built-in function
'exit' [enabled by default]
       exit (1);
       ^
pr57067.c:32:3: warning: incompatible implicit declaration of built-in function
'printf' [enabled by default]
   printf ("\nPASS\n");
   ^
pr57067.c:34:1: error: in basic block 2:
 }
 ^
pr57067.c:34:1: error: flow control insn inside a basic block
(call_insn 8 7 9 2 (parallel [
            (set (reg:SI 0 r0)
                (call (mem:SI (symbol_ref:SI ("malloc") [flags 0x41]
<function_decl 0x7f0cc7362900 malloc>) [0 __builtin_malloc S4 A32])
                    (const_int 0 [0])))
            (use (const_int 0 [0]))
            (clobber (reg:SI 14 lr))
        ]) pr57067.c:18 -1
     (expr_list:REG_EH_REGION (const_int 0 [0])
        (nil))
    (expr_list:REG_CFA_WINDOW_SAVE (use (reg:SI 0 r0))
        (nil)))
pr57067.c:34:1: internal compiler error: in rtl_verify_flow_info_1, at
cfgrtl.c:2321
0x7cc383 _fatal_insn(char const*, rtx_def const*, char const*, int, char
const*)
    /work/local-checkouts/gcc-fsf/gcc/rtl-error.c:109
0x52ed65 rtl_verify_flow_info_1
    /work/local-checkouts/gcc-fsf/gcc/cfgrtl.c:2321
0x52efb2 rtl_verify_flow_info
    /work/local-checkouts/gcc-fsf/gcc/cfgrtl.c:2345
0x51ef49 verify_flow_info()
    /work/local-checkouts/gcc-fsf/gcc/cfghooks.c:258
0xc02464 try_optimize_cfg
    /work/local-checkouts/gcc-fsf/gcc/cfgcleanup.c:2812
0xc02464 cleanup_cfg(int)
    /work/local-checkouts/gcc-fsf/gcc/cfgcleanup.c:2974
0x51c7dd gimple_expand_cfg
    /work/local-checkouts/gcc-fsf/gcc/cfgexpand.c:4781


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

* [Bug rtl-optimization/57067] Missing control flow edges for setjmp/longjmp
  2013-04-25  8:23 [Bug rtl-optimization/57067] New: Missing control flow edges for setjmp/longjmp krebbel at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  2013-05-17 14:03 ` gretay at gcc dot gnu.org
@ 2014-12-10 12:37 ` rguenth at gcc dot gnu.org
  2022-12-15 18:02 ` pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: rguenth at gcc dot gnu.org @ 2014-12-10 12:37 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57067
Bug 57067 depends on bug 56982, which changed state.

Bug 56982 Summary: [4.8 Regression] Bad optimization with setjmp()
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56982

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


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

* [Bug rtl-optimization/57067] Missing control flow edges for setjmp/longjmp
  2013-04-25  8:23 [Bug rtl-optimization/57067] New: Missing control flow edges for setjmp/longjmp krebbel at gcc dot gnu.org
                   ` (6 preceding siblings ...)
  2014-12-10 12:37 ` rguenth at gcc dot gnu.org
@ 2022-12-15 18:02 ` pinskia at gcc dot gnu.org
  2022-12-15 18:04 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-12-15 18:02 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57067

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |qinzhao at gcc dot gnu.org

--- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 108132 has been marked as a duplicate of this bug. ***

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

* [Bug rtl-optimization/57067] Missing control flow edges for setjmp/longjmp
  2013-04-25  8:23 [Bug rtl-optimization/57067] New: Missing control flow edges for setjmp/longjmp krebbel at gcc dot gnu.org
                   ` (7 preceding siblings ...)
  2022-12-15 18:02 ` pinskia at gcc dot gnu.org
@ 2022-12-15 18:04 ` pinskia at gcc dot gnu.org
  2022-12-15 18:33 ` amonakov at gcc dot gnu.org
  2022-12-15 19:33 ` pinskia at gcc dot gnu.org
  10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-12-15 18:04 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57067

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |fxue at os dot amperecomputing.com

--- Comment #8 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 108117 has been marked as a duplicate of this bug. ***

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

* [Bug rtl-optimization/57067] Missing control flow edges for setjmp/longjmp
  2013-04-25  8:23 [Bug rtl-optimization/57067] New: Missing control flow edges for setjmp/longjmp krebbel at gcc dot gnu.org
                   ` (8 preceding siblings ...)
  2022-12-15 18:04 ` pinskia at gcc dot gnu.org
@ 2022-12-15 18:33 ` amonakov at gcc dot gnu.org
  2022-12-15 19:33 ` pinskia at gcc dot gnu.org
  10 siblings, 0 replies; 12+ messages in thread
From: amonakov at gcc dot gnu.org @ 2022-12-15 18:33 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57067

--- Comment #9 from Alexander Monakov <amonakov at gcc dot gnu.org> ---
*** Bug 108117 has been marked as a duplicate of this bug. ***

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

* [Bug rtl-optimization/57067] Missing control flow edges for setjmp/longjmp
  2013-04-25  8:23 [Bug rtl-optimization/57067] New: Missing control flow edges for setjmp/longjmp krebbel at gcc dot gnu.org
                   ` (9 preceding siblings ...)
  2022-12-15 18:33 ` amonakov at gcc dot gnu.org
@ 2022-12-15 19:33 ` pinskia at gcc dot gnu.org
  10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-12-15 19:33 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57067

--- Comment #10 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 108132 has been marked as a duplicate of this bug. ***

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

end of thread, other threads:[~2022-12-15 19:33 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-04-25  8:23 [Bug rtl-optimization/57067] New: Missing control flow edges for setjmp/longjmp krebbel at gcc dot gnu.org
2013-04-25  9:17 ` [Bug rtl-optimization/57067] " rguenth at gcc dot gnu.org
2013-04-25 14:46 ` krebbel at gcc dot gnu.org
2013-04-25 15:11 ` rguenther at suse dot de
2013-04-29 16:58 ` gretay at gcc dot gnu.org
2013-05-14 11:15 ` rguenth at gcc dot gnu.org
2013-05-17 14:03 ` gretay at gcc dot gnu.org
2014-12-10 12:37 ` rguenth at gcc dot gnu.org
2022-12-15 18:02 ` pinskia at gcc dot gnu.org
2022-12-15 18:04 ` pinskia at gcc dot gnu.org
2022-12-15 18:33 ` amonakov at gcc dot gnu.org
2022-12-15 19:33 ` pinskia at gcc dot gnu.org

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).