summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@mac.com>2009-02-13 06:46:13 +0000
committerAnders Carlsson <andersca@mac.com>2009-02-13 06:46:13 +0000
commit76187b4d689a6ce601f2055b3dad5be6a4ab1012 (patch)
tree0025efa593eadd034d149f8d63406f13f62bff3e
parentf71a473720baf27023577c478d0b44d9b1997616 (diff)
downloadbcm5719-llvm-76187b4d689a6ce601f2055b3dad5be6a4ab1012.tar.gz
bcm5719-llvm-76187b4d689a6ce601f2055b3dad5be6a4ab1012.zip
Add sema support for the nodebug attribute.
llvm-svn: 64441
-rw-r--r--clang/include/clang/AST/Attr.h13
-rw-r--r--clang/include/clang/Parse/AttributeList.h1
-rw-r--r--clang/lib/Parse/AttributeList.cpp1
-rw-r--r--clang/lib/Sema/SemaDeclAttr.cpp19
-rw-r--r--clang/test/Sema/attr-nodebug.c8
5 files changed, 40 insertions, 2 deletions
diff --git a/clang/include/clang/AST/Attr.h b/clang/include/clang/AST/Attr.h
index 60b84f43c3a..c951ba712e8 100644
--- a/clang/include/clang/AST/Attr.h
+++ b/clang/include/clang/AST/Attr.h
@@ -55,7 +55,8 @@ public:
Blocks,
Const,
Pure,
- Cleanup
+ Cleanup,
+ Nodebug
};
private:
@@ -493,6 +494,16 @@ public:
static bool classof(const CleanupAttr *A) { return true; }
};
+class NodebugAttr : public Attr {
+public:
+ NodebugAttr() : Attr(Nodebug) {}
+
+ // Implement isa/cast/dyncast/etc.
+
+ static bool classof(const Attr *A) { return A->getKind() == Nodebug; }
+ static bool classof(const DeprecatedAttr *A) { return true; }
+};
+
} // end namespace clang
#endif
diff --git a/clang/include/clang/Parse/AttributeList.h b/clang/include/clang/Parse/AttributeList.h
index 56f30d38f43..e5384ddbcd1 100644
--- a/clang/include/clang/Parse/AttributeList.h
+++ b/clang/include/clang/Parse/AttributeList.h
@@ -80,6 +80,7 @@ public:
AT_const,
AT_nsobject,
AT_cleanup,
+ AT_nodebug,
UnknownAttribute
};
diff --git a/clang/lib/Parse/AttributeList.cpp b/clang/lib/Parse/AttributeList.cpp
index c540da74f15..71712b646f8 100644
--- a/clang/lib/Parse/AttributeList.cpp
+++ b/clang/lib/Parse/AttributeList.cpp
@@ -70,6 +70,7 @@ AttributeList::Kind AttributeList::getKind(const IdentifierInfo *Name) {
case 7:
if (!memcmp(Str, "aligned", 7)) return AT_aligned;
if (!memcmp(Str, "cleanup", 7)) return AT_cleanup;
+ if (!memcmp(Str, "nodebug", 7)) return AT_nodebug;
if (!memcmp(Str, "nonnull", 7)) return AT_nonnull;
if (!memcmp(Str, "nothrow", 7)) return AT_nothrow;
if (!memcmp(Str, "objc_gc", 7)) return AT_objc_gc;
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index c08634c7889..4bca3d9fc76 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -1304,6 +1304,22 @@ static void HandleModeAttr(Decl *D, const AttributeList &Attr, Sema &S) {
cast<ValueDecl>(D)->setType(NewTy);
}
+static void HandleNodebugAttr(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;
+ }
+ FunctionDecl *Fn = dyn_cast<FunctionDecl>(d);
+ if (!Fn) {
+ S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type)
+ << "nodebug" << "function";
+ return;
+ }
+
+ d->addAttr(new NodebugAttr());
+}
+
//===----------------------------------------------------------------------===//
// Top Level Sema Entry Points
//===----------------------------------------------------------------------===//
@@ -1355,10 +1371,11 @@ static void ProcessDeclAttribute(Decl *D, const AttributeList &Attr, Sema &S) {
case AttributeList::AT_const: HandleConstAttr (D, Attr, S); break;
case AttributeList::AT_pure: HandlePureAttr (D, Attr, S); break;
case AttributeList::AT_cleanup: HandleCleanupAttr (D, Attr, S); break;
+ case AttributeList::AT_nodebug: HandleNodebugAttr (D, Attr, S); break;
default:
#if 0
// TODO: when we have the full set of attributes, warn about unknown ones.
- S.Diag(Attr->getLoc(), diag::warn_attribute_ignored) << Attr->getName();
+ S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) << Attr.getName();
#endif
break;
}
diff --git a/clang/test/Sema/attr-nodebug.c b/clang/test/Sema/attr-nodebug.c
new file mode 100644
index 00000000000..a3b525c4938
--- /dev/null
+++ b/clang/test/Sema/attr-nodebug.c
@@ -0,0 +1,8 @@
+// RUN: clang %s -verify -fsyntax-only
+
+int a __attribute__((nodebug)); // expected-warning {{'nodebug' attribute only applies to function types}}
+
+void t1() __attribute__((nodebug));
+
+void t2() __attribute__((nodebug(2))); // expected-error {{attribute requires 0 argument(s)}}
+
OpenPOWER on IntegriCloud