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>
&& DECL_IMPLICIT_INSTANTIATION (decl))
defer_p = 1;
+ /* Defer vague-linkage variables. */
+ if (DECL_INLINE_VAR_P (decl))
+ defer_p = 1;
+
/* If we're not deferring, go ahead and assemble the variable. */
if (!defer_p)
rest_of_decl_compilation (decl, toplev, at_eof);
* implicit instantiations of function templates
- * inline function
+ * inline functions
+
+ * inline variables
* implicit instantiations of static data members of class
templates
|| DECL_DECLARED_INLINE_P (decl));
else
gcc_assert (DECL_IMPLICIT_INSTANTIATION (decl)
+ || DECL_INLINE_VAR_P (decl)
|| DECL_VTABLE_OR_VTT_P (decl)
|| DECL_TINFO_P (decl));
/* Check that a definition of DECL is available in this translation
this entity as undefined in this translation unit. */
import_p = true;
}
- else if (DECL_FUNCTION_MEMBER_P (decl))
+ else if (TREE_CODE (decl) == FUNCTION_DECL && DECL_FUNCTION_MEMBER_P (decl))
{
if (!DECL_DECLARED_INLINE_P (decl))
{
// { dg-final { scan-assembler-times " DW_AT_\[^\n\r]*linkage_name" 7 } }
inline int a;
+int& ar = a;
+
struct S
{
static inline double b = 4.0;
// { dg-final { scan-assembler-times " DW_AT_\[^\n\r]*linkage_name" 7 } }
inline int a;
+int& ar = a;
+
struct S
{
static inline double b = 4.0;
--- /dev/null
+// PR c++/113708
+// { dg-additional-options "-fmodule-header" }
+// { dg-module-cmi {} }
+
+inline int f() { return 42; }
+inline int a = f();
--- /dev/null
+// PR c++/113708
+// { dg-module-do link }
+// { dg-additional-options "-fmodules-ts" }
+
+import "init-7_a.H";
+int main() { a; }