aboutsummaryrefslogtreecommitdiff
path: root/gcc/c/c-decl.cc
diff options
context:
space:
mode:
authorTobias Burnus <tobias@codesourcery.com>2023-09-12 09:19:04 +0200
committerTobias Burnus <tobias@codesourcery.com>2023-09-12 09:19:04 +0200
commit35f498d8dfc8e579eaba2ff2d2b96769c632fd58 (patch)
treef3e2f5b948ee20d3990a57e8a137212e5df60530 /gcc/c/c-decl.cc
parentb90a4c3dd502974f352084c23a6cdfd767e1340b (diff)
downloadgcc-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/c/c-decl.cc')
-rw-r--r--gcc/c/c-decl.cc26
1 files changed, 26 insertions, 0 deletions
diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc
index 649c5ae6..5822faf 100644
--- a/gcc/c/c-decl.cc
+++ b/gcc/c/c-decl.cc
@@ -681,6 +681,11 @@ decl_jump_unsafe (tree decl)
if (VAR_P (decl) && C_DECL_COMPOUND_LITERAL_P (decl))
return false;
+ if (flag_openmp
+ && VAR_P (decl)
+ && lookup_attribute ("omp allocate", DECL_ATTRIBUTES (decl)))
+ return true;
+
/* Always warn about crossing variably modified types. */
if ((VAR_P (decl) || TREE_CODE (decl) == TYPE_DECL)
&& c_type_variably_modified_p (TREE_TYPE (decl)))
@@ -724,6 +729,15 @@ c_print_identifier (FILE *file, tree node, int indent)
c_binding_oracle = save;
}
+/* Establish that the scope contains declarations that are sensitive to
+ jumps that cross a binding. Together with decl_jump_unsafe, this is
+ used to diagnose such jumps. */
+void
+c_mark_decl_jump_unsafe_in_current_scope ()
+{
+ current_scope->has_jump_unsafe_decl = 1;
+}
+
/* Establish a binding between NAME, an IDENTIFIER_NODE, and DECL,
which may be any of several kinds of DECL or TYPE or error_mark_node,
in the scope SCOPE. */
@@ -3974,6 +3988,9 @@ warn_about_goto (location_t goto_loc, tree label, tree decl)
if (c_type_variably_modified_p (TREE_TYPE (decl)))
error_at (goto_loc,
"jump into scope of identifier with variably modified type");
+ else if (flag_openmp
+ && lookup_attribute ("omp allocate", DECL_ATTRIBUTES (decl)))
+ error_at (goto_loc, "jump skips OpenMP %<allocate%> allocation");
else
if (!warning_at (goto_loc, OPT_Wjump_misses_init,
"jump skips variable initialization"))
@@ -4253,6 +4270,15 @@ c_check_switch_jump_warnings (struct c_spot_bindings *switch_bindings,
"variably modified type"));
emitted = true;
}
+ else if (flag_openmp
+ && lookup_attribute ("omp allocate",
+ DECL_ATTRIBUTES (b->decl)))
+ {
+ saw_error = true;
+ error_at (case_loc,
+ "switch jumps over OpenMP %<allocate%> allocation");
+ emitted = true;
+ }
else
emitted
= warning_at (case_loc, OPT_Wjump_misses_init,