From: Jakub Jelinek Date: Fri, 9 Feb 2018 23:22:43 +0000 (+0100) Subject: re PR sanitizer/83987 (ICE with OpenMP, sanitizer and virtual bases) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=6724f8a61d49dfdfaa11995765b85ee170e48ac7;p=gcc.git re PR sanitizer/83987 (ICE with OpenMP, sanitizer and virtual bases) PR sanitizer/83987 * omp-low.c (maybe_remove_omp_member_access_dummy_vars, remove_member_access_dummy_vars): New functions. (lower_omp_for, lower_omp_taskreg, lower_omp_target, lower_omp_1, execute_lower_omp): Use them. * tree.c (cp_free_lang_data): Revert 2018-01-23 change. * g++.dg/ubsan/pr83987-2.C: New test. From-SVN: r257545 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 5766bc51859..0ee4f1cf6b3 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,5 +1,11 @@ 2018-02-10 Jakub Jelinek + PR sanitizer/83987 + * omp-low.c (maybe_remove_omp_member_access_dummy_vars, + remove_member_access_dummy_vars): New functions. + (lower_omp_for, lower_omp_taskreg, lower_omp_target, + lower_omp_1, execute_lower_omp): Use them. + PR rtl-optimization/84308 * shrink-wrap.c (spread_components): Release todo vector. diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 9df4c2948af..e01e73bb97b 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2018-02-10 Jakub Jelinek + + PR sanitizer/83987 + * tree.c (cp_free_lang_data): Revert 2018-01-23 change. + 2018-02-09 Jason Merrill PR c++/81917 - ICE with void_t and partial specialization. diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index d85f934f2de..a53bddf2ef0 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -5273,16 +5273,6 @@ cp_free_lang_data (tree t) /* We do not need the leftover chaining of namespaces from the binding level. */ DECL_CHAIN (t) = NULL_TREE; - /* Set DECL_VALUE_EXPRs of OpenMP privatized member artificial - decls to error_mark_node. These are DECL_IGNORED_P and after - OpenMP lowering they aren't useful anymore. Clearing DECL_VALUE_EXPR - doesn't work, as expansion could then consider them as something - to be expanded. */ - if (VAR_P (t) - && DECL_LANG_SPECIFIC (t) - && DECL_OMP_PRIVATIZED_MEMBER (t) - && DECL_IGNORED_P (t)) - SET_DECL_VALUE_EXPR (t, error_mark_node); } /* Stub for c-common. Please keep in sync with c-decl.c. diff --git a/gcc/omp-low.c b/gcc/omp-low.c index ebbf88e250e..d8588b9faed 100644 --- a/gcc/omp-low.c +++ b/gcc/omp-low.c @@ -3208,6 +3208,43 @@ scan_omp (gimple_seq *body_p, omp_context *ctx) /* Re-gimplification and code generation routines. */ +/* Remove omp_member_access_dummy_var variables from gimple_bind_vars + of BIND if in a method. */ + +static void +maybe_remove_omp_member_access_dummy_vars (gbind *bind) +{ + if (DECL_ARGUMENTS (current_function_decl) + && DECL_ARTIFICIAL (DECL_ARGUMENTS (current_function_decl)) + && (TREE_CODE (TREE_TYPE (DECL_ARGUMENTS (current_function_decl))) + == POINTER_TYPE)) + { + tree vars = gimple_bind_vars (bind); + for (tree *pvar = &vars; *pvar; ) + if (omp_member_access_dummy_var (*pvar)) + *pvar = DECL_CHAIN (*pvar); + else + pvar = &DECL_CHAIN (*pvar); + gimple_bind_set_vars (bind, vars); + } +} + +/* Remove omp_member_access_dummy_var variables from BLOCK_VARS of + block and its subblocks. */ + +static void +remove_member_access_dummy_vars (tree block) +{ + for (tree *pvar = &BLOCK_VARS (block); *pvar; ) + if (omp_member_access_dummy_var (*pvar)) + *pvar = DECL_CHAIN (*pvar); + else + pvar = &DECL_CHAIN (*pvar); + + for (block = BLOCK_SUBBLOCKS (block); block; block = BLOCK_CHAIN (block)) + remove_member_access_dummy_vars (block); +} + /* If a context was created for STMT when it was scanned, return it. */ static omp_context * @@ -6961,6 +6998,7 @@ lower_omp_for (gimple_stmt_iterator *gsi_p, omp_context *ctx) pop_gimplify_context (new_stmt); gimple_bind_append_vars (new_stmt, ctx->block_vars); + maybe_remove_omp_member_access_dummy_vars (new_stmt); BLOCK_VARS (block) = gimple_bind_vars (new_stmt); if (BLOCK_VARS (block)) TREE_USED (block) = 1; @@ -7413,6 +7451,7 @@ lower_omp_taskreg (gimple_stmt_iterator *gsi_p, omp_context *ctx) /* Declare all the variables created by mapping and the variables declared in the scope of the parallel body. */ record_vars_into (ctx->block_vars, child_fn); + maybe_remove_omp_member_access_dummy_vars (par_bind); record_vars_into (gimple_bind_vars (par_bind), child_fn); if (ctx->record_type) @@ -7781,6 +7820,7 @@ lower_omp_target (gimple_stmt_iterator *gsi_p, omp_context *ctx) /* Declare all the variables created by mapping and the variables declared in the scope of the target body. */ record_vars_into (ctx->block_vars, child_fn); + maybe_remove_omp_member_access_dummy_vars (tgt_bind); record_vars_into (gimple_bind_vars (tgt_bind), child_fn); } @@ -8772,6 +8812,7 @@ lower_omp_1 (gimple_stmt_iterator *gsi_p, omp_context *ctx) break; case GIMPLE_BIND: lower_omp (gimple_bind_body_ptr (as_a (stmt)), ctx); + maybe_remove_omp_member_access_dummy_vars (as_a (stmt)); break; case GIMPLE_OMP_PARALLEL: case GIMPLE_OMP_TASK: @@ -8976,6 +9017,16 @@ execute_lower_omp (void) all_contexts = NULL; } BITMAP_FREE (task_shared_vars); + + /* If current function is a method, remove artificial dummy VAR_DECL created + for non-static data member privatization, they aren't needed for + debuginfo nor anything else, have been already replaced everywhere in the + IL and cause problems with LTO. */ + if (DECL_ARGUMENTS (current_function_decl) + && DECL_ARTIFICIAL (DECL_ARGUMENTS (current_function_decl)) + && (TREE_CODE (TREE_TYPE (DECL_ARGUMENTS (current_function_decl))) + == POINTER_TYPE)) + remove_member_access_dummy_vars (DECL_INITIAL (current_function_decl)); return 0; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index fdbb5493a77..1688f5a8aa2 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-02-10 Jakub Jelinek + + PR sanitizer/83987 + * g++.dg/ubsan/pr83987-2.C: New test. + 2018-02-09 Peter Bergner PR target/83926 diff --git a/gcc/testsuite/g++.dg/ubsan/pr83987-2.C b/gcc/testsuite/g++.dg/ubsan/pr83987-2.C new file mode 100644 index 00000000000..a70b7b2850b --- /dev/null +++ b/gcc/testsuite/g++.dg/ubsan/pr83987-2.C @@ -0,0 +1,24 @@ +// PR sanitizer/83987 +// { dg-do compile { target fopenmp } } +// { dg-options "-fopenmp -fsanitize=vptr" } + +struct A +{ + int i; +}; + +struct B : virtual A +{ + void foo(); +}; + +void B::foo() +{ +#pragma omp parallel + { + #pragma omp sections lastprivate (i) + { + i = 0; + } + } +}