https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78363
--- Comment #7 from Richard Biener <rguenth at gcc dot gnu.org> --- (In reply to Jakub Jelinek from comment #6) > I think I'd prefer the second hunk (but it needs to go omp-expand.c instead), > guarded with if (!gimple_in_ssa_p (cfun)), so that it is really done only > early. It should likely be done in expand_omp_target too, not sure about > grid_expand_target_grid_body, Martin?). And for omp_cpyfn already in > omp-low.c's finalize_task_copyfn. Perhaps best spot for the debug early > hook is close to the cgraph_node::add_new_function calls in omp*.c. Not sure I understand the finalize_task_copyfn place -- it's important to generate early debug before outlining anything (any part of the fns BLOCK tree). I think the following catches all of those, the taskreg one is enough to fix the testcase (testcases for the others would be nice to have). Thus the following is what I am going to bootstrap/test: Index: gcc/omp-expand.c =================================================================== --- gcc/omp-expand.c (revision 244867) +++ 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));