Author: leonardchan Date: Mon Aug 27 10:57:29 2018 New Revision: 340765 URL: http://llvm.org/viewvc/llvm-project?rev=340765&view=rev Log: [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 Modified: cfe/trunk/include/clang/Basic/Attr.td cfe/trunk/lib/AST/TypePrinter.cpp cfe/trunk/lib/Sema/SemaType.cpp Modified: cfe/trunk/include/clang/Basic/Attr.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=340765&r1=340764&r2=340765&view=diff ============================================================================== --- cfe/trunk/include/clang/Basic/Attr.td (original) +++ cfe/trunk/include/clang/Basic/Attr.td Mon Aug 27 10:57:29 2018 @@ -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 { Modified: cfe/trunk/lib/AST/TypePrinter.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/TypePrinter.cpp?rev=340765&r1=340764&r2=340765&view=diff ============================================================================== --- cfe/trunk/lib/AST/TypePrinter.cpp (original) +++ cfe/trunk/lib/AST/TypePrinter.cpp Mon Aug 27 10:57:29 2018 @@ -1427,6 +1427,12 @@ void TypePrinter::printAttributedAfter(c 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(c case attr::Ptr64: case attr::SPtr: case attr::UPtr: + case attr::AddressSpace: llvm_unreachable("This attribute should have been handled already"); case attr::NSReturnsRetained: Modified: cfe/trunk/lib/Sema/SemaType.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=340765&r1=340764&r2=340765&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaType.cpp (original) +++ cfe/trunk/lib/Sema/SemaType.cpp Mon Aug 27 10:57:29 2018 @@ -5597,12 +5597,6 @@ GetTypeSourceInfoForDeclarator(TypeProce } 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(TypeProce 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(Qua /// 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 HandleAddressSpaceTypeAttrib // 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(TypeProcess 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: _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits