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

--- Comment #5 from Richard Biener <rguenth at gcc dot gnu.org> ---
diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c
index e99e102..e23c8c6 100644
--- a/gcc/tree-cfg.c
+++ b/gcc/tree-cfg.c
@@ -7054,6 +7054,13 @@ replace_block_vars_by_duplicates (tree block,
hash_map<tree, tree> *vars_map,
   for (tp = &BLOCK_VARS (block); *tp; tp = &DECL_CHAIN (*tp))
     {
       t = *tp;
+      /* Re-wire types to the new context so debug info can be properly
+         emitted.  */
+      if (TREE_CODE (t) == TYPE_DECL)
+       {
+         DECL_CONTEXT (t) = to_context;
+         TYPE_CONTEXT (TREE_TYPE (t)) = to_context;
+       }
       if (!VAR_P (t) && TREE_CODE (t) != CONST_DECL)
        continue;
       replace_by_duplicate_decl (&t, vars_map, to_context);

fixes this, so does

diff --git a/gcc/omp-low.c b/gcc/omp-low.c
index 331da6a..5ef5c05 100644
--- a/gcc/omp-low.c
+++ b/gcc/omp-low.c
@@ -84,6 +84,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "symbol-summary.h"
 #include "hsa.h"
 #include "params.h"
+#include "debug.h"

 /* Lowering of OMP parallel and workshare constructs proceeds in two
    phases.  The first phase scans the function looking for OMP statements
@@ -7347,6 +7348,7 @@ expand_omp_taskreg (struct omp_region *region)
       else
        block = gimple_block (entry_stmt);

+      (*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;

but I'm not sure (for both cases) that late invocation (first hunk via
parloops at least) will not break things again.

Note the 2nd hunk makes sure we preserve the original BLOCK structure in
debug-info for main.

As with all our "IPA" opts some more thought about debug needs to be done...

The 2nd hunk should eventually move to move_sese_region_to_fn of course
but then (because of parloops) we need a way to query the debug backend
whether we still may call early-global-decl.  Oh, and move_sese_region_to_fn
would need to strip TYPE_DECLs from the BLOCKs it "moves".

Which means a third option also works (no early/late issue but of course
it might lose debug when done early - it doesn't for this testcase):

diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c
index e99e102..6fb56bf 100644
--- a/gcc/tree-cfg.c
+++ b/gcc/tree-cfg.c
@@ -7054,6 +7054,15 @@ replace_block_vars_by_duplicates (tree block,
hash_map<tree, tree> *vars_map,
   for (tp = &BLOCK_VARS (block); *tp; tp = &DECL_CHAIN (*tp))
     {
       t = *tp;
+      /* Drop TYPE_DECLs, they have wrong context and confuse debug
+        generation.  */
+      if (TREE_CODE (t) == TYPE_DECL)
+       {
+         *tp = DECL_CHAIN (t);
+         if (!*tp)
+           break;
+         continue;
+       }
       if (!VAR_P (t) && TREE_CODE (t) != CONST_DECL)
        continue;
       replace_by_duplicate_decl (&t, vars_map, to_context);


any preference?

Reply via email to