Skip to content

Commit 58b73ef

Browse files
authored
Fix a bug where an extended vector of __fp16 was being converted to a (#4125)
generic vector type rdar://86109177 (cherry picked from commit 350d43f)
1 parent 4f9defc commit 58b73ef

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

clang/lib/Sema/SemaExpr.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9915,9 +9915,11 @@ static bool tryVectorConvertAndSplat(Sema &S, ExprResult *scalar,
99159915
static ExprResult convertVector(Expr *E, QualType ElementType, Sema &S) {
99169916
const auto *VecTy = E->getType()->getAs<VectorType>();
99179917
assert(VecTy && "Expression E must be a vector");
9918-
QualType NewVecTy = S.Context.getVectorType(ElementType,
9919-
VecTy->getNumElements(),
9920-
VecTy->getVectorKind());
9918+
QualType NewVecTy =
9919+
VecTy->isExtVectorType()
9920+
? S.Context.getExtVectorType(ElementType, VecTy->getNumElements())
9921+
: S.Context.getVectorType(ElementType, VecTy->getNumElements(),
9922+
VecTy->getVectorKind());
99219923

99229924
// Look through the implicit cast. Return the subexpression if its type is
99239925
// NewVecTy.

clang/test/Sema/fp16vec-sema.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ typedef __fp16 half4 __attribute__ ((vector_size (8)));
44
typedef float float4 __attribute__ ((vector_size (16)));
55
typedef short short4 __attribute__ ((vector_size (8)));
66
typedef int int4 __attribute__ ((vector_size (16)));
7+
typedef __fp16 exthalf4 __attribute__((ext_vector_type(4)));
78

89
half4 hv0, hv1;
910
float4 fv0, fv1;
@@ -51,3 +52,8 @@ void testFP16Vec(int c) {
5152
hv0++; // expected-error{{cannot increment value of type}}
5253
++hv0; // expected-error{{cannot increment value of type}}
5354
}
55+
56+
void testExtVec(exthalf4 a) {
57+
// Check that the type of "(-a)" is exthalf4.
58+
__fp16 t0 = (-a).z;
59+
}

0 commit comments

Comments
 (0)