diff options
author | Nick Desaulniers <ndesaulniers@google.com> | 2019-01-09 23:54:55 +0000 |
---|---|---|
committer | Nick Desaulniers <ndesaulniers@google.com> | 2019-01-09 23:54:55 +0000 |
commit | 9b9fe4166f521eb8b1c3da16bb30a02be08398fa (patch) | |
tree | e5a9b1db6e72a89e1be484ebf62d14e4d349910b /clang/lib/Sema/SemaDeclAttr.cpp | |
parent | d4e7a0d83ca785925a4f8c82d114377f5b156bbf (diff) | |
download | bcm5719-llvm-9b9fe4166f521eb8b1c3da16bb30a02be08398fa.tar.gz bcm5719-llvm-9b9fe4166f521eb8b1c3da16bb30a02be08398fa.zip |
[Sema] Mark target of __attribute__((alias("target"))) used for C
Summary:
Prevents -Wunneeded-internal-delcaration warnings when the target has no
other references. This occurs frequently in device drivers in the Linux
kernel.
Sema would need to invoke the demangler on the target, since in C++ the
target name is mangled:
int f() { return 42; }
int g() __attribute__((alias("_Z1fv")));
Sema does not have the ability to demangle names at this time.
https://bugs.llvm.org/show_bug.cgi?id=39088
https://github.com/ClangBuiltLinux/linux/issues/232
Reviewers: rsmith, rjmccall
Reviewed By: rsmith
Subscribers: erik.pilkington, cfe-commits, pirama, srhines
Differential Revision: https://reviews.llvm.org/D54188
llvm-svn: 350776
Diffstat (limited to 'clang/lib/Sema/SemaDeclAttr.cpp')
-rw-r--r-- | clang/lib/Sema/SemaDeclAttr.cpp | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index 864c930136e..b5859d1fb7b 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -1898,7 +1898,16 @@ static void handleAliasAttr(Sema &S, Decl *D, const ParsedAttr &AL) { } } - // FIXME: check if target symbol exists in current file + // Mark target used to prevent unneeded-internal-declaration warnings. + if (!S.LangOpts.CPlusPlus) { + // FIXME: demangle Str for C++, as the attribute refers to the mangled + // linkage name, not the pre-mangled identifier. + const DeclarationNameInfo target(&S.Context.Idents.get(Str), AL.getLoc()); + LookupResult LR(S, target, Sema::LookupOrdinaryName); + if (S.LookupQualifiedName(LR, S.getCurLexicalContext())) + for (NamedDecl *ND : LR) + ND->markUsed(S.Context); + } D->addAttr(::new (S.Context) AliasAttr(AL.getRange(), S.Context, Str, AL.getAttributeSpellingListIndex())); |