Bootstrapped and regtested (just modules.exp so far) on x86_64-pc-linux-gnu, OK for trunk if full regtest succeeds?
-- >8 -- Currently inline vars imported from modules aren't correctly finalised, which means that import_export_decl gets called at the end of TU processing despite not being meant to for these kinds of declarations. This patch takes the logic from 'make_rtl_for_nonlocal_decl' to determine when to perform rest of decl compilation on these decls. However other parts of this function (asmspec handling) are not yet covered. PR c++/113708 gcc/cp/ChangeLog: * module.cc (trees_in::read_var_def): Perform rest of decl compilation on non-local statics. gcc/testsuite/ChangeLog: * g++.dg/modules/init-7_a.H: New test. * g++.dg/modules/init-7_b.C: New test. Signed-off-by: Nathaniel Shead <nathanielosh...@gmail.com> --- gcc/cp/module.cc | 12 +++++++++++- gcc/testsuite/g++.dg/modules/init-7_a.H | 6 ++++++ gcc/testsuite/g++.dg/modules/init-7_b.C | 6 ++++++ 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/modules/init-7_a.H create mode 100644 gcc/testsuite/g++.dg/modules/init-7_b.C diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc index 560d8f3b614..49a3421e6cc 100644 --- a/gcc/cp/module.cc +++ b/gcc/cp/module.cc @@ -11809,6 +11809,7 @@ trees_in::read_var_def (tree decl, tree maybe_template) { if (DECL_EXTERNAL (decl)) DECL_NOT_REALLY_EXTERN (decl) = true; + DECL_INITIAL (decl) = init; if (VAR_P (decl)) { DECL_INITIALIZED_P (decl) = true; @@ -11819,8 +11820,17 @@ trees_in::read_var_def (tree decl, tree maybe_template) && !DECL_VTABLE_OR_VTT_P (decl) && !DECL_TEMPLATE_INFO (decl))) note_vague_linkage_variable (decl); + + /* Emit RTL as needed, as with make_rtl_for_nonlocal_decl. */ + // FIXME: Handle asmspec? + if ((!DECL_FUNCTION_SCOPE_P (decl) + || (TREE_STATIC (decl) && var_in_maybe_constexpr_fn (decl))) + && !DECL_VIRTUAL_P (decl) + && (!DECL_TEMPLATE_INFO (decl) + || DECL_EXPLICIT_INSTANTIATION (decl))) + rest_of_decl_compilation (decl, !DECL_FUNCTION_SCOPE_P (decl), + /*at_end=*/0); } - DECL_INITIAL (decl) = init; if (!dyn_init) ; else if (CP_DECL_THREAD_LOCAL_P (decl)) diff --git a/gcc/testsuite/g++.dg/modules/init-7_a.H b/gcc/testsuite/g++.dg/modules/init-7_a.H new file mode 100644 index 00000000000..7a0bb721c30 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/init-7_a.H @@ -0,0 +1,6 @@ +// PR c++/113708 +// { dg-additional-options "-fmodule-header" } +// { dg-module-cmi {} } + +inline int f() { return 42; } +inline int a = f(); diff --git a/gcc/testsuite/g++.dg/modules/init-7_b.C b/gcc/testsuite/g++.dg/modules/init-7_b.C new file mode 100644 index 00000000000..58bb0620ca5 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/init-7_b.C @@ -0,0 +1,6 @@ +// PR c++/113708 +// { dg-module-do link } +// { dg-additional-options "-fmodules-ts" } + +import "init-7_a.H"; +int main() { a; } -- 2.43.0