]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR c/81687 (Compiler drops label in OpenMP region)
authorJakub Jelinek <jakub@redhat.com>
Sat, 16 Sep 2017 18:38:53 +0000 (20:38 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Sat, 16 Sep 2017 18:38:53 +0000 (20:38 +0200)
Backported from mainline
2017-08-09  Jakub Jelinek  <jakub@redhat.com>

PR c/81687
* omp-low.c (omp_copy_decl): Don't remap FORCED_LABEL or DECL_NONLOCAL
LABEL_DECLs.
* tree-cfg.c (move_stmt_op): Don't adjust DECL_CONTEXT of FORCED_LABEL
or DECL_NONLOCAL labels.
(move_stmt_r) <case GIMPLE_LABEL>: Adjust DECL_CONTEXT of FORCED_LABEL
or DECL_NONLOCAL labels here.

* testsuite/libgomp.c/pr81687-1.c: New test.
* testsuite/libgomp.c/pr81687-2.c: New test.

From-SVN: r252885

gcc/ChangeLog
gcc/omp-low.c
gcc/tree-cfg.c
libgomp/ChangeLog
libgomp/testsuite/libgomp.c/pr81687-1.c [new file with mode: 0644]
libgomp/testsuite/libgomp.c/pr81687-2.c [new file with mode: 0644]

index 3ecc00f6e5cd01478528462337d174f154a518a8..60a389b781a6a6d661e5bac3c0fab44874b791ae 100644 (file)
@@ -1,6 +1,16 @@
 2017-09-16  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       2017-08-09  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c/81687
+       * omp-low.c (omp_copy_decl): Don't remap FORCED_LABEL or DECL_NONLOCAL
+       LABEL_DECLs.
+       * tree-cfg.c (move_stmt_op): Don't adjust DECL_CONTEXT of FORCED_LABEL
+       or DECL_NONLOCAL labels.
+       (move_stmt_r) <case GIMPLE_LABEL>: Adjust DECL_CONTEXT of FORCED_LABEL
+       or DECL_NONLOCAL labels here.
+
        2017-08-08  Richard Biener  <rguenther@suse.de>
 
        PR middle-end/81766
index c1147c63d1195b68441126e6f5b0932e967ae450..220e9eb73f900cb85305637bedcf56e9337ece48 100644 (file)
@@ -1370,6 +1370,8 @@ omp_copy_decl (tree var, copy_body_data *cb)
 
   if (TREE_CODE (var) == LABEL_DECL)
     {
+      if (FORCED_LABEL (var) || DECL_NONLOCAL (var))
+       return var;
       new_var = create_artificial_label (DECL_SOURCE_LOCATION (var));
       DECL_CONTEXT (new_var) = current_function_decl;
       insert_decl_map (&ctx->cb, var, new_var);
index 2a76c41ebf91d2ea1851c6309f600a6105c39e0e..ab0c91c4ee6590f9561ed42ca9ac6d457776826b 100644 (file)
@@ -6467,7 +6467,15 @@ move_stmt_op (tree *tp, int *walk_subtrees, void *data)
                *tp = t = out->to;
            }
 
-         DECL_CONTEXT (t) = p->to_context;
+         /* For FORCED_LABELs we can end up with references from other
+            functions if some SESE regions are outlined.  It is UB to
+            jump in between them, but they could be used just for printing
+            addresses etc.  In that case, DECL_CONTEXT on the label should
+            be the function containing the glabel stmt with that LABEL_DECL,
+            rather than whatever function a reference to the label was seen
+            last time.  */
+         if (!FORCED_LABEL (t) && !DECL_NONLOCAL (t))
+           DECL_CONTEXT (t) = p->to_context;
        }
       else if (p->remap_decls_p)
        {
@@ -6586,6 +6594,21 @@ move_stmt_r (gimple_stmt_iterator *gsi_p, bool *handled_ops_p,
     case GIMPLE_OMP_RETURN:
     case GIMPLE_OMP_CONTINUE:
       break;
+
+    case GIMPLE_LABEL:
+      {
+       /* For FORCED_LABEL, move_stmt_op doesn't adjust DECL_CONTEXT,
+          so that such labels can be referenced from other regions.
+          Make sure to update it when seeing a GIMPLE_LABEL though,
+          that is the owner of the label.  */
+       walk_gimple_op (stmt, move_stmt_op, wi);
+       *handled_ops_p = true;
+       tree label = gimple_label_label (as_a <glabel *> (stmt));
+       if (FORCED_LABEL (label) || DECL_NONLOCAL (label))
+         DECL_CONTEXT (label) = p->to_context;
+      }
+      break;
+
     default:
       if (is_gimple_omp (stmt))
        {
index 8304dda7fbbad85f88e6b0d02c45f8c053e32dc5..9c045ba079f0feb626f8735fa41346a056a06a7a 100644 (file)
@@ -1,6 +1,12 @@
 2017-09-16  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       2017-08-09  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c/81687
+       * testsuite/libgomp.c/pr81687-1.c: New test.
+       * testsuite/libgomp.c/pr81687-2.c: New test.
+
        2017-07-27  Jakub Jelinek  <jakub@redhat.com>
 
        PR c/45784
diff --git a/libgomp/testsuite/libgomp.c/pr81687-1.c b/libgomp/testsuite/libgomp.c/pr81687-1.c
new file mode 100644 (file)
index 0000000..768ec44
--- /dev/null
@@ -0,0 +1,23 @@
+/* PR c/81687 */
+/* { dg-do link } */
+/* { dg-additional-options "-O2" } */
+
+extern int printf (const char *, ...);
+
+int
+main ()
+{
+  #pragma omp parallel
+  {
+   lab1:
+    printf ("lab1=%p\n", (void *)(&&lab1));
+  }
+ lab2:
+  #pragma omp parallel
+  {
+   lab3:
+    printf ("lab2=%p\n", (void *)(&&lab2));
+  }
+  printf ("lab3=%p\n", (void *)(&&lab3));
+  return 0;
+}
diff --git a/libgomp/testsuite/libgomp.c/pr81687-2.c b/libgomp/testsuite/libgomp.c/pr81687-2.c
new file mode 100644 (file)
index 0000000..e819f76
--- /dev/null
@@ -0,0 +1,27 @@
+/* PR c/81687 */
+/* { dg-do link } */
+/* { dg-additional-options "-O2" } */
+
+int
+main ()
+{
+  __label__ lab4, lab5, lab6;
+  volatile int l = 0;
+  int m = l;
+  void foo (int x) { if (x == 1) goto lab4; }
+  void bar (int x) { if (x == 2) goto lab5; }
+  void baz (int x) { if (x == 3) goto lab6; }
+  #pragma omp parallel
+  {
+    foo (m + 1);
+   lab4:;
+  }
+  #pragma omp task
+  {
+    bar (m + 2);
+   lab5:;
+  }
+  baz (m + 3);
+ lab6:;
+  return 0;
+}