Re: [PATCH] d: Fix ICE in in force_decl_die, at dwarf2out.c with -gdwarf-2 -gstrict-dwarf [PR98067]

2020-12-16 Thread Jason Merrill via Gcc-patches

On 12/15/20 7:15 PM, Iain Buclaw wrote:

Hi,

This patch fixes an ICE in dwarf2out.c that occurs when compiling a
selective import declaration in D with strict dwarf2 in effect.

Manifest constants in D are represented as CONST_DECLs, which can be
imported from one module to another.  However, when compiling on strict
dwarf2 targets such as *-*darwin10, importing CONST_DECLs cannot be
represented in debug as D did not exist as an AT_language until dwarf3,
and the only available fallback being DW_LANG_C.  As CONST_DECLs are
treated as enumerators in C, and not outputted individually in
gen_decl_die, this causes an internal error in force_decl_die to occur.

To handle this, similar to other places in dwarf2out, if a CONST_DECL is
seen in dwarf2out_imported_module_or_decl_1, then we simply return early
if the language is not one of Ada, D, or Fortran.

The new files and tests added are boilerplate for introducing
gdc.dg/debug and gdc.dg/debug/dwarf2 test directories, as well as two
extra tests - langdw2.d and langdw3.d - that verify that DW_LANG_D is
set except for strict dwarf2.

This has been bootstrapped, and the D testsuite regression tested on
x86_64-linux-gnu/-m32/-mx32.

OK for mainline?


OK.


Iain.

---
gcc/ChangeLog:

PR d/98067
* dwarf2out.c (dwarf2out_imported_module_or_decl_1): Handle
  CONST_DECL only if is_fortran, is_ada, or is_dlang.

gcc/testsuite/ChangeLog:

PR d/98067
* gdc.dg/debug/debug.exp: New test.
* gdc.dg/debug/dwarf2/dwarf2.exp: New test.
* gdc.dg/debug/dwarf2/imports/pr98067.d: New test.
* gdc.dg/debug/dwarf2/langdw2.d: New test.
* gdc.dg/debug/dwarf2/langdw3.d: New test.
* gdc.dg/debug/dwarf2/pr98067.d: New test.
* gdc.dg/debug/trivial.d: New test.
---
  gcc/dwarf2out.c   |  7 
  gcc/testsuite/gdc.dg/debug/debug.exp  | 28 ++
  gcc/testsuite/gdc.dg/debug/dwarf2/dwarf2.exp  | 38 +++
  .../gdc.dg/debug/dwarf2/imports/pr98067.d |  3 ++
  gcc/testsuite/gdc.dg/debug/dwarf2/langdw2.d   |  7 
  gcc/testsuite/gdc.dg/debug/dwarf2/langdw3.d   |  6 +++
  gcc/testsuite/gdc.dg/debug/dwarf2/pr98067.d   |  6 +++
  gcc/testsuite/gdc.dg/debug/trivial.d  |  6 +++
  8 files changed, 101 insertions(+)
  create mode 100644 gcc/testsuite/gdc.dg/debug/debug.exp
  create mode 100644 gcc/testsuite/gdc.dg/debug/dwarf2/dwarf2.exp
  create mode 100644 gcc/testsuite/gdc.dg/debug/dwarf2/imports/pr98067.d
  create mode 100644 gcc/testsuite/gdc.dg/debug/dwarf2/langdw2.d
  create mode 100644 gcc/testsuite/gdc.dg/debug/dwarf2/langdw3.d
  create mode 100644 gcc/testsuite/gdc.dg/debug/dwarf2/pr98067.d
  create mode 100644 gcc/testsuite/gdc.dg/debug/trivial.d

diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index 0baa056447c..027f327c1a1 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -26705,6 +26705,13 @@ dwarf2out_imported_module_or_decl_1 (tree decl,
  gen_type_die_for_member (type, decl,
   get_context_die (TYPE_CONTEXT (type)));
}
+ if (TREE_CODE (decl) == CONST_DECL)
+   {
+ /* Individual enumerators of an enum type do not get output here
+(see gen_decl_die), so we cannot call force_decl_die.  */
+ if (!is_fortran () && !is_ada () && !is_dlang ())
+   return;
+   }
  if (TREE_CODE (decl) == NAMELIST_DECL)
at_import_die = gen_namelist_decl (DECL_NAME (decl),
 get_context_die (DECL_CONTEXT (decl)),
diff --git a/gcc/testsuite/gdc.dg/debug/debug.exp 
b/gcc/testsuite/gdc.dg/debug/debug.exp
new file mode 100644
index 000..1607c4d6d44
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/debug/debug.exp
@@ -0,0 +1,28 @@
+# Copyright (C) 2020 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3.  If not see
+# .
+
+# Load support procs.
+load_lib gdc-dg.exp
+
+# Initialize `dg'.
+dg-init
+
+# Main loop.
+gcc-dg-debug-runtest gdc_target_compile trivial.d [list -O -O3] \
+[lsort [glob -nocomplain $srcdir/$subdir/*.d]]
+
+# All done.
+dg-finish
diff --git a/gcc/testsuite/gdc.dg/debug/dwarf2/dwarf2.exp 
b/gcc/testsuite/gdc.dg/debug/dwarf2/dwarf2.exp
new file mode 100644
index 000..11711e197b9
--- /dev/null
+++ 

[PATCH] d: Fix ICE in in force_decl_die, at dwarf2out.c with -gdwarf-2 -gstrict-dwarf [PR98067]

2020-12-15 Thread Iain Buclaw via Gcc-patches
Hi,

This patch fixes an ICE in dwarf2out.c that occurs when compiling a
selective import declaration in D with strict dwarf2 in effect.

Manifest constants in D are represented as CONST_DECLs, which can be
imported from one module to another.  However, when compiling on strict
dwarf2 targets such as *-*darwin10, importing CONST_DECLs cannot be
represented in debug as D did not exist as an AT_language until dwarf3,
and the only available fallback being DW_LANG_C.  As CONST_DECLs are
treated as enumerators in C, and not outputted individually in
gen_decl_die, this causes an internal error in force_decl_die to occur.

To handle this, similar to other places in dwarf2out, if a CONST_DECL is
seen in dwarf2out_imported_module_or_decl_1, then we simply return early
if the language is not one of Ada, D, or Fortran.

The new files and tests added are boilerplate for introducing
gdc.dg/debug and gdc.dg/debug/dwarf2 test directories, as well as two
extra tests - langdw2.d and langdw3.d - that verify that DW_LANG_D is
set except for strict dwarf2.

This has been bootstrapped, and the D testsuite regression tested on
x86_64-linux-gnu/-m32/-mx32.

OK for mainline?

Iain.

---
gcc/ChangeLog:

PR d/98067
* dwarf2out.c (dwarf2out_imported_module_or_decl_1): Handle
  CONST_DECL only if is_fortran, is_ada, or is_dlang.

gcc/testsuite/ChangeLog:

PR d/98067
* gdc.dg/debug/debug.exp: New test.
* gdc.dg/debug/dwarf2/dwarf2.exp: New test.
* gdc.dg/debug/dwarf2/imports/pr98067.d: New test.
* gdc.dg/debug/dwarf2/langdw2.d: New test.
* gdc.dg/debug/dwarf2/langdw3.d: New test.
* gdc.dg/debug/dwarf2/pr98067.d: New test.
* gdc.dg/debug/trivial.d: New test.
---
 gcc/dwarf2out.c   |  7 
 gcc/testsuite/gdc.dg/debug/debug.exp  | 28 ++
 gcc/testsuite/gdc.dg/debug/dwarf2/dwarf2.exp  | 38 +++
 .../gdc.dg/debug/dwarf2/imports/pr98067.d |  3 ++
 gcc/testsuite/gdc.dg/debug/dwarf2/langdw2.d   |  7 
 gcc/testsuite/gdc.dg/debug/dwarf2/langdw3.d   |  6 +++
 gcc/testsuite/gdc.dg/debug/dwarf2/pr98067.d   |  6 +++
 gcc/testsuite/gdc.dg/debug/trivial.d  |  6 +++
 8 files changed, 101 insertions(+)
 create mode 100644 gcc/testsuite/gdc.dg/debug/debug.exp
 create mode 100644 gcc/testsuite/gdc.dg/debug/dwarf2/dwarf2.exp
 create mode 100644 gcc/testsuite/gdc.dg/debug/dwarf2/imports/pr98067.d
 create mode 100644 gcc/testsuite/gdc.dg/debug/dwarf2/langdw2.d
 create mode 100644 gcc/testsuite/gdc.dg/debug/dwarf2/langdw3.d
 create mode 100644 gcc/testsuite/gdc.dg/debug/dwarf2/pr98067.d
 create mode 100644 gcc/testsuite/gdc.dg/debug/trivial.d

diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index 0baa056447c..027f327c1a1 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -26705,6 +26705,13 @@ dwarf2out_imported_module_or_decl_1 (tree decl,
  gen_type_die_for_member (type, decl,
   get_context_die (TYPE_CONTEXT (type)));
}
+ if (TREE_CODE (decl) == CONST_DECL)
+   {
+ /* Individual enumerators of an enum type do not get output here
+(see gen_decl_die), so we cannot call force_decl_die.  */
+ if (!is_fortran () && !is_ada () && !is_dlang ())
+   return;
+   }
  if (TREE_CODE (decl) == NAMELIST_DECL)
at_import_die = gen_namelist_decl (DECL_NAME (decl),
 get_context_die (DECL_CONTEXT (decl)),
diff --git a/gcc/testsuite/gdc.dg/debug/debug.exp 
b/gcc/testsuite/gdc.dg/debug/debug.exp
new file mode 100644
index 000..1607c4d6d44
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/debug/debug.exp
@@ -0,0 +1,28 @@
+# Copyright (C) 2020 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3.  If not see
+# .
+
+# Load support procs.
+load_lib gdc-dg.exp
+
+# Initialize `dg'.
+dg-init
+
+# Main loop.
+gcc-dg-debug-runtest gdc_target_compile trivial.d [list -O -O3] \
+[lsort [glob -nocomplain $srcdir/$subdir/*.d]]
+
+# All done.
+dg-finish
diff --git a/gcc/testsuite/gdc.dg/debug/dwarf2/dwarf2.exp 
b/gcc/testsuite/gdc.dg/debug/dwarf2/dwarf2.exp
new file mode 100644
index 000..11711e197b9
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/debug/dwarf2/dwarf2.exp
@@ -0,0 +1,38 @@
+#   Copyright (C) 2020