The following works with PARALLEL but not with TARGET. OpenMP states the following is supposed to work: A = 5; // == this->A B = 6; // == this->B C[44] = 7; // == this->C; assume 'int C[100]' #pragma firstprivate(A,C) private(B) { A += 5; // Now: A is 10. B = 7; C[44] += 7; // Now C is 14 // It is unspecified what value this->{A,B,C} has } // {A,B,C[44]} == this->{A,B,C[44]} are still {5,6,7} * * * In the C++ FE, that's handled by creating a temporary variable:      v = create_temporary_var (TREE_TYPE (m)); with      SET_DECL_VALUE_EXPR (v, m); DECL_OMP_PRIVATIZED_MEMBER(v) where 'm' is, e.g., 'this->A' - and a bunch of 'if (DECL_OMP_PRIVATIZED_MEMBER(decl))' in the g++ FE, only. For PARALLEL, the VALUE_EXPR survives until omp-low.cc, which handles this for (first)privatizing. But for TARGET, in gimplify.cc, after the following call in gimplify_omp_workshare 16813 gimple *g = gimplify_and_return_first (OMP_BODY (expr), &body); the 'A' in the body will be turned into 'this->A'. * * * Thus, while there is after omplower the expected #pragma omp target ... firstprivate(A) and also    D.3081 = .omp_data_i->A; A= ...; what actually gets used is    D.3084 = .omp_data_i->D.3046;    this = D.3084;    D.2996 = this->A; which unsurprisingly breaks. * * * This can be "fixed" by using the following patch. With that patch, the -fdump-tree-omplower looks fine. But it does then fail with: during RTL pass: expand g2.cpp:11:7: internal compiler error: in make_decl_rtl, at varasm.cc:1443 for the 'A' with 'B = A' (where B is a non-member var) and 'A' is still as the value expr 'this->A'. --- a/gcc/gimplify.cc +++ b/gcc/gimplify.cc @@ -3285,12 +3285,15 @@ gimplify_var_or_parm_decl (tree *expr_p) if (gimplify_omp_ctxp && omp_notice_variable (gimplify_omp_ctxp, decl, true)) return GS_ALL_DONE; + if (!flag_openmp) // Assume: C++'s DECL_OMP_PRIVATIZED_MEMBER (decl) + { /* If the decl is an alias for another expression, substitute it. */ if (DECL_HAS_VALUE_EXPR_P (decl)) { *expr_p = unshare_expr (DECL_VALUE_EXPR (decl)); return GS_OK; } + } return GS_ALL_DONE; } * * * Any idea / suggestion how to handle this best? One way I see would be to add a lang-hook here to check for DECL_OMP_PRIVATIZED_MEMBER, similar to the hack above. And then ensure that the DECL_VALUE_EXPR points to the var decl in the target region (i.e. some hacking in omp-low.cc). I have no idea whether that would - nor whether that would be the way forward. - Thoughts? Tobias