public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-3163] c++ modules: static var in inline function [PR104433]
@ 2022-10-07 13:33 Patrick Palka
0 siblings, 0 replies; only message in thread
From: Patrick Palka @ 2022-10-07 13:33 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:edbb2551d156d69a2e337dcd8daa69f2680d57ea
commit r13-3163-gedbb2551d156d69a2e337dcd8daa69f2680d57ea
Author: Patrick Palka <ppalka@redhat.com>
Date: Fri Oct 7 09:32:45 2022 -0400
c++ modules: static var in inline function [PR104433]
The below testcase fails to link with the error
undefined reference to `f()::y'
ultimately because during stream out for the static VAR_DECL y we
override DECL_EXTERNAL to true, which later during IPA confuses
symbol_table::remove_unreachable_nodes into thinking it's safe
to not emit the symbol.
The streaming code here already avoids overriding DECL_EXTERNAL for
inline vars and functions, so it seems natural to extend this to
static vars from an inline function.
PR c++/104433
gcc/cp/ChangeLog:
* module.cc (trees_out::core_bools): Don't override
DECL_EXTERNAL to true for static variables from an inline
function.
gcc/testsuite/ChangeLog:
* g++.dg/modules/static-2_a.H: New test.
* g++.dg/modules/static-2_b.C: New test.
Diff:
---
gcc/cp/module.cc | 3 +++
gcc/testsuite/g++.dg/modules/static-2_a.H | 8 ++++++++
gcc/testsuite/g++.dg/modules/static-2_b.C | 9 +++++++++
3 files changed, 20 insertions(+)
diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc
index c5eff219909..cb1929bc5d5 100644
--- a/gcc/cp/module.cc
+++ b/gcc/cp/module.cc
@@ -5411,6 +5411,9 @@ trees_out::core_bools (tree t)
case VAR_DECL:
if (TREE_PUBLIC (t)
+ && !(TREE_STATIC (t)
+ && DECL_FUNCTION_SCOPE_P (t)
+ && DECL_DECLARED_INLINE_P (DECL_CONTEXT (t)))
&& !DECL_VAR_DECLARED_INLINE_P (t))
is_external = true;
break;
diff --git a/gcc/testsuite/g++.dg/modules/static-2_a.H b/gcc/testsuite/g++.dg/modules/static-2_a.H
new file mode 100644
index 00000000000..65c7619616b
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/static-2_a.H
@@ -0,0 +1,8 @@
+// PR c++/104433
+// { dg-additional-options -fmodule-header }
+// { dg-module-cmi {} }
+
+inline int* f() {
+ static int y;
+ return &y;
+}
diff --git a/gcc/testsuite/g++.dg/modules/static-2_b.C b/gcc/testsuite/g++.dg/modules/static-2_b.C
new file mode 100644
index 00000000000..bfd35b0fc15
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/static-2_b.C
@@ -0,0 +1,9 @@
+// PR c++/104433
+// { dg-additional-options -fmodules-ts }
+// { dg-do link }
+
+import "static-2_a.H";
+
+int main() {
+ f();
+}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-10-07 13:33 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-07 13:33 [gcc r13-3163] c++ modules: static var in inline function [PR104433] Patrick Palka
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).