[PATCH] D54188: [Sema] Mark target of __attribute__((alias("target"))) used for C

Nick Desaulniers via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 9 15:58:45 PST 2019


This revision was automatically updated to reflect the committed changes.
nickdesaulniers marked an inline comment as done.
Closed by commit rL350776: [Sema] Mark target of __attribute__((alias("target"))) used for C (authored by nickdesaulniers, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D54188/new/

https://reviews.llvm.org/D54188

Files:
  cfe/trunk/lib/Sema/SemaDeclAttr.cpp
  cfe/trunk/test/Sema/alias-unused.c


Index: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
===================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp
@@ -1898,7 +1898,16 @@
     }
   }
 
-  // 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()));
Index: cfe/trunk/test/Sema/alias-unused.c
===================================================================
--- cfe/trunk/test/Sema/alias-unused.c
+++ cfe/trunk/test/Sema/alias-unused.c
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -Wunneeded-internal-declaration -x c -verify %s
+// expected-no-diagnostics
+static int f() { return 42; }
+int g() __attribute__((alias("f")));
+
+static int foo [] = { 42, 0xDEAD };
+extern typeof(foo) bar __attribute__((unused, alias("foo")));


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D54188.180954.patch
Type: text/x-patch
Size: 1446 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190109/05ed434c/attachment.bin>


More information about the cfe-commits mailing list