leonardchan created this revision. leonardchan added reviewers: rjmccall, rsmith, phosek, mcgrathr, ebevhan, theraven. leonardchan added a project: clang.
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. Repository: rC Clang https://reviews.llvm.org/D51229 Files: include/clang/Basic/Attr.td lib/AST/TypePrinter.cpp lib/Sema/SemaType.cpp Index: lib/Sema/SemaType.cpp =================================================================== --- lib/Sema/SemaType.cpp +++ lib/Sema/SemaType.cpp @@ -7281,10 +7281,21 @@ case ParsedAttr::AT_OpenCLLocalAddressSpace: case ParsedAttr::AT_OpenCLConstantAddressSpace: case ParsedAttr::AT_OpenCLGenericAddressSpace: - case ParsedAttr::AT_AddressSpace: + case ParsedAttr::AT_AddressSpace: { HandleAddressSpaceTypeAttribute(type, attr, state.getSema()); + + if (attr.getKind() == ParsedAttr::AT_AddressSpace && + !type->getAs<DependentAddressSpaceType>()) { + ASTContext &Ctx = state.getSema().Context; + auto *ASAttr = ::new (Ctx) AddressSpaceAttr( + attr.getRange(), Ctx, attr.getAttributeSpellingListIndex(), + static_cast<unsigned>(type.getQualifiers().getAddressSpace())); + type = state.getAttributedType(ASAttr, type, type); + } + attr.setUsedAsTypeAttr(); break; + } OBJC_POINTER_TYPE_ATTRS_CASELIST: if (!handleObjCPointerTypeAttr(state, attr, type)) distributeObjCPointerTypeAttr(state, attr, type); Index: lib/AST/TypePrinter.cpp =================================================================== --- lib/AST/TypePrinter.cpp +++ lib/AST/TypePrinter.cpp @@ -1427,6 +1427,9 @@ return; } + if (T->getAttrKind() == attr::AddressSpace) + return; + OS << " __attribute__(("; switch (T->getAttrKind()) { #define TYPE_ATTR(NAME) @@ -1494,6 +1497,9 @@ case attr::PreserveAll: OS << "preserve_all"; break; + + case attr::AddressSpace: + llvm_unreachable("Printing of address_space is handled by the qualifier"); } OS << "))"; } Index: include/clang/Basic/Attr.td =================================================================== --- include/clang/Basic/Attr.td +++ include/clang/Basic/Attr.td @@ -564,8 +564,6 @@ 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 {
Index: lib/Sema/SemaType.cpp =================================================================== --- lib/Sema/SemaType.cpp +++ lib/Sema/SemaType.cpp @@ -7281,10 +7281,21 @@ case ParsedAttr::AT_OpenCLLocalAddressSpace: case ParsedAttr::AT_OpenCLConstantAddressSpace: case ParsedAttr::AT_OpenCLGenericAddressSpace: - case ParsedAttr::AT_AddressSpace: + case ParsedAttr::AT_AddressSpace: { HandleAddressSpaceTypeAttribute(type, attr, state.getSema()); + + if (attr.getKind() == ParsedAttr::AT_AddressSpace && + !type->getAs<DependentAddressSpaceType>()) { + ASTContext &Ctx = state.getSema().Context; + auto *ASAttr = ::new (Ctx) AddressSpaceAttr( + attr.getRange(), Ctx, attr.getAttributeSpellingListIndex(), + static_cast<unsigned>(type.getQualifiers().getAddressSpace())); + type = state.getAttributedType(ASAttr, type, type); + } + attr.setUsedAsTypeAttr(); break; + } OBJC_POINTER_TYPE_ATTRS_CASELIST: if (!handleObjCPointerTypeAttr(state, attr, type)) distributeObjCPointerTypeAttr(state, attr, type); Index: lib/AST/TypePrinter.cpp =================================================================== --- lib/AST/TypePrinter.cpp +++ lib/AST/TypePrinter.cpp @@ -1427,6 +1427,9 @@ return; } + if (T->getAttrKind() == attr::AddressSpace) + return; + OS << " __attribute__(("; switch (T->getAttrKind()) { #define TYPE_ATTR(NAME) @@ -1494,6 +1497,9 @@ case attr::PreserveAll: OS << "preserve_all"; break; + + case attr::AddressSpace: + llvm_unreachable("Printing of address_space is handled by the qualifier"); } OS << "))"; } Index: include/clang/Basic/Attr.td =================================================================== --- include/clang/Basic/Attr.td +++ include/clang/Basic/Attr.td @@ -564,8 +564,6 @@ 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 {
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits