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
This commit is contained in:
Anders Carlsson 2008-10-05 23:32:53 +00:00
Родитель d3616a8d0b
Коммит 232eb7d33b
4 изменённых файлов: 53 добавлений и 2 удалений

Просмотреть файл

@ -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;

Просмотреть файл

@ -73,6 +73,7 @@ public:
AT_objc_gc,
AT_blocks,
AT_sentinel,
AT_const,
UnknownAttribute
};

Просмотреть файл

@ -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;

Просмотреть файл

@ -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.