Open Quuxplusone opened 9 years ago
Bugzilla Link | PR22602 |
Status | NEW |
Importance | P normal |
Reported by | torne@google.com |
Reported on | 2015-02-16 08:09:25 -0800 |
Last modified on | 2015-02-23 12:50:40 -0800 |
Version | 3.5 |
Hardware | PC Linux |
CC | llvm-bugs@lists.llvm.org, rafael@espindo.la, richard-llvm@metafoo.co.uk |
Fixed by commit(s) | |
Attachments | |
Blocks | |
Blocked by | |
See also |
Actually, this is not just a bogus warning; it fails to compile entirely if you
compile it as C++:
alias.cc:
extern "C" {
static void foo() {}
void bar() __attribute__((alias("foo")))
Retitling, as this is not just a bogus warning; it fails to compile entirely if
you compile it as C++:
alias.cc:
extern "C" {
static void foo() {}
void bar() __attribute__((alias("foo")));
}
$ clang++ -c alias.cc -Wunused-function
alias.cc:5:13: warning: unused function 'foo' [-Wunused-function]
static void foo() {}
^
alias.cc:7:27: error: alias must point to a defined variable or function
void bar() __attribute__((alias("foo")));
^
1 warning and 1 error generated.
It looks like this is due to a combination of extern "C" not applying to static
functions (and thus foo is having its name mangled), and alias() taking the
mangled symbol name as a parameter. Aliasing it to "_Z3foov" makes it compile
successfully, though the warning about foo being unused is still incorrectly
generated.
This same source works correctly in gcc.
gcc does not mangle the name of the extern "C" static function, which is presumably why it works there.
Yes, I believe it is unfortunate we implemented the language linkage rules as they are worded on the standard and not how they are used in practice.
This particular case might be solvable by creating the (foo -> mangled name) alias earlier.
Yeah, I am aware that the standard doesn't necessarily match what gcc is doing here, but since I believe attribute((alias)) is a gcc extension, cases that work in gcc should probably also work in clang for compatibility with existing code. :)
(In reply to comment #4)
> This particular case might be solvable by creating the (foo -> mangled name)
> alias earlier.
I think this is the right solution. There's also a fairly straightforward
workaround for the build failure:
static void foo() __asm__("foo");
static void foo() {}
void bar() __attribute__((alias("foo")));
This does not help with the warning, though.