public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-1752] tree-ssa-sink: do not sink to in front of setjmp
@ 2022-07-19 14:16 Alexander Monakov
  0 siblings, 0 replies; only message in thread
From: Alexander Monakov @ 2022-07-19 14:16 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:76c3f0dc2f815e0e450642efd5348c3ab852e4d0

commit r13-1752-g76c3f0dc2f815e0e450642efd5348c3ab852e4d0
Author: Alexander Monakov <amonakov@ispras.ru>
Date:   Fri Jan 14 20:23:41 2022 +0300

    tree-ssa-sink: do not sink to in front of setjmp
    
    gcc/ChangeLog:
    
            * tree-ssa-sink.cc (select_best_block): Punt if selected block
            has incoming abnormal edges.
    
    gcc/testsuite/ChangeLog:
    
            * gcc.dg/setjmp-7.c: New test.

Diff:
---
 gcc/testsuite/gcc.dg/setjmp-7.c | 13 +++++++++++++
 gcc/tree-ssa-sink.cc            |  6 ++++++
 2 files changed, 19 insertions(+)

diff --git a/gcc/testsuite/gcc.dg/setjmp-7.c b/gcc/testsuite/gcc.dg/setjmp-7.c
new file mode 100644
index 00000000000..44b5bcbfa9d
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/setjmp-7.c
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fno-guess-branch-probability -w" } */
+/* { dg-require-effective-target indirect_jumps } */
+
+struct __jmp_buf_tag { };
+typedef struct __jmp_buf_tag jmp_buf[1];
+struct globals { jmp_buf listingbuf; };
+extern struct globals *const ptr_to_globals;
+void foo()
+{
+    if ( _setjmp ( ((*ptr_to_globals).listingbuf )))
+	;
+}
diff --git a/gcc/tree-ssa-sink.cc b/gcc/tree-ssa-sink.cc
index 2e744d6ae50..9213052017a 100644
--- a/gcc/tree-ssa-sink.cc
+++ b/gcc/tree-ssa-sink.cc
@@ -208,6 +208,12 @@ select_best_block (basic_block early_bb,
       temp_bb = get_immediate_dominator (CDI_DOMINATORS, temp_bb);
     }
 
+  /* Placing a statement before a setjmp-like function would be invalid
+     (it cannot be reevaluated when execution follows an abnormal edge).
+     If we selected a block with abnormal predecessors, just punt.  */
+  if (bb_has_abnormal_pred (best_bb))
+    return early_bb;
+
   /* If we found a shallower loop nest, then we always consider that
      a win.  This will always give us the most control dependent block
      within that loop nest.  */


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-07-19 14:16 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-19 14:16 [gcc r13-1752] tree-ssa-sink: do not sink to in front of setjmp Alexander Monakov

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