diff options
| author | Alexey Bader <alexey.bader@intel.com> | 2018-06-20 08:31:24 +0000 |
|---|---|---|
| committer | Alexey Bader <alexey.bader@intel.com> | 2018-06-20 08:31:24 +0000 |
| commit | f29d777f847b2a3d0aec2a499490fa34815fc918 (patch) | |
| tree | ebb1e91f9f98b7b4ef981932abdd2859df09e4ed /clang/lib/Sema | |
| parent | 16662f3c6ea9bd5cb3459b6ad71d52037f4b397a (diff) | |
| download | bcm5719-llvm-f29d777f847b2a3d0aec2a499490fa34815fc918.tar.gz bcm5719-llvm-f29d777f847b2a3d0aec2a499490fa34815fc918.zip | |
[Sema] Allow creating types with multiple of the same addrspace.
Summary:
The comment with the OpenCL clause about this clearly
says: "No type shall be qualified by qualifiers for
two or more different address spaces."
This must mean that two or more qualifiers for the
_same_ address space is allowed. However, it is
likely unintended by the programmer, so emit a
warning.
For dependent address space types, reject them like
before since we cannot know what the address space
will be.
Patch by Bevin Hansson (ebevhan).
Reviewers: Anastasia
Reviewed By: Anastasia
Subscribers: bader, cfe-commits
Differential Revision: https://reviews.llvm.org/D47630
llvm-svn: 335103
Diffstat (limited to 'clang/lib/Sema')
| -rw-r--r-- | clang/lib/Sema/SemaType.cpp | 46 |
1 files changed, 29 insertions, 17 deletions
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp index 9ee947b80a3..978c1cc0158 100644 --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/lib/Sema/SemaType.cpp @@ -5758,14 +5758,6 @@ QualType Sema::BuildAddressSpaceAttr(QualType &T, Expr *AddrSpace, SourceLocation AttrLoc) { if (!AddrSpace->isValueDependent()) { - // If this type is already address space qualified, reject it. - // ISO/IEC TR 18037 S5.3 (amending C99 6.7.3): "No type shall be qualified - // by qualifiers for two or more different address spaces." - if (T.getAddressSpace() != LangAS::Default) { - Diag(AttrLoc, diag::err_attribute_address_multiple_qualifiers); - return QualType(); - } - llvm::APSInt addrSpace(32); if (!AddrSpace->isIntegerConstantExpr(addrSpace, Context)) { Diag(AttrLoc, diag::err_attribute_argument_type) @@ -5796,6 +5788,20 @@ QualType Sema::BuildAddressSpaceAttr(QualType &T, Expr *AddrSpace, LangAS ASIdx = getLangASFromTargetAS(static_cast<unsigned>(addrSpace.getZExtValue())); + // If this type is already address space qualified with a different + // address space, reject it. + // ISO/IEC TR 18037 S5.3 (amending C99 6.7.3): "No type shall be qualified + // by qualifiers for two or more different address spaces." + if (T.getAddressSpace() != LangAS::Default) { + if (T.getAddressSpace() != ASIdx) { + Diag(AttrLoc, diag::err_attribute_address_multiple_qualifiers); + return QualType(); + } else + // Emit a warning if they are identical; it's likely unintended. + Diag(AttrLoc, + diag::warn_attribute_address_multiple_identical_qualifiers); + } + return Context.getAddrSpaceQualType(T, ASIdx); } @@ -5817,15 +5823,6 @@ QualType Sema::BuildAddressSpaceAttr(QualType &T, Expr *AddrSpace, /// space for the type. static void HandleAddressSpaceTypeAttribute(QualType &Type, const AttributeList &Attr, Sema &S){ - // If this type is already address space qualified, reject it. - // ISO/IEC TR 18037 S5.3 (amending C99 6.7.3): "No type shall be qualified by - // qualifiers for two or more different address spaces." - if (Type.getAddressSpace() != LangAS::Default) { - S.Diag(Attr.getLoc(), diag::err_attribute_address_multiple_qualifiers); - Attr.setInvalid(); - return; - } - // 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()) { @@ -5888,6 +5885,21 @@ static void HandleAddressSpaceTypeAttribute(QualType &Type, llvm_unreachable("Invalid address space"); } + // If this type is already address space qualified with a different + // address space, reject it. + // ISO/IEC TR 18037 S5.3 (amending C99 6.7.3): "No type shall be qualified by + // qualifiers for two or more different address spaces." + if (Type.getAddressSpace() != LangAS::Default) { + if (Type.getAddressSpace() != ASIdx) { + S.Diag(Attr.getLoc(), diag::err_attribute_address_multiple_qualifiers); + Attr.setInvalid(); + return; + } else + // Emit a warning if they are identical; it's likely unintended. + S.Diag(Attr.getLoc(), + diag::warn_attribute_address_multiple_identical_qualifiers); + } + Type = S.Context.getAddrSpaceQualType(Type, ASIdx); } } |

