diff options
author | Ted Kremenek <kremenek@apple.com> | 2008-02-27 20:43:06 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2008-02-27 20:43:06 +0000 |
commit | aecb38368546aa2cdb58d53bbcb3e8ad46365fc6 (patch) | |
tree | fdacc5db4a711486f22e6ed1eba85990286fc63f | |
parent | b0ab2120e53fae2af52f24373b9aa17b12a83357 (diff) |
Added support for attribute "noreturn."
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@47689 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | Parse/AttributeList.cpp | 3 | ||||
-rw-r--r-- | Sema/Sema.h | 1 | ||||
-rw-r--r-- | Sema/SemaDecl.cpp | 14 | ||||
-rw-r--r-- | include/clang/AST/Attr.h | 13 | ||||
-rw-r--r-- | include/clang/Parse/AttributeList.h | 3 |
5 files changed, 31 insertions, 3 deletions
diff --git a/Parse/AttributeList.cpp b/Parse/AttributeList.cpp index 63d07b399b..4ceece8f27 100644 --- a/Parse/AttributeList.cpp +++ b/Parse/AttributeList.cpp @@ -49,7 +49,7 @@ AttributeList::Kind AttributeList::getKind(const IdentifierInfo *Name) { Str += 2; Len -= 4; } - + switch (Len) { case 6: if (!memcmp(Str, "packed", 6)) return AT_packed; @@ -59,6 +59,7 @@ AttributeList::Kind AttributeList::getKind(const IdentifierInfo *Name) { break; case 8: if (!memcmp(Str, "annotate", 8)) return AT_annotate; + if (!memcmp(Str, "noreturn", 8)) return AT_noreturn; break; case 11: if (!memcmp(Str, "vector_size", 11)) return AT_vector_size; diff --git a/Sema/Sema.h b/Sema/Sema.h index c2d249a9c6..17ba542fc5 100644 --- a/Sema/Sema.h +++ b/Sema/Sema.h @@ -272,6 +272,7 @@ private: void HandleAlignedAttribute(Decl *d, AttributeList *rawAttr); void HandlePackedAttribute(Decl *d, AttributeList *rawAttr); void HandleAnnotateAttribute(Decl *d, AttributeList *rawAttr); + void HandleNoReturnAttribute(Decl *d, AttributeList *rawAttr); void WarnUndefinedMethod(SourceLocation ImpLoc, ObjCMethodDecl *method, bool &IncompleteImpl); diff --git a/Sema/SemaDecl.cpp b/Sema/SemaDecl.cpp index 1a0c3b2079..e841787a58 100644 --- a/Sema/SemaDecl.cpp +++ b/Sema/SemaDecl.cpp @@ -1785,6 +1785,9 @@ void Sema::HandleDeclAttribute(Decl *New, AttributeList *Attr) { case AttributeList::AT_annotate: HandleAnnotateAttribute(New, Attr); break; + case AttributeList::AT_noreturn: + HandleNoReturnAttribute(New, Attr); + break; default: // FIXME: add other attributes... break; @@ -1927,6 +1930,17 @@ void Sema::HandlePackedAttribute(Decl *d, AttributeList *rawAttr) { rawAttr->getName()->getName()); } +void Sema::HandleNoReturnAttribute(Decl *d, AttributeList *rawAttr) { + // check the attribute arguments. + if (rawAttr->getNumArgs() != 0) { + Diag(rawAttr->getLoc(), diag::err_attribute_wrong_number_arguments, + std::string("0")); + return; + } + + d->addAttr(new NoReturnAttr()); +} + void Sema::HandleAnnotateAttribute(Decl *d, AttributeList *rawAttr) { // check the attribute arguments. if (rawAttr->getNumArgs() != 1) { diff --git a/include/clang/AST/Attr.h b/include/clang/AST/Attr.h index fea0b404df..2517288460 100644 --- a/include/clang/AST/Attr.h +++ b/include/clang/AST/Attr.h @@ -25,7 +25,8 @@ public: enum Kind { Aligned, Packed, - Annotate + Annotate, + NoReturn }; private: @@ -95,6 +96,16 @@ public: } static bool classof(const AnnotateAttr *A) { return true; } }; + +class NoReturnAttr : public Attr { +public: + NoReturnAttr() : Attr(NoReturn) {} + + // Implement isa/cast/dyncast/etc. + + static bool classof(const Attr *A) { return A->getKind() == NoReturn; } + static bool classof(const NoReturnAttr *A) { return true; } +}; } // end namespace clang diff --git a/include/clang/Parse/AttributeList.h b/include/clang/Parse/AttributeList.h index d627f10b86..a6a699ef8b 100644 --- a/include/clang/Parse/AttributeList.h +++ b/include/clang/Parse/AttributeList.h @@ -48,7 +48,8 @@ public: AT_address_space, AT_aligned, AT_packed, - AT_annotate + AT_annotate, + AT_noreturn }; IdentifierInfo *getName() const { return AttrName; } |