Skip to content

Commit efd0472

Browse files
zahiraamrnk
authored andcommitted
BuildVectorType with a dependent (array) type is crashing the compiler - Fix for PR-47542
Reviewed By: rnk Differential Revision: https://reviews.llvm.org/D88150
1 parent 54d9f74 commit efd0472

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

clang/lib/Sema/SemaType.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2517,9 +2517,10 @@ QualType Sema::BuildVectorType(QualType CurType, Expr *SizeExpr,
25172517
SourceLocation AttrLoc) {
25182518
// The base type must be integer (not Boolean or enumeration) or float, and
25192519
// can't already be a vector.
2520-
if (!CurType->isDependentType() &&
2521-
(!CurType->isBuiltinType() || CurType->isBooleanType() ||
2522-
(!CurType->isIntegerType() && !CurType->isRealFloatingType()))) {
2520+
if ((!CurType->isDependentType() &&
2521+
(!CurType->isBuiltinType() || CurType->isBooleanType() ||
2522+
(!CurType->isIntegerType() && !CurType->isRealFloatingType()))) ||
2523+
CurType->isArrayType()) {
25232524
Diag(AttrLoc, diag::err_attribute_invalid_vector_type) << CurType;
25242525
return QualType();
25252526
}

clang/test/SemaCXX/attr-gnu.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ void f() {
1212

1313
void g(int a[static [[]] 5]); // expected-error {{static array size is a C99 feature, not permitted in C++}}
1414

15+
template<typename T> struct A {
16+
int x[sizeof(T)] __attribute((vector_size(8))); // expected-error {{invalid vector element type 'int [sizeof(T)]'}}
17+
};
18+
19+
typedef int myvect[4] __attribute__((vector_size(16))); // expected-error {{invalid vector element type 'int [4]'}}
20+
void foo(myvect *in, myvect *out) { (*out)[0] = (*in)[0]; }
21+
1522
namespace {
1623
class B {
1724
public:

0 commit comments

Comments
 (0)