Bounds checking for address spaces.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@77303 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp
index 226f214..d3daa07 100644
--- a/lib/Sema/SemaType.cpp
+++ b/lib/Sema/SemaType.cpp
@@ -1469,6 +1469,23 @@
return;
}
+ // Bounds checking.
+ if (addrSpace.isSigned()) {
+ if (addrSpace.isNegative()) {
+ S.Diag(Attr.getLoc(), diag::err_attribute_address_space_negative)
+ << ASArgExpr->getSourceRange();
+ return;
+ }
+ addrSpace.setIsSigned(false);
+ }
+ llvm::APSInt max(addrSpace.getBitWidth());
+ max = QualType::MaxAddressSpace;
+ if (addrSpace > max) {
+ S.Diag(Attr.getLoc(), diag::err_attribute_address_space_too_high)
+ << QualType::MaxAddressSpace << ASArgExpr->getSourceRange();
+ return;
+ }
+
unsigned ASIdx = static_cast<unsigned>(addrSpace.getZExtValue());
Type = S.Context.getAddrSpaceQualType(Type, ASIdx);
}