[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


================
@@ -0,0 +1,47 @@
+// RUN: %clang_cc1 -triple %itanium_abi_triple -Wunused -x c -verify %s
+// RUN: %clang_cc1 -triple %itanium_abi_triple -Wunused -x c++ -verify=expected,cxx %s
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+static int f(void) { return 42; }
+int g(void) __attribute__((alias("f")));
+
+static int foo [] = { 42, 0xDEAD }; // cxx-warning{{variable 'foo' is not needed and will not be emitted}}
----------------
MaskRay wrote:

`foo` is mangled. This test just runs -fsyntax-only, not -c. If -c is specified, we will get an error:

```
% fclang -c x.cc
x.cc:2:47: error: alias must point to a defined variable or function
    2 | extern typeof(foo) bar __attribute__((unused, alias("foo")));
      |                                               ^
x.cc:2:47: note: the function or variable specified in an alias must refer to its mangled name
x.cc:2:47: note: function by that name is mangled as "_ZL3foo"
    2 | extern typeof(foo) bar __attribute__((unused, alias("foo")));
      |                                               ^~~~~~~~~~~~
      |                                               alias("_ZL3foo")
```

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


More information about the cfe-commits mailing list