[clang] [Sema] Mark alias/ifunc targets used and consider mangled names (PR #87130)

Fangrui Song via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 4 15:45:52 PDT 2024


================
@@ -1980,6 +1981,23 @@ 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. For C++, we look up the demangled name
+// ignoring parameters. This should handle the majority of use cases while
+// leaveing false positives for namespace scope names and false negatives in
+// the presence of overloads.
+static void markUsedForAliasOrIfunc(Sema &S, Decl *D, const ParsedAttr &AL,
+                                    StringRef Str) {
+  char *Demangled = llvm::itaniumDemangle(Str, /*ParseParams=*/false);
----------------
MaskRay wrote:

I added a `S.getASTContext().getCXXABIKind() != TargetCXXABI::Microsoft` check.

Note: while `alias` works for Windows, it is only checked in tests CodeGenCXX/visibility-dllstorageclass.cpp/CodeGen/debug-info-alias-pointer.c . I don't consider it used publicly.

I've also updated the description to say that our behavior is different from GCC for `extern "C" { static void f(); }`. So, the C++ handling is best-effort.

https://github.com/llvm/llvm-project/pull/87130


More information about the cfe-commits mailing list