BuildVectorType with a dependent (array) type is crashing the compiler - Fix for PR-47542

Reviewed By: rnk

Differential Revision: https://reviews.llvm.org/D88150
This commit is contained in:
Zahira Ammarguellat 2020-09-28 16:54:40 -07:00 committed by Reid Kleckner
parent 54d9f743c8
commit efd04721c9
2 changed files with 11 additions and 3 deletions

View File

@ -2517,9 +2517,10 @@ QualType Sema::BuildVectorType(QualType CurType, Expr *SizeExpr,
SourceLocation AttrLoc) {
// The base type must be integer (not Boolean or enumeration) or float, and
// can't already be a vector.
if (!CurType->isDependentType() &&
(!CurType->isBuiltinType() || CurType->isBooleanType() ||
(!CurType->isIntegerType() && !CurType->isRealFloatingType()))) {
if ((!CurType->isDependentType() &&
(!CurType->isBuiltinType() || CurType->isBooleanType() ||
(!CurType->isIntegerType() && !CurType->isRealFloatingType()))) ||
CurType->isArrayType()) {
Diag(AttrLoc, diag::err_attribute_invalid_vector_type) << CurType;
return QualType();
}

View File

@ -12,6 +12,13 @@ void f() {
void g(int a[static [[]] 5]); // expected-error {{static array size is a C99 feature, not permitted in C++}}
template<typename T> struct A {
int x[sizeof(T)] __attribute((vector_size(8))); // expected-error {{invalid vector element type 'int [sizeof(T)]'}}
};
typedef int myvect[4] __attribute__((vector_size(16))); // expected-error {{invalid vector element type 'int [4]'}}
void foo(myvect *in, myvect *out) { (*out)[0] = (*in)[0]; }
namespace {
class B {
public: