Sema/AST support for attribute used. Patch by Anders Johnson (with small tweaks & test case)!
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64478 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp
index 491579c..29f6cb1 100644
--- a/lib/Sema/SemaDeclAttr.cpp
+++ b/lib/Sema/SemaDeclAttr.cpp
@@ -431,6 +431,27 @@
d->addAttr(new UnusedAttr());
}
+static void HandleUsedAttr(Decl *d, const AttributeList &Attr, Sema &S) {
+ // check the attribute arguments.
+ if (Attr.getNumArgs() != 0) {
+ S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << 0;
+ return;
+ }
+
+ if (const VarDecl *VD = dyn_cast<VarDecl>(d)) {
+ if (VD->hasLocalStorage()) {
+ S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) << "used";
+ return;
+ }
+ } else if (!isFunctionOrMethod(d)) {
+ S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type)
+ << "used" << "variable and function";
+ return;
+ }
+
+ d->addAttr(new UsedAttr());
+}
+
static void HandleConstructorAttr(Decl *d, const AttributeList &Attr, Sema &S) {
// check the attribute arguments.
if (Attr.getNumArgs() != 0 && Attr.getNumArgs() != 1) {
@@ -1357,6 +1378,7 @@
case AttributeList::AT_stdcall: HandleStdCallAttr (D, Attr, S); break;
case AttributeList::AT_unavailable: HandleUnavailableAttr(D, Attr, S); break;
case AttributeList::AT_unused: HandleUnusedAttr (D, Attr, S); break;
+ case AttributeList::AT_used: HandleUsedAttr (D, Attr, S); break;
case AttributeList::AT_vector_size: HandleVectorSizeAttr(D, Attr, S); break;
case AttributeList::AT_visibility: HandleVisibilityAttr(D, Attr, S); break;
case AttributeList::AT_weak: HandleWeakAttr (D, Attr, S); break;