[clang] [Sema] Mark alias/ifunc targets used and consider mangled names (PR #87130)
Nick Desaulniers via cfe-commits
cfe-commits at lists.llvm.org
Mon Apr 1 08:50:57 PDT 2024
================
@@ -1,7 +1,35 @@
-// RUN: %clang_cc1 -triple x86_64-linux-gnu -Wunneeded-internal-declaration -x c -verify %s
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -Wunused -x c -verify %s
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -Wunused -x c++ -verify %s
+
+#ifdef __cplusplus
+extern "C" {
+#else
// expected-no-diagnostics
+#endif
static int f(void) { return 42; }
int g(void) __attribute__((alias("f")));
static int foo [] = { 42, 0xDEAD };
extern typeof(foo) bar __attribute__((unused, alias("foo")));
+
+static int (*resolver(void))(void) { return f; }
+int ifunc(void) __attribute__((ifunc("resolver")));
+
+#ifdef __cplusplus
+}
+
+/// We demangle alias/ifunc target and mark all found functions as used.
+static int f1(int) { return 42; }
----------------
nickdesaulniers wrote:
This behavior differs from GCC; https://godbolt.org/z/fz8a153qY. Even which function is retained for codegen purposes is different. That's sure to lead to compatibility issues. So beyond this diagnostic related change, it looks like we may have a pre-existing codegen bug here, too.
---
Given an alias to `_ZL2f1v`, that demangles to `f1()`. So we _should_ diagnose that `f1(int)` is unused (`_ZL2f1i`).
Same for `_ZL9resolver1v` below.
You allude to fixing false positives in lieu of adding false negatives, but I would prefer to not have to compromise like that.
https://github.com/llvm/llvm-project/pull/87130
More information about the cfe-commits
mailing list