diff options
author | Jakub Jelinek <jakub@redhat.com> | 2016-03-02 20:16:14 +0100 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2016-03-02 20:16:14 +0100 |
commit | da3d46cba8a16bd0981967ea7ed82d54042879ce (patch) | |
tree | f57aa687d2dd5488df0e71d98672b1e7b3265350 /gcc | |
parent | 268bc320088146b2eb3533ec6088e0b566e310de (diff) | |
download | gcc-da3d46cba8a16bd0981967ea7ed82d54042879ce.zip gcc-da3d46cba8a16bd0981967ea7ed82d54042879ce.tar.gz gcc-da3d46cba8a16bd0981967ea7ed82d54042879ce.tar.bz2 |
re PR libgomp/69555 (libgomp.c++/target-6.C fails because of undefined behaviour)
PR libgomp/69555
* gimplify.c (gimplify_decl_expr): For decls with REFERENCE_TYPE, also
gimplify_type_sizes the type they refer to.
(omp_notice_variable): Handle reference vars to VLAs.
* omp-low.c (lower_omp_target): Emit setup of OMP_CLAUSE_PRIVATE reference
to VLA decls in the second pass instead of first pass.
* testsuite/libgomp.c++/pr69555-1.C: New test.
* testsuite/libgomp.c++/pr69555-2.C: New test.
From-SVN: r233913
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ChangeLog | 9 | ||||
-rw-r--r-- | gcc/gimplify.c | 46 | ||||
-rw-r--r-- | gcc/omp-low.c | 32 |
3 files changed, 67 insertions, 20 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 9c72ecb..67cee6b 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,12 @@ +2016-03-02 Jakub Jelinek <jakub@redhat.com> + + PR libgomp/69555 + * gimplify.c (gimplify_decl_expr): For decls with REFERENCE_TYPE, also + gimplify_type_sizes the type they refer to. + (omp_notice_variable): Handle reference vars to VLAs. + * omp-low.c (lower_omp_target): Emit setup of OMP_CLAUSE_PRIVATE reference + to VLA decls in the second pass instead of first pass. + 2016-03-02 Tom de Vries <tom@codesourcery.com> PR tree-optimization/68659 diff --git a/gcc/gimplify.c b/gcc/gimplify.c index e7ea974..b331e41 100644 --- a/gcc/gimplify.c +++ b/gcc/gimplify.c @@ -1436,14 +1436,22 @@ gimplify_decl_expr (tree *stmt_p, gimple_seq *seq_p) if ((TREE_CODE (decl) == TYPE_DECL || TREE_CODE (decl) == VAR_DECL) && !TYPE_SIZES_GIMPLIFIED (TREE_TYPE (decl))) - gimplify_type_sizes (TREE_TYPE (decl), seq_p); + { + gimplify_type_sizes (TREE_TYPE (decl), seq_p); + if (TREE_CODE (TREE_TYPE (decl)) == REFERENCE_TYPE) + gimplify_type_sizes (TREE_TYPE (TREE_TYPE (decl)), seq_p); + } /* ??? DECL_ORIGINAL_TYPE is streamed for LTO so it needs to be gimplified in case its size expressions contain problematic nodes like CALL_EXPR. */ if (TREE_CODE (decl) == TYPE_DECL && DECL_ORIGINAL_TYPE (decl) && !TYPE_SIZES_GIMPLIFIED (DECL_ORIGINAL_TYPE (decl))) - gimplify_type_sizes (DECL_ORIGINAL_TYPE (decl), seq_p); + { + gimplify_type_sizes (DECL_ORIGINAL_TYPE (decl), seq_p); + if (TREE_CODE (DECL_ORIGINAL_TYPE (decl)) == REFERENCE_TYPE) + gimplify_type_sizes (TREE_TYPE (DECL_ORIGINAL_TYPE (decl)), seq_p); + } if (TREE_CODE (decl) == VAR_DECL && !DECL_EXTERNAL (decl)) { @@ -6264,16 +6272,30 @@ omp_notice_variable (struct gimplify_omp_ctx *ctx, tree decl, bool in_code) if ((n->value & (GOVD_SEEN | GOVD_LOCAL)) == 0 && (flags & (GOVD_SEEN | GOVD_LOCAL)) == GOVD_SEEN - && DECL_SIZE (decl) - && TREE_CODE (DECL_SIZE (decl)) != INTEGER_CST) - { - splay_tree_node n2; - tree t = DECL_VALUE_EXPR (decl); - gcc_assert (TREE_CODE (t) == INDIRECT_REF); - t = TREE_OPERAND (t, 0); - gcc_assert (DECL_P (t)); - n2 = splay_tree_lookup (ctx->variables, (splay_tree_key) t); - n2->value |= GOVD_SEEN; + && DECL_SIZE (decl)) + { + if (TREE_CODE (DECL_SIZE (decl)) != INTEGER_CST) + { + splay_tree_node n2; + tree t = DECL_VALUE_EXPR (decl); + gcc_assert (TREE_CODE (t) == INDIRECT_REF); + t = TREE_OPERAND (t, 0); + gcc_assert (DECL_P (t)); + n2 = splay_tree_lookup (ctx->variables, (splay_tree_key) t); + n2->value |= GOVD_SEEN; + } + else if (lang_hooks.decls.omp_privatize_by_reference (decl) + && TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (decl))) + && (TREE_CODE (TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (decl)))) + != INTEGER_CST)) + { + splay_tree_node n2; + tree t = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (decl))); + gcc_assert (DECL_P (t)); + n2 = splay_tree_lookup (ctx->variables, (splay_tree_key) t); + if (n2) + n2->value |= GOVD_SEEN; + } } shared = ((flags | n->value) & GOVD_SHARED) != 0; diff --git a/gcc/omp-low.c b/gcc/omp-low.c index 989d03e..ecbf74a 100644 --- a/gcc/omp-low.c +++ b/gcc/omp-low.c @@ -16472,13 +16472,7 @@ lower_omp_target (gimple_stmt_iterator *gsi_p, omp_context *ctx) x = build_fold_addr_expr_loc (clause_loc, x); } else - { - tree atmp - = builtin_decl_explicit (BUILT_IN_ALLOCA_WITH_ALIGN); - tree rtype = TREE_TYPE (TREE_TYPE (new_var)); - tree al = size_int (TYPE_ALIGN (rtype)); - x = build_call_expr_loc (clause_loc, atmp, 2, x, al); - } + break; x = fold_convert_loc (clause_loc, TREE_TYPE (new_var), x); gimplify_expr (&x, &new_body, NULL, is_gimple_val, fb_rvalue); @@ -16545,7 +16539,8 @@ lower_omp_target (gimple_stmt_iterator *gsi_p, omp_context *ctx) } /* Handle GOMP_MAP_FIRSTPRIVATE_{POINTER,REFERENCE} in second pass, so that firstprivate vars holding OMP_CLAUSE_SIZE if needed - are already handled. */ + are already handled. Similarly OMP_CLAUSE_PRIVATE for VLAs + or references to VLAs. */ for (c = clauses; c; c = OMP_CLAUSE_CHAIN (c)) switch (OMP_CLAUSE_CODE (c)) { @@ -16687,6 +16682,27 @@ lower_omp_target (gimple_stmt_iterator *gsi_p, omp_context *ctx) gimple_seq_add_stmt (&new_body, gimple_build_assign (new_pvar, x)); } + else if (is_reference (var) && !is_gimple_omp_oacc (ctx->stmt)) + { + location_t clause_loc = OMP_CLAUSE_LOCATION (c); + tree new_var = lookup_decl (var, ctx); + tree x = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (new_var))); + if (TREE_CONSTANT (x)) + break; + else + { + tree atmp + = builtin_decl_explicit (BUILT_IN_ALLOCA_WITH_ALIGN); + tree rtype = TREE_TYPE (TREE_TYPE (new_var)); + tree al = size_int (TYPE_ALIGN (rtype)); + x = build_call_expr_loc (clause_loc, atmp, 2, x, al); + } + + x = fold_convert_loc (clause_loc, TREE_TYPE (new_var), x); + gimplify_expr (&x, &new_body, NULL, is_gimple_val, fb_rvalue); + gimple_seq_add_stmt (&new_body, + gimple_build_assign (new_var, x)); + } break; } |