]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: Update decl_linkage for C++11
authorNathaniel Shead <nathanieloshead@gmail.com>
Mon, 19 Aug 2024 06:38:41 +0000 (16:38 +1000)
committerNathaniel Shead <nathanieloshead@gmail.com>
Fri, 27 Sep 2024 03:49:23 +0000 (13:49 +1000)
commitaf4471cb422a867f1877c7c08bb63fa75a8888fe
tree6b4ede63935b0d3ead4083163a26e0a4b6ce460f
parent3471ae37200bd8154084334204a6f72a5bbae974
c++: Update decl_linkage for C++11

Currently modules code uses a variety of ad-hoc methods to attempt to
determine whether an entity has internal linkage, which leads to
inconsistencies and some correctness issues as different edge cases are
neglected.  While investigating this I discovered 'decl_linkage', but it
doesn't seem to have been updated to account for the C++11 clarification
that all entities declared in an anonymous namespace are internal.

I'm not convinced that even in C++98 it was intended that e.g. types in
anonymous namespaces should be external, but some tests in the testsuite
rely on this, so for compatibility I restricted those modifications to
C++11 and later.

This should have relatively minimal impact as not much seems to actually
rely on decl_linkage, but does change the mangling of symbols in
anonymous namespaces slightly.  Previously, we had

  namespace {
    int x;  // mangled as '_ZN12_GLOBAL__N_11xE'
    static int y;  // mangled as '_ZN12_GLOBAL__N_1L1yE'
  }

but with this patch the x is now mangled like y (with the extra 'L').
For contrast, Clang currently mangles neither x nor y with the 'L'.
Since this only affects internal-linkage entities I don't believe this
should break ABI in any observable fashion.

gcc/cp/ChangeLog:

* name-lookup.cc (do_namespace_alias): Propagate TREE_PUBLIC for
namespace aliases.
* tree.cc (decl_linkage): Update rules for C++11.

gcc/testsuite/ChangeLog:

* g++.dg/modules/mod-sym-4.C: Update test to account for
non-static internal-linkage variables new mangling.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
Reviewed-by: Jason Merrill <jason@redhat.com>
gcc/cp/name-lookup.cc
gcc/cp/tree.cc
gcc/testsuite/g++.dg/modules/mod-sym-4.C