diff options
author | Tobias Burnus <tobias@codesourcery.com> | 2023-09-12 09:19:04 +0200 |
---|---|---|
committer | Tobias Burnus <tobias@codesourcery.com> | 2023-09-12 09:19:04 +0200 |
commit | 35f498d8dfc8e579eaba2ff2d2b96769c632fd58 (patch) | |
tree | f3e2f5b948ee20d3990a57e8a137212e5df60530 /gcc/gimplify.cc | |
parent | b90a4c3dd502974f352084c23a6cdfd767e1340b (diff) | |
download | gcc-35f498d8dfc8e579eaba2ff2d2b96769c632fd58.zip gcc-35f498d8dfc8e579eaba2ff2d2b96769c632fd58.tar.gz gcc-35f498d8dfc8e579eaba2ff2d2b96769c632fd58.tar.bz2 |
OpenMP (C only): omp allocate - extend parsing support, improve diagnostic
The 'allocate' directive can be used for both stack and static variables.
While the parser in C and C++ was pre-existing, it missed several
diagnostics, which this commit adds - for now only for C.
While the "sorry, unimplemented" for static variables is still issues
during parsing, the sorry for stack variables is now issued in the
middle end, preparing for the actual implementation. (Again: only for C.)
gcc/c/ChangeLog:
* c-parser.cc (c_parser_omp_construct): Move call to
c_parser_omp_allocate to ...
(c_parser_pragma): ... here.
(c_parser_omp_allocate): Avoid ICE is allocator could not be
parsed; set 'omp allocate' attribute for stack/automatic variables
and only reject static variables; add several additional
restriction checks.
* c-tree.h (c_mark_decl_jump_unsafe_in_current_scope): New prototype.
* c-decl.cc (decl_jump_unsafe): Return true for omp-allocated decls.
(c_mark_decl_jump_unsafe_in_current_scope): New.
(warn_about_goto, c_check_switch_jump_warnings): Add error for
omp-allocated decls.
gcc/ChangeLog:
* gimplify.cc (gimplify_bind_expr): Check for
insertion after variable cleanup. Convert 'omp allocate'
var-decl attribute to GOMP_alloc/GOMP_free calls.
gcc/testsuite/ChangeLog:
* c-c++-common/gomp/allocate-5.c: Fix testcase; make some
dg-messages for 'sorry' as c++, only.
* c-c++-common/gomp/directive-1.c: Make a 'sorry' c++ only.
* c-c++-common/gomp/allocate-9.c: New test.
* c-c++-common/gomp/allocate-11.c: New test.
* c-c++-common/gomp/allocate-12.c: New test.
* c-c++-common/gomp/allocate-14.c: New test.
* c-c++-common/gomp/allocate-15.c: New test.
* c-c++-common/gomp/allocate-16.c: New test.
Diffstat (limited to 'gcc/gimplify.cc')
-rw-r--r-- | gcc/gimplify.cc | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/gcc/gimplify.cc b/gcc/gimplify.cc index a49b50b..a0e8cc2 100644 --- a/gcc/gimplify.cc +++ b/gcc/gimplify.cc @@ -1363,6 +1363,46 @@ gimplify_bind_expr (tree *expr_p, gimple_seq *pre_p) if (VAR_P (t)) { struct gimplify_omp_ctx *ctx = gimplify_omp_ctxp; + tree attr; + + if (flag_openmp + && !is_global_var (t) + && DECL_CONTEXT (t) == current_function_decl + && TREE_USED (t) + && (attr = lookup_attribute ("omp allocate", DECL_ATTRIBUTES (t))) + != NULL_TREE) + { + tree alloc = TREE_PURPOSE (TREE_VALUE (attr)); + tree align = TREE_VALUE (TREE_VALUE (attr)); + /* Allocate directives that appear in a target region must specify + an allocator clause unless a requires directive with the + dynamic_allocators clause is present in the same compilation + unit. */ + bool missing_dyn_alloc = false; + if (alloc == NULL_TREE + && ((omp_requires_mask & OMP_REQUIRES_DYNAMIC_ALLOCATORS) + == 0)) + { + /* This comes too early for omp_discover_declare_target..., + but should at least catch the most common cases. */ + missing_dyn_alloc + = cgraph_node::get (current_function_decl)->offloadable; + for (struct gimplify_omp_ctx *ctx2 = ctx; + ctx2 && !missing_dyn_alloc; ctx2 = ctx2->outer_context) + if (ctx2->code == OMP_TARGET) + missing_dyn_alloc = true; + } + if (missing_dyn_alloc) + error_at (DECL_SOURCE_LOCATION (t), + "%<allocate%> directive for %qD inside a target " + "region must specify an %<allocator%> clause", t); + else if (align != NULL_TREE + || alloc == NULL_TREE + || !integer_onep (alloc)) + sorry_at (DECL_SOURCE_LOCATION (t), + "OpenMP %<allocate%> directive, used for %qD, not " + "yet supported", t); + } /* Mark variable as local. */ if (ctx && ctx->region_type != ORT_NONE && !DECL_EXTERNAL (t)) |