[PATCH] D51229: [Sema/Attribute] Make types declared with address_space an AttributedType
Leonard Chan via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Aug 24 12:07:51 PDT 2018
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 {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D51229.162428.patch
Type: text/x-patch
Size: 2130 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180824/e67617c2/attachment.bin>
More information about the cfe-commits
mailing list