diff options
author | Jason Merrill <jason@redhat.com> | 2024-11-26 07:50:49 -0500 |
---|---|---|
committer | Jason Merrill <jason@redhat.com> | 2024-11-26 23:53:37 -0500 |
commit | 2fd9aef1db1a4260ee823bc3a3d4cfc22e95c543 (patch) | |
tree | 9d4b734f52820cc1ffc28b57a84726c7b7677c4d /gcc | |
parent | d89d033e2731a53bf71a0db5259380504357d2f5 (diff) | |
download | gcc-2fd9aef1db1a4260ee823bc3a3d4cfc22e95c543.zip gcc-2fd9aef1db1a4260ee823bc3a3d4cfc22e95c543.tar.gz gcc-2fd9aef1db1a4260ee823bc3a3d4cfc22e95c543.tar.bz2 |
c++: modules and local static
Here we weren't emitting the guard variable for 'a' when we emitted 'afn'
in the importer, because we only treated inline variables as needing that.
Fixed by generalizing to vague_linkage_p.
But we need to specifically exempt vtables, because the rest of the module
code handles them specially and expects them to be DECL_EXTERNAL.
gcc/cp/ChangeLog:
* module.cc (trees_out::core_bools): Check vague_linkage_p.
(has_definition): Likewise.
gcc/testsuite/ChangeLog:
* g++.dg/modules/static-3_b.C: New test.
* g++.dg/modules/static-3_a.H: New test.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cp/module.cc | 23 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/modules/static-3_a.H | 13 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/modules/static-3_b.C | 8 |
3 files changed, 33 insertions, 11 deletions
diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc index e595508..ddede0f 100644 --- a/gcc/cp/module.cc +++ b/gcc/cp/module.cc @@ -5521,16 +5521,13 @@ trees_out::core_bools (tree t, bits_out& bits) 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)) + && DECL_VTABLE_OR_VTT_P (t)) + /* We handle vtable linkage specially. */ is_external = true; - break; - + gcc_fallthrough (); case FUNCTION_DECL: if (TREE_PUBLIC (t) - && !DECL_DECLARED_INLINE_P (t)) + && !vague_linkage_p (t)) is_external = true; break; } @@ -11950,11 +11947,15 @@ has_definition (tree decl) since there's no TU to emit them in otherwise. */ return true; - if (!decl_maybe_constant_var_p (decl) - && !DECL_INLINE_VAR_P (decl)) - return false; + if (decl_maybe_constant_var_p (decl)) + /* We might need its constant value. */ + return true; - return true; + if (vague_linkage_p (decl)) + /* These are emitted as needed. */ + return true; + + return false; } break; diff --git a/gcc/testsuite/g++.dg/modules/static-3_a.H b/gcc/testsuite/g++.dg/modules/static-3_a.H new file mode 100644 index 0000000..e5a014e --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/static-3_a.H @@ -0,0 +1,13 @@ +// { dg-additional-options -fmodules } +// { dg-module-do link } + +inline int i; + +struct A { + A() { ++i; } +}; + +inline A& afn() { + static A a; + return a; +} diff --git a/gcc/testsuite/g++.dg/modules/static-3_b.C b/gcc/testsuite/g++.dg/modules/static-3_b.C new file mode 100644 index 0000000..70180f8 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/static-3_b.C @@ -0,0 +1,8 @@ +// { dg-additional-options -fmodules } + +import "static-3_a.H"; + +int main() +{ + afn(); +} |