[Bug debug/78363] [7 Regression] ICE in in force_type_die, at dwarf2out.c:24864

2017-01-25 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78363

Richard Biener  changed:

   What|Removed |Added

 Status|ASSIGNED|RESOLVED
 Resolution|--- |FIXED

--- Comment #10 from Richard Biener  ---
Fixed.

[Bug debug/78363] [7 Regression] ICE in in force_type_die, at dwarf2out.c:24864

2017-01-25 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78363

--- Comment #9 from Richard Biener  ---
Author: rguenth
Date: Wed Jan 25 09:48:10 2017
New Revision: 244892

URL: https://gcc.gnu.org/viewcvs?rev=244892=gcc=rev
Log:
2017-01-25  Richard Biener  

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.

Added:
trunk/gcc/testsuite/g++.dg/gomp/pr78363-1.C
trunk/gcc/testsuite/g++.dg/gomp/pr78363-2.C
trunk/gcc/testsuite/g++.dg/gomp/pr78363-3.C
Modified:
trunk/gcc/ChangeLog
trunk/gcc/omp-expand.c
trunk/gcc/testsuite/ChangeLog

[Bug debug/78363] [7 Regression] ICE in in force_type_die, at dwarf2out.c:24864

2017-01-24 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78363

Jakub Jelinek  changed:

   What|Removed |Added

 CC||jamborm at gcc dot gnu.org

--- Comment #8 from Jakub Jelinek  ---
For the expand_omp_target hunk, a testcase would be e.g.

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 ();
}

For tasking as opposed to parallel, testcase that ICEs is e.g.:

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 ();
}

For grid, you want Martin to write a testcase ;).
Regarding finalize_task_copyfn, this is for an artificial function created for
constructors of firstprivate vars in task, like:
struct S { S (); ~S (); S (const S &); };
void foo (S &);

void
bar ()
{
  S s;
#pragma omp task firstprivate (s)
  foo (s);
}
The *cpyfn* for this looks like:
  try
{
  {
.omp_data_o.3_1 = .omp_data_o;
_2 = &.omp_data_o.3_1->s;
_3 = .omp_data_i->s;
S::S (_2, _3);
return;
  }
}
  catch
{
  <<>>
}
and is not actually outlined from the original function, but rather constructed
from scratch.  Couldn't get ICE on it, so let's ignore that for now.

[Bug debug/78363] [7 Regression] ICE in in force_type_die, at dwarf2out.c:24864

2017-01-24 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78363

--- Comment #7 from Richard Biener  ---
(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 (, 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));

[Bug debug/78363] [7 Regression] ICE in in force_type_die, at dwarf2out.c:24864

2017-01-17 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78363

--- Comment #6 from Jakub Jelinek  ---
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.

[Bug debug/78363] [7 Regression] ICE in in force_type_die, at dwarf2out.c:24864

2017-01-13 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78363

Richard Biener  changed:

   What|Removed |Added

   Priority|P3  |P1
 Status|NEW |ASSIGNED
   Assignee|unassigned at gcc dot gnu.org  |rguenth at gcc dot 
gnu.org

[Bug debug/78363] [7 Regression] ICE in in force_type_die, at dwarf2out.c:24864

2016-11-16 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78363

--- Comment #5 from Richard Biener  ---
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 *vars_map,
   for (tp = _VARS (block); *tp; tp = _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 (, 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 *vars_map,
   for (tp = _VARS (block); *tp; tp = _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 (, vars_map, to_context);


any preference?

[Bug debug/78363] [7 Regression] ICE in in force_type_die, at dwarf2out.c:24864

2016-11-16 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78363

--- Comment #4 from Richard Biener  ---
Ok, so we eliminate as unused

DIE0: DW_TAG_structure_type (0x2c04fb40)
  abbrev id: 0 offset: 0 mark: 0
  DW_AT_name: ""
  DW_AT_byte_size: 1
  DW_AT_decl_file: "t.ii" (0)
  DW_AT_decl_line: 5
DIE0: DW_TAG_subprogram (0x2c04fb90)
  abbrev id: 0 offset: 0 mark: 0
  DW_AT_name: "~"
  DW_AT_artificial: 1
  DW_AT_declaration: 1
  DW_AT_object_pointer: die -> 0 (0x2c04fbe0)
DIE0: DW_TAG_formal_parameter (0x2c04fbe0)
  abbrev id: 0 offset: 0 mark: 0
  DW_AT_type: die -> 0 (0x2c04fc30)
  DW_AT_artificial: 1
DIE0: DW_TAG_pointer_type (0x2c04fc30)
  abbrev id: 0 offset: 0 mark: 0
  DW_AT_byte_size: 8
  DW_AT_type: die -> 0 (0x2c04fb40)
DIE0: DW_TAG_formal_parameter (0x2c04fc80)
  abbrev id: 0 offset: 0 mark: 0
  DW_AT_type: die -> 0 (0x2c04f910)
  DW_AT_artificial: 1
DIE0: DW_TAG_subprogram (0x2c04fcd0)
  abbrev id: 0 offset: 0 mark: 0
  DW_AT_name: "operator()"
  DW_AT_type: die -> 0 (0x2c04f910)
  DW_AT_artificial: 1
  DW_AT_object_pointer: die -> 0 (0x2c04ff00)
DIE0: DW_TAG_pointer_type (0x2c04fd70)
  abbrev id: 0 offset: 0 mark: 0
  DW_AT_byte_size: 8
  DW_AT_type: die -> 0 (0x2c04fdc0)
DIE0: DW_TAG_const_type (0x2c04ff50)
  abbrev id: 0 offset: 0 mark: 0
  DW_AT_type: die -> 0 (0x2c04fd70)
DIE0: DW_TAG_const_type (0x2c04fdc0)
  abbrev id: 0 offset: 0 mark: 0
  DW_AT_type: die -> 0 (0x2c04fb40)
DIE0: DW_TAG_formal_parameter (0x2c04ff00)
  abbrev id: 0 offset: 0 mark: 0
  DW_AT_name: "__closure"
  DW_AT_type: die -> 0 (0x2c04ff50)
  DW_AT_artificial: 1

even though the functions are called.  die_perennial_p is not set and
the lambda DW_TAG_structure_type is not in function context (for whatever
reason).  So

  for (c = die->die_parent; c; c = c->die_parent)
if (c->die_tag == DW_TAG_subprogram)
  break;

  /* Finding used static member functions inside of classes
 is needed just for local classes, because for other classes
 static member function DIEs with DW_AT_specification
 are emitted outside of the DW_TAG_*_type.  If we ever change
 it, we'd need to call this even for non-local classes.  */
  if (c)
prune_unused_types_walk_local_classes (die);

doesn't apply.

The DIE for the type is created when the early DIE for main._omp_fn.0 is
created, via walking of its BLOCK tree.  At this point the DIE for main
is not yet created.  The main._omp_fn.0 function also nowhere refers
back to main (via abstract origin or so as cloning generally does).

Thus the DIE ends up in limbo and is put to CU context in early-finish
flush-limbo-die-list because scope-die-for doesn't handle FUNCTION_DECL
scope.  Those are supposed to be handled by process_scope_vars but as
I said in my initial comment the context is off (as the BLOCK got moved
to main._omp_fn.0).

[Bug debug/78363] [7 Regression] ICE in in force_type_die, at dwarf2out.c:24864

2016-11-15 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78363

Richard Biener  changed:

   What|Removed |Added

   Keywords||openmp, wrong-debug
 CC||jakub at gcc dot gnu.org

--- Comment #3 from Richard Biener  ---
So we emit late debug for  we didn't
emit early debug for.  But we pruned its (type) context already.

So the bug is that we fail to emit early debug for the above decl.

(gdb) p decl
$8 = 
(gdb) p decl_function_context(decl)
$7 = (tree_node *) 0x76a06300
(gdb) p debug_tree ($7)
 )
at /space/rguenther/src/svn/trunk/gcc/dwarf2out.c:25227
25227 set_early_dwarf s;
Missing separate debuginfos, use: zypper install
libgmp10-debuginfo-6.0.0-71.1.x86_64 libisl15-debuginfo-0.16.1-0.x86_64
libmpc3-debuginfo-1.0.2-38.2.x86_64 libmpfr4-debuginfo-3.1.2-3.1.2.x86_64
(gdb) p debug_tree (decl->decl_common.initial)
 
chain > supercontext 
subblocks  supercontext >>>
$1 = void
(gdb) p debug_tree (0x76a02e40)
 >

so whenever dwarf2out looks at contexts of __lambda0 it ends up at main
rather tha at main._omp_fn.0.  This is an artifact of move_sese_region_to_fn
not copying anything but just "rewiring" stuff.  It already replaces
BLOCK_VARS by "duplicates" but fails to handle non-vars.

[Bug debug/78363] [7 Regression] ICE in in force_type_die, at dwarf2out.c:24864

2016-11-15 Thread marxin at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78363

Martin Liška  changed:

   What|Removed |Added

 Status|UNCONFIRMED |NEW
   Keywords||ice-on-valid-code
   Last reconfirmed||2016-11-15
 CC||marxin at gcc dot gnu.org,
   ||rguenth at gcc dot gnu.org
 Ever confirmed|0   |1
Summary|internal compiler error: in |[7 Regression] ICE in in
   |force_type_die, at  |force_type_die, at
   |dwarf2out.c:24864   |dwarf2out.c:24864
   Target Milestone|--- |7.0
  Known to fail||6.2.0

--- Comment #2 from Martin Liška  ---
Confirmed, started with r240578.