The following patch fixes PR78363, debug confused by early debug emitted from inconsistent IL which happens after OMP outlining wrecks parts of the BLOCK tree (outlined TYPE_DECLs have wrong context).
Bootstrapped and tested on x86_64-unknown-linux-gnu, ok for trunk? Thanks, Richard. 2017-01-25 Richard Biener <rguent...@suse.de> PR debug/78363 * omp-expand.c: Include debug.h. (expand_omp_taskreg): Make sure to generate early debug before outlining anything from a function. (expand_omp_target): Likewise. (grid_expand_target_grid_body): Likewise. * g++.dg/gomp/pr78363-1.C: New testcase. * g++.dg/gomp/pr78363-2.C: Likewise. * g++.dg/gomp/pr78363-3.C: Likewise. Index: gcc/omp-expand.c =================================================================== --- gcc/omp-expand.c (revision 244890) +++ gcc/omp-expand.c (working copy) @@ -57,6 +57,7 @@ along with GCC; see the file COPYING3. #include "gomp-constants.h" #include "gimple-pretty-print.h" #include "hsa-common.h" +#include "debug.h" /* OMP region information. Every parallel and workshare @@ -1305,6 +1306,11 @@ expand_omp_taskreg (struct omp_region *r else block = gimple_block (entry_stmt); + /* Make sure to generate early debug for the function before + outlining anything. */ + if (! gimple_in_ssa_p (cfun)) + (*debug_hooks->early_global_decl) (cfun->decl); + new_bb = move_sese_region_to_fn (child_cfun, entry_bb, exit_bb, block); if (exit_bb) single_succ_edge (new_bb)->flags = EDGE_FALLTHRU; @@ -7016,6 +7022,11 @@ expand_omp_target (struct omp_region *re gsi_remove (&gsi, true); } + /* Make sure to generate early debug for the function before + outlining anything. */ + if (! gimple_in_ssa_p (cfun)) + (*debug_hooks->early_global_decl) (cfun->decl); + /* Move the offloading region into CHILD_CFUN. */ block = gimple_block (entry_stmt); @@ -7589,6 +7600,11 @@ grid_expand_target_grid_body (struct omp init_tree_ssa (cfun); pop_cfun (); + /* Make sure to generate early debug for the function before + outlining anything. */ + if (! gimple_in_ssa_p (cfun)) + (*debug_hooks->early_global_decl) (cfun->decl); + tree old_parm_decl = DECL_ARGUMENTS (kern_fndecl); gcc_assert (!DECL_CHAIN (old_parm_decl)); tree new_parm_decl = copy_node (DECL_ARGUMENTS (kern_fndecl)); Index: gcc/testsuite/g++.dg/gomp/pr78363-1.C =================================================================== --- gcc/testsuite/g++.dg/gomp/pr78363-1.C (nonexistent) +++ gcc/testsuite/g++.dg/gomp/pr78363-1.C (working copy) @@ -0,0 +1,14 @@ +// { dg-do compile } +// { dg-require-effective-target c++11 } +// { dg-options "-g -fopenmp" } + +int main() +{ + int n = 0; + +#pragma omp parallel for reduction (+: n) + for (int i = [](){ return 3; }(); i < 10; ++i) + n++; + + return n; +} Index: gcc/testsuite/g++.dg/gomp/pr78363-2.C =================================================================== --- gcc/testsuite/g++.dg/gomp/pr78363-2.C (nonexistent) +++ gcc/testsuite/g++.dg/gomp/pr78363-2.C (working copy) @@ -0,0 +1,15 @@ +// { dg-do compile } +// { dg-require-effective-target c++11 } +// { dg-options "-g -fopenmp" } + +int main() +{ + int n = 0; +#pragma omp target map(tofrom:n) +#pragma omp for reduction (+: n) + for (int i = [](){ return 3; }(); i < 10; ++i) + n++; + if (n != 7) + __builtin_abort (); + return 0; +} Index: gcc/testsuite/g++.dg/gomp/pr78363-3.C =================================================================== --- gcc/testsuite/g++.dg/gomp/pr78363-3.C (nonexistent) +++ gcc/testsuite/g++.dg/gomp/pr78363-3.C (working copy) @@ -0,0 +1,14 @@ +// { dg-do compile } +// { dg-require-effective-target c++11 } +// { dg-options "-g -fopenmp" } + +int main() +{ + int n = 0; +#pragma omp task shared (n) + for (int i = [](){ return 3; }(); i < 10; ++i) + n = i; +#pragma omp taskwait + if (n != 7) + __builtin_abort (); +}