public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-9201] c++: Revert deferring emission of inline variables [PR114013]
@ 2024-02-28  0:26 Nathaniel Shead
  0 siblings, 0 replies; only message in thread
From: Nathaniel Shead @ 2024-02-28  0:26 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:615b62aada6cc42759e5c43e196dab6c524925d6

commit r14-9201-g615b62aada6cc42759e5c43e196dab6c524925d6
Author: Nathaniel Shead <nathanieloshead@gmail.com>
Date:   Wed Feb 28 11:20:53 2024 +1100

    c++: Revert deferring emission of inline variables [PR114013]
    
    This is a (partial) reversion of r14-8987-gdd9d14f7d53 to return to
    eagerly emitting inline variables to the middle-end when they are
    declared. 'import_export_decl' will still continue to accept them, as
    allowing this is a pure extension and doesn't seem to cause issues with
    modules, but otherwise deferring the emission of inline variables
    appears to cause issues on some targets and prevents some code using
    inline variable templates from correctly linking.
    
    There might be a more targetted way to support this, but due to the
    complexity of handling linkage and emission I'd prefer to wait till
    GCC 15 to explore our options.
    
            PR c++/113970
            PR c++/114013
    
    gcc/cp/ChangeLog:
    
            * decl.cc (make_rtl_for_nonlocal_decl): Don't defer inline
            variables.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/cpp1z/inline-var10.C: New test.
    
    Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>

Diff:
---
 gcc/cp/decl.cc                            |  4 ----
 gcc/testsuite/g++.dg/cpp1z/inline-var10.C | 33 +++++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+), 4 deletions(-)

diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index e47f694e4e5..d19d09adde4 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -7954,10 +7954,6 @@ make_rtl_for_nonlocal_decl (tree decl, tree init, const char* asmspec)
       && 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);
diff --git a/gcc/testsuite/g++.dg/cpp1z/inline-var10.C b/gcc/testsuite/g++.dg/cpp1z/inline-var10.C
new file mode 100644
index 00000000000..8a198556778
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1z/inline-var10.C
@@ -0,0 +1,33 @@
+// PR c++/114013
+// { dg-do link { target c++17 } }
+
+struct S { int a, b; };
+
+template <int N>
+constexpr struct S var[8] = {};
+
+template <>
+constexpr inline struct S var<6>[8] = {
+  { 1, 1 }, { 2, 0 }, { 3, 1 }, { 4, 0 },
+  { 5, 1 }, { 6, 0 }, { 7, 1 }, { 8, 0 }
+};
+
+[[gnu::noipa]] void
+foo (S)
+{
+}
+
+template <int N>
+void
+bar (int x)
+{
+  foo (var<N>[x]);
+}
+
+volatile int x;
+
+int
+main ()
+{
+  bar <6> (x);
+}

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-02-28  0:26 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-28  0:26 [gcc r14-9201] c++: Revert deferring emission of inline variables [PR114013] Nathaniel Shead

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).