enum gimplify_status ret;
int i, nargs;
gcall *call;
- bool builtin_va_start_p = false, omp_dispatch_p = false;
+ bool builtin_va_start_p = false, omp_dispatch_p = false,
+ variant_substituted_p = false;
location_t loc = EXPR_LOCATION (*expr_p);
gcc_assert (TREE_CODE (*expr_p) == CALL_EXPR);
{
tree variant = omp_resolve_declare_variant (fndecl);
if (variant != fndecl)
- CALL_EXPR_FN (*expr_p) = build1 (ADDR_EXPR, fnptrtype, variant);
+ {
+ CALL_EXPR_FN (*expr_p) = build1 (ADDR_EXPR, fnptrtype, variant);
+ variant_substituted_p = true;
+ }
}
/* There is a sequence point before the call, so any side effects in
}
}
- if ((need_device_ptr && !is_device_ptr)
- || (need_device_addr && !has_device_addr))
+ if (variant_substituted_p
+ && ((need_device_ptr && !is_device_ptr)
+ || (need_device_addr && !has_device_addr)))
{
if (dispatch_device_num == NULL_TREE)
{
--- /dev/null
+/* { dg-do compile } */
+/* { dg-additional-options "-fdump-tree-gimple" } */
+
+/* Ensure that adjust_args is only applied when variant substitution happens. */
+
+void h(int *);
+void f(int *);
+#pragma omp declare variant(f) match(construct={dispatch}) adjust_args(need_device_ptr : x)
+void g(int *x);
+
+void foo(int *y)
+{
+ #pragma omp dispatch
+ h(y);
+ #pragma omp dispatch
+ f(y);
+ #pragma omp dispatch
+ g(y);
+}
+
+/* { dg-final { scan-tree-dump-times "h \\(y\\);" 1 "gimple" } } */
+/* { dg-final { scan-tree-dump-times "f \\(y\\);" 1 "gimple" } } */
+/* { dg-final { scan-tree-dump-times "D\.\[0-9]+ = __builtin_omp_get_mapped_ptr \\(y, D\.\[0-9]+\\);" 1 "gimple" } } */
+/* { dg-final { scan-tree-dump-times "f \\(D\.\[0-9]+\\);" 1 "gimple" } } */