diff options
author | waffl3x <waffl3x@baylibre.com> | 2025-01-10 01:13:37 -0700 |
---|---|---|
committer | Sandra Loosemore <sloosemore@baylibre.com> | 2025-05-15 20:25:50 +0000 |
commit | 6e7487f5f6fa84f8ca6870f012a81d0d7a222c54 (patch) | |
tree | 7369891638da4a0626f7576b34d9f6c63e4c42ef /gcc/c/c-parser.cc | |
parent | 5f7678f015bb31a5aef0ea4f801a3fcff2e85050 (diff) | |
download | gcc-6e7487f5f6fa84f8ca6870f012a81d0d7a222c54.zip gcc-6e7487f5f6fa84f8ca6870f012a81d0d7a222c54.tar.gz gcc-6e7487f5f6fa84f8ca6870f012a81d0d7a222c54.tar.bz2 |
OpenMP: Add C++ support for 'omp allocate'
This patch handles local variables, global variables, as well as static
local variables where it is currently practical to do so. For now we sorry
on static local variables inside implicit constexpr functions, this includes
lambdas in c++17 and up, and inline functions with -fimplicit-constexpr in
c++14 and up. I have another patch that fixes most cases, unfortunately
there are a few cases that are not fixable without additional redesigns.
For function templates Instead of storing the directive directly in a
variables 'omp allocate' attribute and substituting into it, this patch
adds the OMP_ALLOCATE tree code that gets substituted. This makes it much
easier to prevent duplicate diagnostics with an invalid allocator/align
clause. This is added to a function template's stmt list and is only used
for substitution. It is not added to instantiations of a function template,
nor to regular functions.
Location information is included in the 'omp allocate' attribute to enhance
diagnostics of variables used in multiple allocate directives. While it is
possible that this could be added to the c front end, it would require some
reworking so it is not included in this patch. It was easy to support this
in the c++ front end because it is not practical to wait for a finalized
directive to add the 'omp allocate' attribute to vars, nor is it practical
to remove it in error cases. Consequentially some extra handling for this
needed to be added to gimplify.cc to avoid problems in error cases and
prevent conflicts with Fortran specific implementation details.
There is a left over band-aid fix in make_rtl_for_nonlocal_decl that only
worked for template cases, it probably has no effect at the moment.
The problem is make_rtl_for_nonlocal_decl never defers static locals in any
kind of constexpr function, including lambdas in c++17, regardless of
whether they can be used in a constant expression. I have a lengthy write
up of the history of why this is the case and the implications of it all,
but it is not directly relevant to this patch. In short, the original
reason static locals are not deferred was to fix PR70353 and was added in
r6-7642-ge0bffbbb5936be, however in r9-3788-gddd0d18c9c0702 the handling of
that case was changed and no longer goes through make_rtl_for_nonlocal_decl.
Unfortunately, we can't merely undo what was added, as c++23 static
constexpr local variables rely on it, as well as cases with c++17 lambdas
that should be disallowed, but aren't.
This should never be relevant, As OpenMP directives are not currently
allowed in constexpr functions, but as stated above the early processing of
static locals happens regardless of whether the function is actually usable
in a constant expression. In non templates, this early processing occurs
before we have even parsed the allocate directive, causing alignment
specified in an align clause to be skipped over entirely. In templates we
at least get to add the attribute to mark a var before this happens, so we
can use the presence of it to make sure they get deferred. This is the
band-aid that is currently present in make_rtl_for_nonlocal_decl, however
we currently reject these cases as it is fairly difficult to differentiate
whether we are in a regular function or not. We can't just rely on
processing_template_decl as it would just error upon instantiation. In
hindsight it would probably have worked fine in cp_parser_omp_allocate, but
this is supposed to be a temporary measure anyway as I have a follow up
patch.
gcc/c/ChangeLog:
* c-parser.cc (c_parser_omp_allocate): Fix typo in diagnostic.
gcc/ChangeLog:
* cgraphunit.cc (varpool_node::finalize_decl): Add assert.
* gimplify.cc (gimplify_bind_expr): Handle C++ specific
implementation details.
gcc/cp/ChangeLog:
* constexpr.cc (potential_constant_expression_1): Handle
OMP_ALLOCATE.
* cp-tree.def (OMP_ALLOCATE): New tree code.
* cp-tree.h (OMP_ALLOCATE_LOCATION): Define.
(OMP_ALLOCATE_VARS): Define.
(OMP_ALLOCATE_ALLOCATOR): Define.
(OMP_ALLOCATE_ALIGN): Define.
(finish_omp_allocate): New function declaration.
* decl.cc (make_rtl_for_nonlocal_decl): Work around ICE with
implicit constexpr functions.
* parser.cc (cp_parser_omp_allocate): Use OMP_CLAUSE_ERROR,
add diagnostics for args, call finish_omp_allocate.
(cp_parser_omp_construct): Don't handle PRAGMA_OMP_ALLOCATE.
(cp_parser_pragma): Comment.
* pt.cc (tsubst_stmt): Handle OMP_ALLOCATE, call
finish_omp_allocate.
* semantics.cc (finish_omp_allocate): New function.
* typeck.cc (can_do_nrvo_p): Don't do NRVO for omp allocate vars.
libgomp/ChangeLog:
* libgomp.texi: Document C++ support.
* testsuite/libgomp.c/allocate-4.c: Move to...
* testsuite/libgomp.c-c++-common/allocate-4.c: ...here.
* testsuite/libgomp.c/allocate-5.c: Move to...
* testsuite/libgomp.c-c++-common/allocate-5.c: ...here.
* testsuite/libgomp.c/allocate-6.c: Move to...
* testsuite/libgomp.c-c++-common/allocate-6.c: ...here.
* testsuite/libgomp.c++/allocate-2.C: New test.
gcc/testsuite/ChangeLog:
* c-c++-common/gomp/allocate-allocator-handle.h: New header.
* c-c++-common/gomp/allocate-5.c: Remove dg-messages for 'sorry',
add dg-error for c++.
* c-c++-common/gomp/allocate-9.c: Include header, remove dg-messages
for 'sorry', add dg-notes for c++, minor refactoring.
* c-c++-common/gomp/allocate-10.c: Enable for c++.
* c-c++-common/gomp/allocate-11.c: Enable for c++, disable warning.
* c-c++-common/gomp/allocate-12.c: Enable for c++, add cases.
* c-c++-common/gomp/allocate-14.c: Enable for c++.
* c-c++-common/gomp/allocate-15.c: Enable for c++.
* c-c++-common/gomp/allocate-16.c: Enable for c++.
* c-c++-common/gomp/allocate-17.c: Remove dg-message for 'sorry'.
* c-c++-common/gomp/allocate-18.c: Include header, remove dg-message
for 'sorry'.
* c-c++-common/gomp/allocate-19.c: Remove xfails for c++, remove
dg-messages for 'sorry'.
* c-c++-common/gomp/allocate-20.c: New test.
* c-c++-common/gomp/directive-1.c: Remove dg-message for 'sorry'.
* g++.dg/gomp/allocate-allocator-handle.h: New header.
* g++.dg/gomp/allocate-5.C: New test.
* g++.dg/gomp/allocate-6.C: New test.
* g++.dg/gomp/allocate-7.C: New test.
* g++.dg/gomp/allocate-8.C: New test.
* g++.dg/gomp/allocate-9.C: New test.
* g++.dg/gomp/allocate-10.C: New test.
* g++.dg/gomp/allocate-11.C: New test.
* g++.dg/gomp/allocate-12.C: New test.
* g++.dg/gomp/allocate-13.C: New test.
* g++.dg/gomp/allocate-14.C: New test.
* g++.dg/gomp/allocate-15.C: New test.
* g++.dg/gomp/allocate-16.C: New test.
* g++.dg/gomp/allocate-17.C: New test.
* g++.dg/gomp/allocate-18.C: New test.
* g++.dg/gomp/allocate-19.C: New test.
* g++.dg/gomp/allocate-20.C: New test.
* g++.dg/gomp/allocate-21.C: New test.
Signed-off-by: waffl3x <waffl3x@baylibre.com>
Co-authored-by: Tobias Burnus <tobias@codesourcery.com>
Diffstat (limited to 'gcc/c/c-parser.cc')
-rw-r--r-- | gcc/c/c-parser.cc | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc index 44b00ae..00ad861 100644 --- a/gcc/c/c-parser.cc +++ b/gcc/c/c-parser.cc @@ -23136,7 +23136,7 @@ c_parser_omp_allocate (c_parser *parser) != get_identifier ("omp_allocator_handle_t")) { error_at (expr_loc, - "%<allocator%> clause allocator expression has type " + "%<allocator%> clause expression has type " "%qT rather than %<omp_allocator_handle_t%>", TREE_TYPE (allocator)); allocator = NULL_TREE; |