diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h --- a/clang/include/clang/AST/Type.h +++ b/clang/include/clang/AST/Type.h @@ -3253,6 +3253,10 @@ return NumElements > VectorTypeBitfields::MaxNumElements; } + static unsigned getMaxNumElements() { + return 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 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -2868,7 +2868,7 @@ 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_attribute_size_too_large : Error<"vector size too large. Size is %0 when the maximum allowed is %1">; def err_typecheck_vector_not_convertable_implict_truncation : Error< "cannot convert between %select{scalar|vector}0 type %1 and vector type" " %2 as implicit conversion would cause truncation">; diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/lib/Sema/SemaType.cpp @@ -2453,7 +2453,10 @@ if (VectorType::isVectorSizeTooLarge(VectorSize / TypeSize)) { Diag(AttrLoc, diag::err_attribute_size_too_large) - << SizeExpr->getSourceRange(); + // Display sizes in error messages in bytes. + << SizeExpr->getSourceRange() + << static_cast(VecSize.getZExtValue()) + << (VectorType::getMaxNumElements() * (TypeSize / 8)); return QualType(); } @@ -2501,7 +2504,8 @@ if (VectorType::isVectorSizeTooLarge(vectorSize)) { Diag(AttrLoc, diag::err_attribute_size_too_large) - << ArraySize->getSourceRange(); + << ArraySize->getSourceRange() << vectorSize + << VectorType::getMaxNumElements(); return QualType(); } diff --git a/clang/test/Sema/types.c b/clang/test/Sema/types.c --- a/clang/test/Sema/types.c +++ b/clang/test/Sema/types.c @@ -70,8 +70,12 @@ } // 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}} +int __attribute__((vector_size(8192))) +x1; // expected-error {{vector size too large. Size is 8192 when the maximum + // allowed is 4092}} +typedef int __attribute__((ext_vector_type(8192))) +x2; // expected-error {{vector size too large. Size is 8192 when the maximum + // allowed is 1023}} // no support for vector enum type enum { e_2 } x3 __attribute__((vector_size(64))); // expected-error {{invalid vector element type}} diff --git a/clang/test/SemaCXX/vector.cpp b/clang/test/SemaCXX/vector.cpp --- a/clang/test/SemaCXX/vector.cpp +++ b/clang/test/SemaCXX/vector.cpp @@ -359,19 +359,22 @@ // expected-error@#1 {{vector size not an integral multiple of component size}} // expected-note@+1 {{in instantiation of template class 'Templates::TemplateVectorType' requested here}} const TemplateVectorType::type BadSize; - // expected-error@#1 {{vector size too large}} - // expected-note@+1 {{in instantiation of template class 'Templates::TemplateVectorType' requested here}} + // expected-error@#1 {{vector size too large. Size is 8192 when the maximum + // allowed is 4092}} expected-note@+1 {{in instantiation of template class + // 'Templates::TemplateVectorType' requested here}} const TemplateVectorType::type TooLarge; // expected-error@#1 {{zero vector size}} // expected-note@+1 {{in instantiation of template class 'Templates::TemplateVectorType' requested here}} const TemplateVectorType::type Zero; - // expected-error@#2 {{vector size too large}} - // expected-error@#3 {{vector size not an integral multiple of component size}} - // expected-note@+1 {{in instantiation of template class 'Templates::PR15730<8, int>' requested here}} + // expected-error@#2 {{vector size too large. Size is 8192 when the maximum + // allowed is 4092}} expected-error@#3 {{vector size not an integral multiple + // of component size}} expected-note@+1 {{in instantiation of template class + // 'Templates::PR15730<8, int>' requested here}} const PR15730<8, int>::type PR15730_1 = {}; - // expected-error@#2 {{vector size too large}} - // expected-note@+1 {{in instantiation of template class 'Templates::PR15730<8, char>' requested here}} + // expected-error@#2 {{vector size too large. Size is 8192 when the maximum + // allowed is 1023}} expected-note@+1 {{in instantiation of template class + // 'Templates::PR15730<8, char>' requested here}} const PR15730<8, char>::type2 PR15730_2 = {}; }