c++: Defer emitting inline variables [PR113708]
commitdd9d14f7d53de07beff06004922a2bff20ece671
authorNathaniel Shead <nathanieloshead@gmail.com>
Wed, 14 Feb 2024 01:26:03 +0000 (14 12:26 +1100)
committerNathaniel Shead <nathanieloshead@gmail.com>
Wed, 14 Feb 2024 19:07:50 +0000 (15 06:07 +1100)
tree367f8f5607131ba80fe934aaf49d57ae1bdc881e
parent2b5e0c11a40865b33bc4424b3c344176eaecf104
c++: Defer emitting inline variables [PR113708]

Inline variables are vague-linkage, and may or may not need to be
emitted in any TU that they are part of, similarly to e.g. template
instantiations.

Currently 'import_export_decl' assumes that inline variables have
already been emitted when it comes to end-of-TU processing, and so
crashes when importing non-trivially-initialised variables from a
module, as they have not yet been finalised.

This patch fixes this by ensuring that inline variables are always
deferred till end-of-TU processing, unifying the behaviour for module
and non-module code.

PR c++/113708

gcc/cp/ChangeLog:

* decl.cc (make_rtl_for_nonlocal_decl): Defer inline variables.
* decl2.cc (import_export_decl): Support inline variables.

gcc/testsuite/ChangeLog:

* g++.dg/debug/dwarf2/inline-var-1.C: Reference 'a' to ensure it
is emitted.
* g++.dg/debug/dwarf2/inline-var-3.C: Likewise.
* g++.dg/modules/init-7_a.H: New test.
* g++.dg/modules/init-7_b.C: New test.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
gcc/cp/decl.cc
gcc/cp/decl2.cc
gcc/testsuite/g++.dg/debug/dwarf2/inline-var-1.C
gcc/testsuite/g++.dg/debug/dwarf2/inline-var-3.C
gcc/testsuite/g++.dg/modules/init-7_a.H [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/init-7_b.C [new file with mode: 0644]