[clang] [Sema] Mark alias/ifunc targets used and consider mangled names (PR #87130)
Fangrui Song via cfe-commits
cfe-commits at lists.llvm.org
Fri Apr 5 10:30:04 PDT 2024
================
@@ -1980,6 +1981,36 @@ static void handleWeakRefAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
D->addAttr(::new (S.Context) WeakRefAttr(S.Context, AL));
}
+// Mark alias/ifunc target as used. Due to name mangling, we look up the
+// demangled name ignoring parameters. This should handle the majority of use
+// cases while leaving namespace scope names unmarked.
+static void markUsedForAliasOrIfunc(Sema &S, Decl *D, const ParsedAttr &AL,
+ StringRef Str) {
+ char *Demangled = nullptr;
+ if (S.getASTContext().getCXXABIKind() != TargetCXXABI::Microsoft)
+ Demangled = llvm::itaniumDemangle(Str, /*ParseParams=*/false);
+ std::unique_ptr<MangleContext> MC(S.Context.createMangleContext());
+ SmallString<256> Name;
+
+ const DeclarationNameInfo Target(
+ &S.Context.Idents.get(Demangled ? Demangled : Str), AL.getLoc());
+ LookupResult LR(S, Target, Sema::LookupOrdinaryName);
+ if (S.LookupName(LR, S.TUScope)) {
+ for (NamedDecl *ND : LR) {
+ if (MC->shouldMangleDeclName(ND)) {
+ llvm::raw_svector_ostream Out(Name);
+ Name.clear();
+ MC->mangleName(GlobalDecl(ND), Out);
+ } else {
+ Name = ND->getIdentifier()->getName();
----------------
MaskRay wrote:
The `if (Name == Str)` comparison below is to mark the correct overload while leaving others unmarked.
The previous code just doesn't bother with overload checking, leading to overly marked functions when extended to C++ / C `__attribute__((overload))`
https://github.com/llvm/llvm-project/pull/87130
More information about the cfe-commits
mailing list