@@ -14775,6 +14775,27 @@ gimplify_omp_metadirective (tree *expr_p, gimple_seq *pre_p, gimple_seq *,
{
auto_vec<tree> selectors;
+ /* Mark offloadable functions containing metadirectives that specify
+ a 'construct' selector with a 'target' constructor. */
+ if (offloading_function_p (current_function_decl))
+ {
+ for (tree clause = OMP_METADIRECTIVE_CLAUSES (*expr_p);
+ clause != NULL_TREE; clause = TREE_CHAIN (clause))
+ {
+ tree selector = TREE_PURPOSE (clause);
+
+ if (omp_has_target_constructor_p (selector))
+ {
+ tree id = get_identifier ("omp metadirective construct target");
+
+ DECL_ATTRIBUTES (current_function_decl)
+ = tree_cons (id, NULL_TREE,
+ DECL_ATTRIBUTES (current_function_decl));
+ break;
+ }
+ }
+ }
+
/* Try to resolve the metadirective. */
vec<struct omp_metadirective_variant> candidates
= omp_resolve_metadirective (*expr_p);
@@ -2922,6 +2922,27 @@ omp_resolve_metadirective (gimple *gs)
return omp_get_dynamic_candidates (variants);
}
+bool
+omp_has_target_constructor_p (tree selector)
+{
+ if (selector == NULL_TREE)
+ return false;
+
+ tree selector_set = TREE_PURPOSE (selector);
+ if (strcmp (IDENTIFIER_POINTER (selector_set), "construct") != 0)
+ return false;
+
+ enum tree_code constructs[5];
+ int nconstructs
+ = omp_constructor_traits_to_codes (TREE_VALUE (selector), constructs);
+
+ for (int i = 0; i < nconstructs; i++)
+ if (constructs[i] == OMP_TARGET)
+ return true;
+
+ return false;
+}
+
/* Encode an oacc launch argument. This matches the GOMP_LAUNCH_PACK
macro on gomp-constants.h. We do not check for overflow. */
@@ -126,6 +126,7 @@ extern tree omp_get_context_selector (tree, const char *, const char *);
extern tree omp_resolve_declare_variant (tree);
extern vec<struct omp_metadirective_variant> omp_resolve_metadirective (tree);
extern vec<struct omp_metadirective_variant> omp_resolve_metadirective (gimple *);
+extern bool omp_has_target_constructor_p (tree);
extern tree oacc_launch_pack (unsigned code, tree device, unsigned op);
extern tree oacc_replace_fn_attrib_attr (tree attribs, tree dims);
extern void oacc_replace_fn_attrib (tree fn, tree dims);
@@ -14300,6 +14300,24 @@ lower_omp_1 (gimple_stmt_iterator *gsi_p, omp_context *ctx)
tree fndecl;
call_stmt = as_a <gcall *> (stmt);
fndecl = gimple_call_fndecl (call_stmt);
+ if (fndecl
+ && lookup_attribute ("omp metadirective construct target",
+ DECL_ATTRIBUTES (fndecl)))
+ {
+ bool in_target_ctx = false;
+
+ for (omp_context *up = ctx; up; up = up->outer)
+ if (gimple_code (up->stmt) == GIMPLE_OMP_TARGET)
+ {
+ in_target_ctx = true;
+ break;
+ }
+ if (!ctx || !in_target_ctx)
+ warning_at (gimple_location (stmt), 0,
+ "direct calls to an offloadable function containing "
+ "metadirectives with a %<construct={target}%> "
+ "selector may produce unexpected results");
+ }
if (fndecl
&& fndecl_built_in_p (fndecl, BUILT_IN_NORMAL))
switch (DECL_FUNCTION_CODE (fndecl))
@@ -25,7 +25,7 @@ void f(double a[], double x) {
/* TODO: This does not execute a version of f with the default clause
active as might be expected. */
- f (a, 2.71828);
+ f (a, 2.71828); /* { dg-warning "direct calls to an offloadable function containing metadirectives with a 'construct={target}' selector may produce unexpected results" } */
return 0;
}
@@ -13,7 +13,7 @@ program test
! TODO: This does not execute a version of f with the default clause
! active as might be expected.
- call f (a, 2.71828)
+ call f (a, 2.71828) ! { dg-warning "direct calls to an offloadable function containing metadirectives with a 'construct={target}' selector may produce unexpected results" }
contains
subroutine f (a, x)
integer :: i
@@ -31,7 +31,7 @@ void f(double a[], double x) {
/* TODO: This does not execute a version of f with the default clause
active as might be expected. */
- f (a, M_E);
+ f (a, M_E); /* { dg-warning "direct calls to an offloadable function containing metadirectives with a 'construct={target}' selector may produce unexpected results" } */
for (i = 0; i < N; i++)
if (fabs (a[i] - (M_E * i)) > EPSILON)
@@ -19,7 +19,7 @@ program test
! TODO: This does not execute a version of f with the default clause
! active as might be expected.
- call f (a, E_CONST)
+ call f (a, E_CONST) ! { dg-warning "direct calls to an offloadable function containing metadirectives with a 'construct={target}' selector may produce unexpected results" }
do i = 1, N
if (abs (a(i) - (E_CONST * i)) .gt. EPSILON) stop 2