Unused,
Visibility,
Weak,
- Blocks
+ Blocks,
+ Const,
+ Pure
};
private:
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;
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;
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) {
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.