]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
OpenMP: Avoid ICE with LTO and 'omp allocate'
authorTobias Burnus <tobias@codesourcery.com>
Fri, 27 Oct 2023 10:41:31 +0000 (12:41 +0200)
committerTobias Burnus <tobias@codesourcery.com>
Fri, 27 Oct 2023 10:41:31 +0000 (12:41 +0200)
gcc/ChangeLog:

* gimplify.cc (gimplify_bind_expr): Remove "omp allocate" attribute
to avoid that auxillary statement list reaches LTO.

gcc/testsuite/ChangeLog:

* gfortran.dg/gomp/allocate-13a.f90: New test.

(cherry picked from commit af4bb221153359f5948da917d5ef2df738bb1e61)

gcc/ChangeLog.omp
gcc/gimplify.cc
gcc/testsuite/ChangeLog.omp
gcc/testsuite/gfortran.dg/gomp/allocate-13a.f90 [new file with mode: 0644]

index cdaabb97356cd15e5dba23c06a4410bd8a8d241e..570f0b009fea8fb93760b2210bab8e92b0e801d1 100644 (file)
@@ -1,3 +1,11 @@
+2023-10-27  Tobias Burnus  <tobias@codesourcery.com>
+
+       Backported from master:
+       2023-10-18  Tobias Burnus  <tobias@codesourcery.com>
+
+       * gimplify.cc (gimplify_bind_expr): Remove "omp allocate" attribute
+       to avoid that auxillary statement list reaches LTO.
+
 2023-10-26  Tobias Burnus  <tobias@codesourcery.com>
 
        Backported from master:
index f2fbd8554ac9b01f8bd7a46a5739770267c8224e..2b6e592213fd5ec4be9227348e446c800decac6b 100644 (file)
@@ -1484,7 +1484,8 @@ gimplify_bind_expr (tree *expr_p, gimple_seq *pre_p)
                      DECL_ATTRIBUTES (v)
                        = tree_cons (get_identifier ("omp allocate var"),
                                     build_tree_list (NULL_TREE, t),
-                                    DECL_ATTRIBUTES (t));
+                                    remove_attribute ("omp allocate",
+                                                      DECL_ATTRIBUTES (t)));
                      tmp = build_fold_indirect_ref (v);
                      TREE_THIS_NOTRAP (tmp) = 1;
                      SET_DECL_VALUE_EXPR (t, tmp);
@@ -1531,7 +1532,12 @@ gimplify_bind_expr (tree *expr_p, gimple_seq *pre_p)
                         at the top, unless an allocator or size expression
                         requires to put it afterward; note that the size is
                         always later in generated code; for strings, no
-                        size expr but still an expr might be available.  */
+                        size expr but still an expr might be available.
+                        As LTO does not handle a statement list, 'sl' has
+                        to be removed; done so by removing the attribute.  */
+                     DECL_ATTRIBUTES (t)
+                       = remove_attribute ("omp allocate",
+                                           DECL_ATTRIBUTES (t));
                      tree sl = TREE_PURPOSE (TREE_CHAIN (TREE_VALUE (attr)));
                      tree_stmt_iterator e = tsi_start (sl);
                      tree needle = NULL_TREE;
@@ -1689,16 +1695,14 @@ gimplify_bind_expr (tree *expr_p, gimple_seq *pre_p)
          && !is_global_var (t)
          && DECL_CONTEXT (t) == current_function_decl)
        {
-         tree attr;
          if (flag_openmp
              && DECL_HAS_VALUE_EXPR_P (t)
              && TREE_USED (t)
-             && ((attr = lookup_attribute ("omp allocate",
-                                           DECL_ATTRIBUTES (t))) != NULL_TREE)
-             && TREE_CHAIN (TREE_VALUE (attr)) == NULL_TREE)
+             && lookup_attribute ("omp allocate", DECL_ATTRIBUTES (t)))
            {
              /* For Fortran, TREE_CHAIN (TREE_VALUE (attr)) is set, which
-                causes that the GOMP_free call is already added above.  */
+                causes that the GOMP_free call is already added above;
+                and "omp allocate" is removed from DECL_ATTRIBUTES.  */
              tree v = TREE_OPERAND (DECL_VALUE_EXPR (t), 0);
              tree tmp = builtin_decl_explicit (BUILT_IN_GOMP_FREE);
              tmp = build_call_expr_loc (end_locus, tmp, 2, v,
index 27445c6df898d56aecf1875b84adb05ebb1b36c4..0bb6af44262521384610c31cf5a853cd69818d95 100644 (file)
@@ -1,3 +1,10 @@
+2023-10-27  Tobias Burnus  <tobias@codesourcery.com>
+
+       Backported from master:
+       2023-10-18  Tobias Burnus  <tobias@codesourcery.com>
+
+       * gfortran.dg/gomp/allocate-13a.f90: New test.
+
 2023-10-26  Tobias Burnus  <tobias@codesourcery.com>
 
        * gfortran.dg/gomp/allocate-4a.f90: Update dg-error.
diff --git a/gcc/testsuite/gfortran.dg/gomp/allocate-13a.f90 b/gcc/testsuite/gfortran.dg/gomp/allocate-13a.f90
new file mode 100644 (file)
index 0000000..4b297cd
--- /dev/null
@@ -0,0 +1,34 @@
+! { dg-do compile { target lto } }
+! { dg-additional-options "-flto" }
+
+! Same as allocate-13.f90 but compiled with -flto.
+
+! This was failing before as the statement list,
+! used for placing the GOMP_alloc/GOMP_free leaked
+! through to LTO.
+
+module m
+  implicit none
+  !$omp requires dynamic_allocators
+contains
+subroutine f ()
+  !$omp declare target
+  integer :: var
+  !$omp allocate(var)
+  var = 5
+end
+
+subroutine h ()
+  !$omp target
+   !$omp parallel
+    !$omp single
+      block
+       integer :: var2(5)
+       !$omp allocate(var2)
+       var2(1) = 7
+      end block
+    !$omp end single
+   !$omp end parallel
+  !$omp end target
+end
+end module