[cfe-commits] r47689 - in /cfe/trunk: Parse/AttributeList.cpp Sema/Sema.h Sema/SemaDecl.cpp include/clang/AST/Attr.h include/clang/Parse/AttributeList.h

Ted Kremenek kremenek at apple.com
Wed Feb 27 12:43:07 PST 2008


Author: kremenek
Date: Wed Feb 27 14:43:06 2008
New Revision: 47689

URL: http://llvm.org/viewvc/llvm-project?rev=47689&view=rev
Log:
Added support for attribute "noreturn."

Modified:
    cfe/trunk/Parse/AttributeList.cpp
    cfe/trunk/Sema/Sema.h
    cfe/trunk/Sema/SemaDecl.cpp
    cfe/trunk/include/clang/AST/Attr.h
    cfe/trunk/include/clang/Parse/AttributeList.h

Modified: cfe/trunk/Parse/AttributeList.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Parse/AttributeList.cpp?rev=47689&r1=47688&r2=47689&view=diff

==============================================================================
--- cfe/trunk/Parse/AttributeList.cpp (original)
+++ cfe/trunk/Parse/AttributeList.cpp Wed Feb 27 14:43:06 2008
@@ -49,7 +49,7 @@
     Str += 2;
     Len -= 4;
   }
-  
+
   switch (Len) {
   case 6: 
     if (!memcmp(Str, "packed", 6)) return AT_packed;
@@ -59,6 +59,7 @@
     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;

Modified: cfe/trunk/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/Sema.h?rev=47689&r1=47688&r2=47689&view=diff

==============================================================================
--- cfe/trunk/Sema/Sema.h (original)
+++ cfe/trunk/Sema/Sema.h Wed Feb 27 14:43:06 2008
@@ -272,6 +272,7 @@
   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);

Modified: cfe/trunk/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaDecl.cpp?rev=47689&r1=47688&r2=47689&view=diff

==============================================================================
--- cfe/trunk/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/Sema/SemaDecl.cpp Wed Feb 27 14:43:06 2008
@@ -1785,6 +1785,9 @@
   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 @@
          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) {

Modified: cfe/trunk/include/clang/AST/Attr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Attr.h?rev=47689&r1=47688&r2=47689&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Attr.h (original)
+++ cfe/trunk/include/clang/AST/Attr.h Wed Feb 27 14:43:06 2008
@@ -25,7 +25,8 @@
   enum Kind {
     Aligned,
     Packed,
-    Annotate
+    Annotate,
+    NoReturn
   };
     
 private:
@@ -95,6 +96,16 @@
   }
   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
 

Modified: cfe/trunk/include/clang/Parse/AttributeList.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/AttributeList.h?rev=47689&r1=47688&r2=47689&view=diff

==============================================================================
--- cfe/trunk/include/clang/Parse/AttributeList.h (original)
+++ cfe/trunk/include/clang/Parse/AttributeList.h Wed Feb 27 14:43:06 2008
@@ -48,7 +48,8 @@
     AT_address_space,
     AT_aligned,
     AT_packed,
-    AT_annotate
+    AT_annotate,
+    AT_noreturn
   };
   
   IdentifierInfo *getName() const { return AttrName; }





More information about the cfe-commits mailing list