summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEli Friedman <eli.friedman@gmail.com>2013-07-26 00:53:47 +0000
committerEli Friedman <eli.friedman@gmail.com>2013-07-26 00:53:47 +0000
commitefe9fa62f5b42dcefb856c33080578791719cf80 (patch)
treea4749c7ffe98ba62b170144271c95c5d4423c343
parentbf44f366a1ab05b31b9f27fc3ce0a55b18823151 (diff)
downloadbcm5719-llvm-efe9fa62f5b42dcefb856c33080578791719cf80.tar.gz
bcm5719-llvm-efe9fa62f5b42dcefb856c33080578791719cf80.zip
Tighten type-checking for vector attributes.
Based on patch by Yunzhong Gao. llvm-svn: 187176
-rw-r--r--clang/include/clang/AST/Type.h5
-rw-r--r--clang/include/clang/Basic/DiagnosticSemaKinds.td1
-rw-r--r--clang/lib/Sema/SemaType.cpp15
-rw-r--r--clang/test/Sema/types.c8
4 files changed, 28 insertions, 1 deletions
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 4997ce2fb71..f578d3b5d10 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -1315,6 +1315,8 @@ protected:
/// NumElements - The number of elements in the vector.
unsigned NumElements : 29 - NumTypeBits;
+
+ enum { MaxNumElements = (1 << (29 - NumTypeBits)) - 1 };
};
class AttributedTypeBitfields {
@@ -2524,6 +2526,9 @@ public:
QualType getElementType() const { return ElementType; }
unsigned getNumElements() const { return VectorTypeBits.NumElements; }
+ static bool isVectorSizeTooLarge(unsigned NumElements) {
+ return NumElements > VectorTypeBitfields::MaxNumElements;
+ }
bool isSugared() const { return false; }
QualType desugar() const { return QualType(this, 0); }
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index aa0f73caced..16619d9db0d 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1829,6 +1829,7 @@ def err_init_method_bad_return_type : Error<
def err_attribute_invalid_size : Error<
"vector size not an integral multiple of component size">;
def err_attribute_zero_size : Error<"zero vector size">;
+def err_attribute_size_too_large : Error<"vector size too large">;
def err_typecheck_vector_not_convertable : Error<
"can't convert between vector values of different size (%0 and %1)">;
def err_typecheck_ext_vector_not_typedef : Error<
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 6657acb1bb5..37e5d819004 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -1645,6 +1645,12 @@ QualType Sema::BuildExtVectorType(QualType T, Expr *ArraySize,
return QualType();
}
+ if (VectorType::isVectorSizeTooLarge(vectorSize)) {
+ Diag(AttrLoc, diag::err_attribute_size_too_large)
+ << ArraySize->getSourceRange();
+ return QualType();
+ }
+
return Context.getExtVectorType(T, vectorSize);
}
@@ -4521,7 +4527,8 @@ static void HandleVectorSizeAttr(QualType& CurType, const AttributeList &Attr,
return;
}
// the base type must be integer or float, and can't already be a vector.
- if (!CurType->isIntegerType() && !CurType->isRealFloatingType()) {
+ if (!CurType->isBuiltinType() ||
+ (!CurType->isIntegerType() && !CurType->isRealFloatingType())) {
S.Diag(Attr.getLoc(), diag::err_attribute_invalid_vector_type) << CurType;
Attr.setInvalid();
return;
@@ -4537,6 +4544,12 @@ static void HandleVectorSizeAttr(QualType& CurType, const AttributeList &Attr,
Attr.setInvalid();
return;
}
+ if (VectorType::isVectorSizeTooLarge(vectorSize / typeSize)) {
+ S.Diag(Attr.getLoc(), diag::err_attribute_size_too_large)
+ << sizeExpr->getSourceRange();
+ Attr.setInvalid();
+ return;
+ }
if (vectorSize == 0) {
S.Diag(Attr.getLoc(), diag::err_attribute_zero_size)
<< sizeExpr->getSourceRange();
diff --git a/clang/test/Sema/types.c b/clang/test/Sema/types.c
index d0637cca61a..dac0bfe9fe8 100644
--- a/clang/test/Sema/types.c
+++ b/clang/test/Sema/types.c
@@ -64,3 +64,11 @@ void test(int i) {
void test2(int i) {
char c = (char __attribute__((may_alias))) i;
}
+
+// vector size too large
+int __attribute__ ((vector_size(8192))) x1; // expected-error {{vector size too large}}
+typedef int __attribute__ ((ext_vector_type(8192))) x2; // expected-error {{vector size too large}}
+
+// no support for vector enum type
+enum { e_2 } x3 __attribute__((vector_size(64))); // expected-error {{invalid vector element type}}
+
OpenPOWER on IntegriCloud