[cfe-commits] r57142 - in /cfe/trunk: include/clang/AST/Attr.h include/clang/Parse/AttributeList.h lib/CodeGen/CGCall.cpp lib/Sema/SemaDeclAttr.cpp

Anders Carlsson andersca at mac.com
Sun Oct 5 16:32:54 PDT 2008


Author: andersca
Date: Sun Oct  5 18:32:53 2008
New Revision: 57142

URL: http://llvm.org/viewvc/llvm-project?rev=57142&view=rev
Log:
Implement support for the const and pure attributes.

Modified:
    cfe/trunk/include/clang/AST/Attr.h
    cfe/trunk/include/clang/Parse/AttributeList.h
    cfe/trunk/lib/CodeGen/CGCall.cpp
    cfe/trunk/lib/Sema/SemaDeclAttr.cpp

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

==============================================================================
--- cfe/trunk/include/clang/AST/Attr.h (original)
+++ cfe/trunk/include/clang/AST/Attr.h Sun Oct  5 18:32:53 2008
@@ -47,7 +47,9 @@
     Unused,    
     Visibility,
     Weak,
-    Blocks
+    Blocks,
+    Const,
+    Pure
   };
     
 private:
@@ -228,7 +230,27 @@
   static bool classof(const Attr *A) { return A->getKind() == NoThrow; }
   static bool classof(const NoThrowAttr *A) { return true; }
 };
-  
+
+class ConstAttr : public Attr {
+public:
+  ConstAttr() : Attr(Const) {}
+
+  // Implement isa/cast/dyncast/etc.
+
+  static bool classof(const Attr *A) { return A->getKind() == Const; }
+  static bool classof(const ConstAttr *A) { return true; }
+};
+
+class PureAttr : public Attr {
+public:
+  PureAttr() : Attr(Pure) {}
+
+  // Implement isa/cast/dyncast/etc.
+
+  static bool classof(const Attr *A) { return A->getKind() == Pure; }
+  static bool classof(const PureAttr *A) { return true; }
+};
+
 class NonNullAttr : public Attr {
   unsigned* ArgNums;
   unsigned Size;

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

==============================================================================
--- cfe/trunk/include/clang/Parse/AttributeList.h (original)
+++ cfe/trunk/include/clang/Parse/AttributeList.h Sun Oct  5 18:32:53 2008
@@ -73,6 +73,7 @@
     AT_objc_gc,
     AT_blocks,
     AT_sentinel,
+    AT_const,
     UnknownAttribute
   };
   

Modified: cfe/trunk/lib/CodeGen/CGCall.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=57142&r1=57141&r2=57142&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGCall.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCall.cpp Sun Oct  5 18:32:53 2008
@@ -520,6 +520,10 @@
       FuncAttrs |= llvm::Attribute::NoUnwind;
     if (TargetDecl->getAttr<NoReturnAttr>())
       FuncAttrs |= llvm::Attribute::NoReturn;
+    if (TargetDecl->getAttr<PureAttr>())
+      FuncAttrs |= llvm::Attribute::ReadOnly;
+    if (TargetDecl->getAttr<ConstAttr>())
+      FuncAttrs |= llvm::Attribute::ReadNone;
   }
 
   QualType RetTy = *begin;

Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=57142&r1=57141&r2=57142&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Sun Oct  5 18:32:53 2008
@@ -717,6 +717,28 @@
   d->addAttr(new NoThrowAttr());
 }
 
+static void HandleConstAttr(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,
+           std::string("0"));
+    return;
+  }
+  
+  d->addAttr(new ConstAttr());
+}
+
+static void HandlePureAttr(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,
+           std::string("0"));
+    return;
+  }
+  
+  d->addAttr(new PureAttr());
+}
+
 /// Handle __attribute__((format(type,idx,firstarg))) attributes
 /// based on http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html
 static void HandleFormatAttr(Decl *d, const AttributeList &Attr, Sema &S) {
@@ -1118,6 +1140,8 @@
   case AttributeList::AT_objc_gc:     HandleObjCGCAttr    (D, Attr, S); break;
   case AttributeList::AT_blocks:      HandleBlocksAttr    (D, Attr, S); break;
   case AttributeList::AT_sentinel:    HandleSentinelAttr  (D, Attr, S); break;
+  case AttributeList::AT_const:       HandleConstAttr     (D, Attr, S); break;
+  case AttributeList::AT_pure:        HandlePureAttr      (D, Attr, S); break;
   default:
 #if 0
     // TODO: when we have the full set of attributes, warn about unknown ones.





More information about the cfe-commits mailing list