return new LinkageSpecDecl(Loc, Language, dcl);
}
-void Sema::HandleDeclAttribute(Decl *New, AttributeList *rawAttr) {
+void Sema::HandleDeclAttribute(Decl *New, AttributeList *Attr) {
- switch (rawAttr->getKind()) {
+ switch (Attr->getKind()) {
case AttributeList::AT_vector_size:
if (ValueDecl *vDecl = dyn_cast<ValueDecl>(New)) {
- QualType newType = HandleVectorTypeAttribute(vDecl->getType(), rawAttr);
+ QualType newType = HandleVectorTypeAttribute(vDecl->getType(), Attr);
if (!newType.isNull()) // install the new vector type into the decl
vDecl->setType(newType);
}
if (TypedefDecl *tDecl = dyn_cast<TypedefDecl>(New)) {
QualType newType = HandleVectorTypeAttribute(tDecl->getUnderlyingType(),
- rawAttr);
+ Attr);
if (!newType.isNull()) // install the new vector type into the decl
tDecl->setUnderlyingType(newType);
}
break;
case AttributeList::AT_ocu_vector_type:
if (TypedefDecl *tDecl = dyn_cast<TypedefDecl>(New))
- HandleOCUVectorTypeAttribute(tDecl, rawAttr);
+ HandleOCUVectorTypeAttribute(tDecl, Attr);
else
- Diag(rawAttr->getLoc(),
+ Diag(Attr->getLoc(),
diag::err_typecheck_ocu_vector_not_typedef);
break;
case AttributeList::AT_address_space:
if (TypedefDecl *tDecl = dyn_cast<TypedefDecl>(New)) {
QualType newType = HandleAddressSpaceTypeAttribute(
tDecl->getUnderlyingType(),
- rawAttr);
- if (!newType.isNull()) // install the new addr spaced type into the decl
- tDecl->setUnderlyingType(newType);
+ Attr);
+ tDecl->setUnderlyingType(newType);
} else if (ValueDecl *vDecl = dyn_cast<ValueDecl>(New)) {
QualType newType = HandleAddressSpaceTypeAttribute(vDecl->getType(),
- rawAttr);
- if (!newType.isNull()) // install the new addr spaced type into the decl
- vDecl->setType(newType);
+ Attr);
+ // install the new addr spaced type into the decl
+ vDecl->setType(newType);
}
break;
case AttributeList::AT_aligned:
- HandleAlignedAttribute(New, rawAttr);
+ HandleAlignedAttribute(New, Attr);
break;
case AttributeList::AT_packed:
- HandlePackedAttribute(New, rawAttr);
+ HandlePackedAttribute(New, Attr);
break;
default:
// FIXME: add other attributes...
}
}
-QualType Sema::HandleAddressSpaceTypeAttribute(QualType curType,
- AttributeList *rawAttr) {
- // check the attribute arguments.
- if (rawAttr->getNumArgs() != 1) {
- Diag(rawAttr->getLoc(), diag::err_attribute_wrong_number_arguments,
- std::string("1"));
- return QualType();
- }
- Expr *addrSpaceExpr = static_cast<Expr *>(rawAttr->getArg(0));
- llvm::APSInt addrSpace(32);
- if (!addrSpaceExpr->isIntegerConstantExpr(addrSpace, Context)) {
- Diag(rawAttr->getLoc(), diag::err_attribute_address_space_not_int,
- addrSpaceExpr->getSourceRange());
- return QualType();
- }
- unsigned addressSpace = static_cast<unsigned>(addrSpace.getZExtValue());
-
- // Zero is the default memory space, so no qualification is needed
- if (addressSpace == 0)
- return curType;
-
- // TODO: Should we convert contained types of address space
- // qualified types here or or where they directly participate in conversions
- // (i.e. elsewhere)
- return Context.getASQualType(curType, addressSpace);
-}
-
void Sema::HandleOCUVectorTypeAttribute(TypedefDecl *tDecl,
AttributeList *rawAttr) {
QualType curType = tDecl->getUnderlyingType();
llvm::SmallVector<AttributeList *, 8> LeftOverAttrs;
AttributeList *AL = DS.getAttributes();
while (AL) {
+ // Unlink this attribute from the chain, so we can process it independently.
AttributeList *ThisAttr = AL;
AL = AL->getNext();
+ ThisAttr->setNext(0);
+
+ // If this is an attribute we can handle, do so now, otherwise, add it to
+ // the LeftOverAttrs list for rechaining.
+ switch (ThisAttr->getKind()) {
+ default: break;
+ case AttributeList::AT_address_space:
+ Result = HandleAddressSpaceTypeAttribute(Result, ThisAttr);
+ delete ThisAttr; // Consume the attribute.
+ continue;
+ }
LeftOverAttrs.push_back(ThisAttr);
}
return Result;
}
+/// HandleAddressSpaceTypeAttribute - Process an address_space attribute on the
+/// specified type.
+QualType Sema::HandleAddressSpaceTypeAttribute(QualType Type,
+ AttributeList *Attr) {
+ // If this type is already address space qualified, reject it.
+ // Clause 6.7.3 - Type qualifiers: "No type shall be qualified by qualifiers
+ // for two or more different address spaces."
+ if (Type.getAddressSpace()) {
+ Diag(Attr->getLoc(), diag::err_attribute_address_multiple_qualifiers);
+ return Type;
+ }
+
+ // Check the attribute arguments.
+ if (Attr->getNumArgs() != 1) {
+ Diag(Attr->getLoc(), diag::err_attribute_wrong_number_arguments,
+ std::string("1"));
+ return Type;
+ }
+ Expr *ASArgExpr = static_cast<Expr *>(Attr->getArg(0));
+ llvm::APSInt addrSpace(32);
+ if (!ASArgExpr->isIntegerConstantExpr(addrSpace, Context)) {
+ Diag(Attr->getLoc(), diag::err_attribute_address_space_not_int,
+ ASArgExpr->getSourceRange());
+ return Type;
+ }
+
+ unsigned ASIdx = static_cast<unsigned>(addrSpace.getZExtValue());
+ return Context.getASQualType(Type, ASIdx);
+}
+
+
/// GetTypeForDeclarator - Convert the type for the specified declarator to Type
/// instances.
QualType Sema::GetTypeForDeclarator(Declarator &D, Scope *S) {