[clang] [clang] Keep explicit visibility on a #pragma weak alias (PR #225354)
Evgenii Kudriashov via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 8 12:52:59 PDT 2026
================
@@ -8805,6 +8805,16 @@ void Sema::DeclApplyPragmaWeak(Scope *S, NamedDecl *ND, const WeakInfo &W) {
if (W.getAlias()) { // clone decl, impersonate __attribute(weak,alias(...))
IdentifierInfo *NDId = ND->getIdentifier();
NamedDecl *NewD = DeclClonePragmaWeak(ND, W.getAlias(), W.getLocation());
+ // The clone is not a redeclaration of any existing declaration of the weak
+ // name, so it does not inherit attributes written on one. Carry over an
+ // explicit visibility, which would otherwise be lost and replaced by the
+ // -fvisibility default. GCC uses the visibility of the weak name's own
+ // declaration here, not that of the aliasee. This lookup has to happen
+ // before the PushOnScopeChains() below, which would make it find NewD.
+ if (NamedDecl *WeakND = LookupSingleName(S, W.getAlias(), W.getLocation(),
----------------
e-kud wrote:
`ND` is a target that we clone for an alias. But we need to take visibility of the previously declared alias.
https://github.com/llvm/llvm-project/pull/225354
More information about the cfe-commits
mailing list