https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66714

--- Comment #21 from vries at gcc dot gnu.org ---
(In reply to cesar from comment #20)
> Created attachment 36030 [details]
> replace block vars fix
> 
> Tom, thanks for your detailed analysis and reduced test case. As you
> suspected, replace_block_vars_by_duplicates isn't updating the
> DECL_VALUE_EXPR properly.

Yeah, and AFAIU Michaels analysis (
https://gcc.gnu.org/ml/gcc-patches/2015-07/msg01037.html ) he agrees that that
is the problem.

> That function is setting the value expr to be the
> original decl, not the new offloaded copy. My patch teaches it how to use an
> offloaded copy. 
> 

Cool.

> All of the value exprs we're interested in for openacc are INDIRECT_REFs and
> I think that holds true for openmp too. Fortran cray pointers caused some
> minor problems because those get represented by a INDIRECT_REF to a
> CONVERT_EXPR as you in the patch. 
> 

> --- a/gcc/tree-cfg.c  
> +++ a/gcc/tree-cfg.c  
> @@ -6916,7 +6916,29 @@ replace_block_vars_by_duplicates (tree block, 
> hash_map<tree, tree> *vars_map,
>       {
>         if (TREE_CODE (*tp) == VAR_DECL && DECL_HAS_VALUE_EXPR_P (*tp))
>           {
> -           SET_DECL_VALUE_EXPR (t, DECL_VALUE_EXPR (*tp));
> +           tree x = DECL_VALUE_EXPR (*tp);
> +
> +           if (TREE_CODE (x) == INDIRECT_REF)
> +             {
> +               tree expr = TREE_OPERAND (x, 0);
> +               tree decl;
> +
> +               if (CONVERT_EXPR_CODE_P (TREE_CODE (expr)))
> +                 decl = TREE_OPERAND (expr, 0);
> +               else
> +                 decl = expr;
> +
> +               replace_by_duplicate_decl (&decl, vars_map, to_context);
> +
> +               if (CONVERT_EXPR_CODE_P (TREE_CODE (expr)))
> +                 expr = build1 (TREE_CODE (expr), TREE_TYPE (expr), decl);
> +               else
> +                 expr = decl;
> +
> +               x = build_simple_mem_ref (expr);
> +             }

How about 

+             else
+               gcc_unreachable ();

?

That makes sure you run into all the unhandled cases.


> I tested this patch in gomp-4_0-branch libgomp and everything appears to
> work. Does this issue present in trunk too?

Yep, this PR was originally filed as gomp-4_0-branch PR but, I changed it to
trunk PR at comment 13.

Reply via email to