forked from OSchip/llvm-project
[Sema/Attribute] Make types declared with address_space an AttributedType
Currently an address_space is stored in a qualifier. This makes any type declared with an address_space attribute in the form `__attribute__((address_space(1))) int 1;` be wrapped in an AttributedType. This is for a later patch where if `address_space` is declared in a macro, any diagnostics that would normally print the address space will instead dump the macro name. This will require saving any macro information in the AttributedType. Differential Revision: https://reviews.llvm.org/D51229 llvm-svn: 340765
This commit is contained in:
parent
118dc299f9
commit
fdadd998ee
|
@ -564,8 +564,6 @@ def AddressSpace : TypeAttr {
|
|||
let Spellings = [Clang<"address_space">];
|
||||
let Args = [IntArgument<"AddressSpace">];
|
||||
let Documentation = [Undocumented];
|
||||
// Represented as a qualifier or DependentAddressSpaceType instead.
|
||||
let ASTNode = 0;
|
||||
}
|
||||
|
||||
def Alias : Attr {
|
||||
|
|
|
@ -1427,6 +1427,12 @@ void TypePrinter::printAttributedAfter(const AttributedType *T,
|
|||
return;
|
||||
}
|
||||
|
||||
// The printing of the address_space attribute is handled by the qualifier
|
||||
// since it is still stored in the qualifier. Return early to prevent printing
|
||||
// this twice.
|
||||
if (T->getAttrKind() == attr::AddressSpace)
|
||||
return;
|
||||
|
||||
OS << " __attribute__((";
|
||||
switch (T->getAttrKind()) {
|
||||
#define TYPE_ATTR(NAME)
|
||||
|
@ -1456,6 +1462,7 @@ void TypePrinter::printAttributedAfter(const AttributedType *T,
|
|||
case attr::Ptr64:
|
||||
case attr::SPtr:
|
||||
case attr::UPtr:
|
||||
case attr::AddressSpace:
|
||||
llvm_unreachable("This attribute should have been handled already");
|
||||
|
||||
case attr::NSReturnsRetained:
|
||||
|
|
|
@ -5597,12 +5597,6 @@ GetTypeSourceInfoForDeclarator(TypeProcessingState &State,
|
|||
}
|
||||
|
||||
for (unsigned i = 0, e = D.getNumTypeObjects(); i != e; ++i) {
|
||||
if (DependentAddressSpaceTypeLoc DASTL =
|
||||
CurrTL.getAs<DependentAddressSpaceTypeLoc>()) {
|
||||
fillDependentAddressSpaceTypeLoc(DASTL, D.getTypeObject(i).getAttrs());
|
||||
CurrTL = DASTL.getPointeeTypeLoc().getUnqualifiedLoc();
|
||||
}
|
||||
|
||||
// An AtomicTypeLoc might be produced by an atomic qualifier in this
|
||||
// declarator chunk.
|
||||
if (AtomicTypeLoc ATL = CurrTL.getAs<AtomicTypeLoc>()) {
|
||||
|
@ -5615,6 +5609,12 @@ GetTypeSourceInfoForDeclarator(TypeProcessingState &State,
|
|||
CurrTL = TL.getNextTypeLoc().getUnqualifiedLoc();
|
||||
}
|
||||
|
||||
while (DependentAddressSpaceTypeLoc TL =
|
||||
CurrTL.getAs<DependentAddressSpaceTypeLoc>()) {
|
||||
fillDependentAddressSpaceTypeLoc(TL, D.getTypeObject(i).getAttrs());
|
||||
CurrTL = TL.getPointeeTypeLoc().getUnqualifiedLoc();
|
||||
}
|
||||
|
||||
// FIXME: Ordering here?
|
||||
while (AdjustedTypeLoc TL = CurrTL.getAs<AdjustedTypeLoc>())
|
||||
CurrTL = TL.getNextTypeLoc().getUnqualifiedLoc();
|
||||
|
@ -5767,7 +5767,10 @@ QualType Sema::BuildAddressSpaceAttr(QualType &T, Expr *AddrSpace,
|
|||
/// specified type. The attribute contains 1 argument, the id of the address
|
||||
/// space for the type.
|
||||
static void HandleAddressSpaceTypeAttribute(QualType &Type,
|
||||
const ParsedAttr &Attr, Sema &S) {
|
||||
const ParsedAttr &Attr,
|
||||
TypeProcessingState &State) {
|
||||
Sema &S = State.getSema();
|
||||
|
||||
// ISO/IEC TR 18037 S5.3 (amending C99 6.7.3): "A function type shall not be
|
||||
// qualified by an address-space qualifier."
|
||||
if (Type->isFunctionType()) {
|
||||
|
@ -5809,10 +5812,15 @@ static void HandleAddressSpaceTypeAttribute(QualType &Type,
|
|||
// the type.
|
||||
QualType T = S.BuildAddressSpaceAttr(Type, ASArgExpr, Attr.getLoc());
|
||||
|
||||
if (!T.isNull())
|
||||
Type = T;
|
||||
else
|
||||
if (!T.isNull()) {
|
||||
ASTContext &Ctx = S.Context;
|
||||
auto *ASAttr = ::new (Ctx) AddressSpaceAttr(
|
||||
Attr.getRange(), Ctx, Attr.getAttributeSpellingListIndex(),
|
||||
static_cast<unsigned>(T.getQualifiers().getAddressSpace()));
|
||||
Type = State.getAttributedType(ASAttr, T, T);
|
||||
} else {
|
||||
Attr.setInvalid();
|
||||
}
|
||||
} else {
|
||||
// The keyword-based type attributes imply which address space to use.
|
||||
switch (Attr.getKind()) {
|
||||
|
@ -7282,7 +7290,7 @@ static void processTypeAttrs(TypeProcessingState &state, QualType &type,
|
|||
case ParsedAttr::AT_OpenCLConstantAddressSpace:
|
||||
case ParsedAttr::AT_OpenCLGenericAddressSpace:
|
||||
case ParsedAttr::AT_AddressSpace:
|
||||
HandleAddressSpaceTypeAttribute(type, attr, state.getSema());
|
||||
HandleAddressSpaceTypeAttribute(type, attr, state);
|
||||
attr.setUsedAsTypeAttr();
|
||||
break;
|
||||
OBJC_POINTER_TYPE_ATTRS_CASELIST:
|
||||
|
|
Loading…
Reference in New Issue