aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@mac.com>2008-10-05 23:32:53 +0000
committerAnders Carlsson <andersca@mac.com>2008-10-05 23:32:53 +0000
commit232eb7d33b96ad8f99de3b5ae840421b3a7c6cb7 (patch)
tree7496307d5faaa35fdb14a3eb580652278501277d
parentd3616a8d0b1506966cb669c19dbfc91bf42c810a (diff)
Implement support for the const and pure attributes.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@57142 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/AST/Attr.h26
-rw-r--r--include/clang/Parse/AttributeList.h1
-rw-r--r--lib/CodeGen/CGCall.cpp4
-rw-r--r--lib/Sema/SemaDeclAttr.cpp24
4 files changed, 53 insertions, 2 deletions
diff --git a/include/clang/AST/Attr.h b/include/clang/AST/Attr.h
index 3115a4513e..c6fb1d16c7 100644
--- a/include/clang/AST/Attr.h
+++ b/include/clang/AST/Attr.h
@@ -47,7 +47,9 @@ public:
Unused,
Visibility,
Weak,
- Blocks
+ Blocks,
+ Const,
+ Pure
};
private:
@@ -228,7 +230,27 @@ public:
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;
diff --git a/include/clang/Parse/AttributeList.h b/include/clang/Parse/AttributeList.h
index 8ca78a34b8..d41faa31b0 100644
--- a/include/clang/Parse/AttributeList.h
+++ b/include/clang/Parse/AttributeList.h
@@ -73,6 +73,7 @@ public:
AT_objc_gc,
AT_blocks,
AT_sentinel,
+ AT_const,
UnknownAttribute
};
diff --git a/lib/CodeGen/CGCall.cpp b/lib/CodeGen/CGCall.cpp
index a1c3c33462..a246ade82c 100644
--- a/lib/CodeGen/CGCall.cpp
+++ b/lib/CodeGen/CGCall.cpp
@@ -520,6 +520,10 @@ void CodeGenModule::ConstructAttributeList(const Decl *TargetDecl,
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;
diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp
index fd79a10bf4..3ab0c91cb9 100644
--- a/lib/Sema/SemaDeclAttr.cpp
+++ b/lib/Sema/SemaDeclAttr.cpp
@@ -717,6 +717,28 @@ static void HandleNothrowAttr(Decl *d, const AttributeList &Attr, Sema &S) {
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 @@ static void ProcessDeclAttribute(Decl *D, const AttributeList &Attr, Sema &S) {
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.