]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fortran: Extend align-clause checks of OpenMP's allocate directive
authorTobias Burnus <tobias@codesourcery.com>
Wed, 1 Feb 2023 14:27:42 +0000 (15:27 +0100)
committerTobias Burnus <tobias@codesourcery.com>
Wed, 1 Feb 2023 14:27:42 +0000 (15:27 +0100)
gcc/fortran/ChangeLog:

* openmp.cc (resolve_omp_clauses): Check also for
power of two.

libgomp/ChangeLog:

* testsuite/libgomp.fortran/allocate-3.f90: Fix ALIGN
usage, remove unused -fdump-tree-original.
* testsuite/libgomp.fortran/allocate-4.f90: New.

(cherry picked from commit bf2cf6f3f1851054237ee7df99bdf60bf5a3e3ae)

gcc/fortran/ChangeLog.omp
gcc/fortran/openmp.cc
libgomp/ChangeLog.omp
libgomp/testsuite/libgomp.fortran/allocate-3.f90
libgomp/testsuite/libgomp.fortran/allocate-4.f90 [new file with mode: 0644]

index 4450c067d87fca703627ed6a486038038a81ec9d..a7e44234d2fe138c6f76c19e7a705fa2c974ba84 100644 (file)
@@ -1,3 +1,11 @@
+2023-02-01  Tobias Burnus  <tobias@codesourcery.com>
+
+       Backported from master:
+       2023-01-23  Tobias Burnus  <tobias@codesourcery.com>
+
+       * openmp.cc (resolve_omp_clauses): Check also for
+       power of two.
+
 2023-01-16  Tobias Burnus  <tobias@codesourcery.com>
 
        Backported from master:
index 7679dbef0882170e86188e99aaef00a7591dc51f..7cc54bb05df3403d1443afd08f79dde281a3b768 100644 (file)
@@ -8183,11 +8183,12 @@ resolve_omp_clauses (gfc_code *code, gfc_omp_clauses *omp_clauses,
              || n->u.align->ts.type != BT_INTEGER
              || n->u.align->rank != 0
              || gfc_extract_int (n->u.align, &alignment)
-             || alignment <= 0)
+             || alignment <= 0
+             || !pow2p_hwi (alignment))
            {
-             gfc_error ("ALIGN modifier requires a scalar positive "
-                        "constant integer alignment expression at %L",
-                        &n->u.align->where);
+             gfc_error ("ALIGN modifier requires at %L a scalar positive "
+                        "constant integer alignment expression that is a "
+                        "power of two", &n->u.align->where);
              break;
            }
        }
index d91aaed3558cfa12a3aebe12a1d732ed9740d639..3d1cb16348a8301244ca4cd13cd68e1f72070e22 100644 (file)
@@ -1,3 +1,12 @@
+2023-02-01  Tobias Burnus  <tobias@codesourcery.com>
+
+       Backported from master:
+       2023-02-01  Tobias Burnus  <tobias@codesourcery.com>
+
+       * testsuite/libgomp.fortran/allocate-3.f90: Fix ALIGN
+       usage, remove unused -fdump-tree-original.
+       * testsuite/libgomp.fortran/allocate-4.f90: New.
+
 2023-01-26  Tobias Burnus  <tobias@codesourcery.com>
 
        Backported from master:
index a39819164d6ac286791e9c3a945d304868d71bff..1fa0bb932c3eaf9fecb76afeeaa3609b983c1ee5 100644 (file)
@@ -1,5 +1,4 @@
 ! { dg-do compile }
-! { dg-additional-options "-fdump-tree-original" }
 
 use omp_lib
 implicit none
@@ -23,6 +22,7 @@ integer :: q, x,y,z
 ! { dg-error "Object 'omp_high_bw_mem_alloc' is not a variable" "" { target *-*-* } .-1 }
 !$omp end parallel
 
-!$omp parallel allocate( align(q) : x) firstprivate(x) ! { dg-error "31:ALIGN modifier requires a scalar positive constant integer alignment expression at" }
+!$omp parallel allocate( align(128) : x) firstprivate(x) ! OK
 !$omp end parallel
+
 end
diff --git a/libgomp/testsuite/libgomp.fortran/allocate-4.f90 b/libgomp/testsuite/libgomp.fortran/allocate-4.f90
new file mode 100644 (file)
index 0000000..ddb507b
--- /dev/null
@@ -0,0 +1,42 @@
+! { dg-do compile }
+
+
+subroutine test()
+use iso_c_binding, only: c_intptr_t
+implicit none
+integer, parameter :: omp_allocator_handle_kind = 1 !! <<<
+integer (kind=omp_allocator_handle_kind), &
+                 parameter :: omp_high_bw_mem_alloc = 4
+integer :: q, x,y,z
+integer, parameter :: cnst(2) = [64, 101]
+
+!$omp parallel allocate( omp_high_bw_mem_alloc : x)  firstprivate(x) ! { dg-error "Expected integer expression of the 'omp_allocator_handle_kind' kind" }
+!$omp end parallel
+
+!$omp parallel allocate( allocator (omp_high_bw_mem_alloc) : x)  firstprivate(x) ! { dg-error "Expected integer expression of the 'omp_allocator_handle_kind' kind" }
+!$omp end parallel
+
+!$omp parallel allocate( align (q) : x)  firstprivate(x) ! { dg-error "32:ALIGN modifier requires at \\(1\\) a scalar positive constant integer alignment expression that is a power of two" }
+!$omp end parallel
+
+!$omp parallel allocate( align (32) : x)  firstprivate(x) ! OK
+!$omp end parallel
+
+!$omp parallel allocate( align(q) : x) firstprivate(x) ! { dg-error "31:ALIGN modifier requires at \\(1\\) a scalar positive constant integer alignment expression that is a power of two" }
+!$omp end parallel
+
+!$omp parallel allocate( align(cnst(1)) : x ) firstprivate(x) ! OK
+!$omp end parallel
+
+!$omp parallel allocate( align(cnst(2)) : x) firstprivate(x)  ! { dg-error "31:ALIGN modifier requires at \\(1\\) a scalar positive constant integer alignment expression that is a power of two" }
+!$omp end parallel
+
+!$omp parallel allocate( align( 31) :x) firstprivate(x)  ! { dg-error "32:ALIGN modifier requires at \\(1\\) a scalar positive constant integer alignment expression that is a power of two" }
+!$omp end parallel
+
+!$omp parallel allocate( align (32.0): x) firstprivate(x)  ! { dg-error "32:ALIGN modifier requires at \\(1\\) a scalar positive constant integer alignment expression that is a power of two" }
+!$omp end parallel
+
+!$omp parallel allocate( align(cnst ) : x ) firstprivate(x)  ! { dg-error "31:ALIGN modifier requires at \\(1\\) a scalar positive constant integer alignment expression that is a power of two" }
+!$omp end parallel
+end