aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorTobias Burnus <tburnus@baylibre.com>2024-12-03 11:02:03 +0100
committerTobias Burnus <tburnus@baylibre.com>2024-12-03 11:02:03 +0100
commit3d72e50caebf232fdd7f70613616ca4fd4fb472b (patch)
treeb60d11e53dc95961e103d8fd33daf22233a12203 /gcc
parent83f22c1c526368cafc3d32f03462ecd7847f054f (diff)
downloadgcc-3d72e50caebf232fdd7f70613616ca4fd4fb472b.zip
gcc-3d72e50caebf232fdd7f70613616ca4fd4fb472b.tar.gz
gcc-3d72e50caebf232fdd7f70613616ca4fd4fb472b.tar.bz2
OpenMP: 'allocate' directive - fixes for 'alignof' and [[omp::decl]]
Fixed a check to permit [[omp::decl(allocate,...)]] parsing in C. Additionaly, we discussed that 'allocate align' should not affect 'alignof' to avoid issues like with: int a; _Alignas(_Alignof(a)) int b; #pragma omp allocate(a) align(128) _Alignas(_Alignof(a)) int c; Thus, the alignment is no longer set in the C and Fortran front ends, but for static variables now in varpool_node::finalize_decl. (For stack variables, the alignment is handled in gimplify_bind_expr.) NOTE: 'omp allocate' is not yet supported in C++. gcc/c/ChangeLog: * c-parser.cc (c_parser_omp_allocate): Only check scope if not in_omp_decl_attribute. Remove setting the alignment. gcc/ChangeLog: * cgraphunit.cc (varpool_node::finalize_decl): Set alignment based on OpenMP's 'omp allocate' attribute/directive. gcc/fortran/ChangeLog: * trans-decl.cc (gfc_finish_var_decl): Remove setting the alignment. libgomp/ChangeLog: * libgomp.texi (Memory allocation): Mention (non-)effect of 'align' on _Alignof. * testsuite/libgomp.c/allocate-7.c: New test. gcc/testsuite/ChangeLog: * c-c++-common/gomp/allocate-18.c: Check that alignof is unaffected by 'omp allocate'. * c-c++-common/gomp/allocate-19.c: Likewise.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/c/c-parser.cc5
-rw-r--r--gcc/cgraphunit.cc12
-rw-r--r--gcc/fortran/trans-decl.cc3
-rw-r--r--gcc/testsuite/c-c++-common/gomp/allocate-18.c6
-rw-r--r--gcc/testsuite/c-c++-common/gomp/allocate-19.c10
5 files changed, 21 insertions, 15 deletions
diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc
index 0acba05..a7719ac 100644
--- a/gcc/c/c-parser.cc
+++ b/gcc/c/c-parser.cc
@@ -22158,7 +22158,7 @@ c_parser_omp_allocate (c_parser *parser)
"%<allocate%> directive", var);
continue;
}
- if (!c_check_in_current_scope (var))
+ if (!parser->in_omp_decl_attribute && !c_check_in_current_scope (var))
{
error_at (OMP_CLAUSE_LOCATION (nl),
"%<allocate%> directive must be in the same scope as %qD",
@@ -22199,9 +22199,6 @@ c_parser_omp_allocate (c_parser *parser)
= {EXPR_LOC_OR_LOC (allocator, OMP_CLAUSE_LOCATION (nl)), var};
walk_tree (&allocator, c_check_omp_allocate_allocator_r, &data, NULL);
}
- if (alignment)
- SET_DECL_ALIGN (var, BITS_PER_UNIT * MAX (tree_to_uhwi (alignment),
- DECL_ALIGN_UNIT (var)));
DECL_ATTRIBUTES (var) = tree_cons (get_identifier ("omp allocate"),
build_tree_list (allocator, alignment),
DECL_ATTRIBUTES (var));
diff --git a/gcc/cgraphunit.cc b/gcc/cgraphunit.cc
index d60ebc1..e954e88 100644
--- a/gcc/cgraphunit.cc
+++ b/gcc/cgraphunit.cc
@@ -983,6 +983,18 @@ varpool_node::finalize_decl (tree decl)
&& !DECL_ARTIFICIAL (node->decl)))
node->force_output = true;
+ if (flag_openmp)
+ {
+ tree attr = lookup_attribute ("omp allocate", DECL_ATTRIBUTES (decl));
+ if (attr)
+ {
+ tree align = TREE_VALUE (TREE_VALUE (attr));
+ if (align)
+ SET_DECL_ALIGN (decl, MAX (tree_to_uhwi (align) * BITS_PER_UNIT,
+ DECL_ALIGN (decl)));
+ }
+ }
+
if (symtab->state == CONSTRUCTION
&& (node->needed_p () || node->referred_to_p ()))
enqueue_node (node);
diff --git a/gcc/fortran/trans-decl.cc b/gcc/fortran/trans-decl.cc
index a62fe3f..d69c843 100644
--- a/gcc/fortran/trans-decl.cc
+++ b/gcc/fortran/trans-decl.cc
@@ -830,9 +830,6 @@ gfc_finish_var_decl (tree decl, gfc_symbol * sym)
tree alloc = gfc_conv_constant_to_tree (n->u2.allocator);
tree align = (n->u.align ? gfc_conv_constant_to_tree (n->u.align)
: NULL_TREE);
- if (align != NULL_TREE)
- SET_DECL_ALIGN (decl, MAX (tree_to_uhwi (align),
- DECL_ALIGN_UNIT (decl)) * BITS_PER_UNIT);
DECL_ATTRIBUTES (decl)
= tree_cons (get_identifier ("omp allocate"),
build_tree_list (alloc, align), DECL_ATTRIBUTES (decl));
diff --git a/gcc/testsuite/c-c++-common/gomp/allocate-18.c b/gcc/testsuite/c-c++-common/gomp/allocate-18.c
index 4182f7e..93c5aca 100644
--- a/gcc/testsuite/c-c++-common/gomp/allocate-18.c
+++ b/gcc/testsuite/c-c++-common/gomp/allocate-18.c
@@ -17,14 +17,14 @@ typedef enum omp_allocator_handle_t
void test0 ()
{
- int A1[5];
+ int A1[5], B1[5];
#pragma omp allocate(A1) align(128) allocator(omp_default_mem_alloc)
/* { dg-message "sorry, unimplemented: '#pragma omp allocate' not yet supported" "" { target c++ } .-1 } */
#ifndef __cplusplus
- _Static_assert (_Alignof(A1) == 128, "wrong alignment");
+ _Static_assert (_Alignof(A1) == _Alignof(B1), "wrong alignment");
#elif __cplusplus >= 201103L
- static_assert (alignof(A1) == 128, "wrong alignment"); /* { dg-bogus "static assertion failed: wrong alignment" "" { xfail { c++ && { ! c++98_only } } } } */
+ static_assert (alignof(A1) == alignof(B1), "wrong alignment");
#endif
}
diff --git a/gcc/testsuite/c-c++-common/gomp/allocate-19.c b/gcc/testsuite/c-c++-common/gomp/allocate-19.c
index ad3493d..5c5fc00 100644
--- a/gcc/testsuite/c-c++-common/gomp/allocate-19.c
+++ b/gcc/testsuite/c-c++-common/gomp/allocate-19.c
@@ -19,14 +19,14 @@ typedef enum omp_allocator_handle_t
__omp_allocator_handle_t_max__ = __UINTPTR_MAX__
} omp_allocator_handle_t;
-static int A1[5] = {1,2,3,4,5};
+static int A1[5] = {1,2,3,4,5}, B1[5];
#pragma omp allocate(A1) align(128) allocator(omp_default_mem_alloc)
/* { dg-message "sorry, unimplemented: '#pragma omp allocate' not yet supported" "" { target c++ } .-1 } */
#ifndef __cplusplus
-_Static_assert (_Alignof(A1) == 128, "wrong alignment");
+_Static_assert (_Alignof(A1) == _Alignof(B1), "wrong alignment");
#elif __cplusplus >= 201103L
-static_assert (alignof(A1) == 128, "wrong alignment"); /* { dg-bogus "static assertion failed: wrong alignment" "" { xfail { c++ && { ! c++98_only } } } } */
+static_assert (alignof(A1) == alignof(B1), "wrong alignment");
#endif
@@ -49,9 +49,9 @@ get ()
/* { dg-message "sorry, unimplemented: '#pragma omp allocate' not yet supported" "" { target c++ } .-1 } */
#ifndef __cplusplus
- _Static_assert (_Alignof(q) == 1024, "wrong alignment");
+ _Static_assert (_Alignof(q) == _Alignof(int), "wrong alignment");
#elif __cplusplus >= 201103L
- static_assert (alignof(q) == 1024, "wrong alignment"); /* { dg-bogus "static assertion failed: wrong alignment" "" { xfail { c++ && { ! c++98_only } } } } */
+ static_assert (alignof(q) == alignof(int), "wrong alignment");
#endif
q += 1;