Bootstrapped and regtested on x86_64-pc-linux-gnu, OK for trunk? -- >8 --
The TYPE_DECL_SUPPRESS_DEBUG and DECL_EXTERNAL flags use the same underlying bit. This is causing confusion when attempting to determine the interface for a streamed-in class type, since the modules code currently assumes that all DECL_EXTERNAL types are extern templates. However, when -g is specified then TYPE_DECL_SUPPRESS_DEBUG (and hence DECL_EXTERNAL) is marked on various other kinds of declarations, such as vtables, which causes them to never be emitted. This patch constrains the checks for DECL_EXTERNAL for this to only consider template instantiations, thus avoiding the issue. PR c++/102607 PR c++/112820 gcc/cp/ChangeLog: * module.cc (trees_in::read_class_def): Only set interface for template instantiations. gcc/testsuite/ChangeLog: * g++.dg/modules/debug-2_a.C: New test. * g++.dg/modules/debug-2_b.C: New test. * g++.dg/modules/debug-2_c.C: New test. * g++.dg/modules/debug-3_a.C: New test. * g++.dg/modules/debug-3_b.C: New test. Signed-off-by: Nathaniel Shead <nathanielosh...@gmail.com> --- gcc/cp/module.cc | 4 +++- gcc/testsuite/g++.dg/modules/debug-2_a.C | 9 +++++++++ gcc/testsuite/g++.dg/modules/debug-2_b.C | 8 ++++++++ gcc/testsuite/g++.dg/modules/debug-2_c.C | 9 +++++++++ gcc/testsuite/g++.dg/modules/debug-3_a.C | 8 ++++++++ gcc/testsuite/g++.dg/modules/debug-3_b.C | 9 +++++++++ 6 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/modules/debug-2_a.C create mode 100644 gcc/testsuite/g++.dg/modules/debug-2_b.C create mode 100644 gcc/testsuite/g++.dg/modules/debug-2_c.C create mode 100644 gcc/testsuite/g++.dg/modules/debug-3_a.C create mode 100644 gcc/testsuite/g++.dg/modules/debug-3_b.C diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc index 33fcf396875..257f39421d0 100644 --- a/gcc/cp/module.cc +++ b/gcc/cp/module.cc @@ -12041,7 +12041,9 @@ trees_in::read_class_def (tree defn, tree maybe_template) bool installing = maybe_dup && !TYPE_SIZE (type); if (installing) { - if (DECL_EXTERNAL (defn) && TYPE_LANG_SPECIFIC (type)) + if (DECL_EXTERNAL (defn) + && TYPE_LANG_SPECIFIC (type) + && CLASSTYPE_TEMPLATE_INSTANTIATION (type)) { /* We don't deal with not-really-extern, because, for a module you want the import to be the interface, and for a diff --git a/gcc/testsuite/g++.dg/modules/debug-2_a.C b/gcc/testsuite/g++.dg/modules/debug-2_a.C new file mode 100644 index 00000000000..eed0905542b --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/debug-2_a.C @@ -0,0 +1,9 @@ +// PR c++/112820 +// { dg-additional-options "-fmodules-ts -g" } +// { dg-module-cmi io } + +export module io; + +export struct error { + virtual const char* what() const noexcept; +}; diff --git a/gcc/testsuite/g++.dg/modules/debug-2_b.C b/gcc/testsuite/g++.dg/modules/debug-2_b.C new file mode 100644 index 00000000000..fc9afbc02e0 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/debug-2_b.C @@ -0,0 +1,8 @@ +// PR c++/112820 +// { dg-additional-options "-fmodules-ts -g" } + +module io; + +const char* error::what() const noexcept { + return "bla"; +} diff --git a/gcc/testsuite/g++.dg/modules/debug-2_c.C b/gcc/testsuite/g++.dg/modules/debug-2_c.C new file mode 100644 index 00000000000..37117f69dcd --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/debug-2_c.C @@ -0,0 +1,9 @@ +// PR c++/112820 +// { dg-module-do link } +// { dg-additional-options "-fmodules-ts -g" } + +import io; + +int main() { + error{}; +} diff --git a/gcc/testsuite/g++.dg/modules/debug-3_a.C b/gcc/testsuite/g++.dg/modules/debug-3_a.C new file mode 100644 index 00000000000..9e33d8260fd --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/debug-3_a.C @@ -0,0 +1,8 @@ +// PR c++/102607 +// { dg-additional-options "-fmodules-ts -g" } +// { dg-module-cmi mod } + +export module mod; +export struct B { + virtual ~B() = default; +}; diff --git a/gcc/testsuite/g++.dg/modules/debug-3_b.C b/gcc/testsuite/g++.dg/modules/debug-3_b.C new file mode 100644 index 00000000000..03c78b71b5d --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/debug-3_b.C @@ -0,0 +1,9 @@ +// PR c++/102607 +// { dg-module-do link } +// { dg-additional-options "-fmodules-ts -g" } + +import mod; +int main() { + struct D : B {}; + (void)D{}; +} -- 2.42.0