<div dir="ltr">Aren't C names sometimes slightly mangled too? For example, on macOS they're prefixed by a _, doesn't that have to be undone there?</div><br><div class="gmail_quote"><div dir="ltr">On Wed, Jan 9, 2019 at 6:58 PM Nick Desaulniers via cfe-commits <<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Author: nickdesaulniers<br>
Date: Wed Jan 9 15:54:55 2019<br>
New Revision: 350776<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=350776&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=350776&view=rev</a><br>
Log:<br>
[Sema] Mark target of __attribute__((alias("target"))) used for C<br>
<br>
Summary:<br>
Prevents -Wunneeded-internal-delcaration warnings when the target has no<br>
other references. This occurs frequently in device drivers in the Linux<br>
kernel.<br>
<br>
Sema would need to invoke the demangler on the target, since in C++ the<br>
target name is mangled:<br>
<br>
int f() { return 42; }<br>
int g() __attribute__((alias("_Z1fv")));<br>
<br>
Sema does not have the ability to demangle names at this time.<br>
<br>
<a href="https://bugs.llvm.org/show_bug.cgi?id=39088" rel="noreferrer" target="_blank">https://bugs.llvm.org/show_bug.cgi?id=39088</a><br>
<a href="https://github.com/ClangBuiltLinux/linux/issues/232" rel="noreferrer" target="_blank">https://github.com/ClangBuiltLinux/linux/issues/232</a><br>
<br>
Reviewers: rsmith, rjmccall<br>
<br>
Reviewed By: rsmith<br>
<br>
Subscribers: erik.pilkington, cfe-commits, pirama, srhines<br>
<br>
Differential Revision: <a href="https://reviews.llvm.org/D54188" rel="noreferrer" target="_blank">https://reviews.llvm.org/D54188</a><br>
<br>
Added:<br>
cfe/trunk/test/Sema/alias-unused.c<br>
Modified:<br>
cfe/trunk/lib/Sema/SemaDeclAttr.cpp<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=350776&r1=350775&r2=350776&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=350776&r1=350775&r2=350776&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Wed Jan 9 15:54:55 2019<br>
@@ -1898,7 +1898,16 @@ static void handleAliasAttr(Sema &S, Dec<br>
}<br>
}<br>
<br>
- // FIXME: check if target symbol exists in current file<br>
+ // Mark target used to prevent unneeded-internal-declaration warnings.<br>
+ if (!S.LangOpts.CPlusPlus) {<br>
+ // FIXME: demangle Str for C++, as the attribute refers to the mangled<br>
+ // linkage name, not the pre-mangled identifier.<br>
+ const DeclarationNameInfo target(&S.Context.Idents.get(Str), AL.getLoc());<br>
+ LookupResult LR(S, target, Sema::LookupOrdinaryName);<br>
+ if (S.LookupQualifiedName(LR, S.getCurLexicalContext()))<br>
+ for (NamedDecl *ND : LR)<br>
+ ND->markUsed(S.Context);<br>
+ }<br>
<br>
D->addAttr(::new (S.Context) AliasAttr(AL.getRange(), S.Context, Str,<br>
AL.getAttributeSpellingListIndex()));<br>
<br>
Added: cfe/trunk/test/Sema/alias-unused.c<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/alias-unused.c?rev=350776&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/alias-unused.c?rev=350776&view=auto</a><br>
==============================================================================<br>
--- cfe/trunk/test/Sema/alias-unused.c (added)<br>
+++ cfe/trunk/test/Sema/alias-unused.c Wed Jan 9 15:54:55 2019<br>
@@ -0,0 +1,7 @@<br>
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -Wunneeded-internal-declaration -x c -verify %s<br>
+// expected-no-diagnostics<br>
+static int f() { return 42; }<br>
+int g() __attribute__((alias("f")));<br>
+<br>
+static int foo [] = { 42, 0xDEAD };<br>
+extern typeof(foo) bar __attribute__((unused, alias("foo")));<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br>
</blockquote></div>