[PATCH] D77378: [Clang] Include size and maximum in vector size error message.
Florian Hahn via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Apr 3 03:44:24 PDT 2020
fhahn updated this revision to Diff 254744.
fhahn added a comment.
Fix wrong formatting of check lines..
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D77378/new/
https://reviews.llvm.org/D77378
Files:
clang/include/clang/AST/Type.h
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaType.cpp
clang/test/Sema/types.c
clang/test/SemaCXX/vector.cpp
Index: clang/test/SemaCXX/vector.cpp
===================================================================
--- clang/test/SemaCXX/vector.cpp
+++ clang/test/SemaCXX/vector.cpp
@@ -359,18 +359,18 @@
// expected-error@#1 {{vector size not an integral multiple of component size}}
// expected-note at +1 {{in instantiation of template class 'Templates::TemplateVectorType<int, 33>' requested here}}
const TemplateVectorType<int, 33>::type BadSize;
- // expected-error@#1 {{vector size too large}}
+ // expected-error@#1 {{vector size too large. Size is 8192 when the maximum allowed is 4092}}
// expected-note at +1 {{in instantiation of template class 'Templates::TemplateVectorType<int, 8192>' requested here}}
const TemplateVectorType<int, 8192>::type TooLarge;
// expected-error@#1 {{zero vector size}}
// expected-note at +1 {{in instantiation of template class 'Templates::TemplateVectorType<int, 0>' requested here}}
const TemplateVectorType<int, 0>::type Zero;
- // expected-error@#2 {{vector size too large}}
+ // 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 at +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-error@#2 {{vector size too large. Size is 8192 when the maximum allowed is 1023}}
// expected-note at +1 {{in instantiation of template class 'Templates::PR15730<8, char>' requested here}}
const PR15730<8, char>::type2 PR15730_2 = {};
}
Index: clang/test/Sema/types.c
===================================================================
--- clang/test/Sema/types.c
+++ clang/test/Sema/types.c
@@ -70,8 +70,8 @@
}
// 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}}
Index: clang/lib/Sema/SemaType.cpp
===================================================================
--- clang/lib/Sema/SemaType.cpp
+++ 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<unsigned>(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();
}
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===================================================================
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ 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">;
Index: clang/include/clang/AST/Type.h
===================================================================
--- clang/include/clang/AST/Type.h
+++ 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); }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D77378.254744.patch
Type: text/x-patch
Size: 4681 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200403/e0453537/attachment.bin>
More information about the cfe-commits
mailing list