Skip to content

Fix a bug where an extended vector of __fp16 was being converted to a generic vector type #4125

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions clang/lib/Sema/SemaExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9915,9 +9915,11 @@ static bool tryVectorConvertAndSplat(Sema &S, ExprResult *scalar,
static ExprResult convertVector(Expr *E, QualType ElementType, Sema &S) {
const auto *VecTy = E->getType()->getAs<VectorType>();
assert(VecTy && "Expression E must be a vector");
QualType NewVecTy = S.Context.getVectorType(ElementType,
VecTy->getNumElements(),
VecTy->getVectorKind());
QualType NewVecTy =
VecTy->isExtVectorType()
? S.Context.getExtVectorType(ElementType, VecTy->getNumElements())
: S.Context.getVectorType(ElementType, VecTy->getNumElements(),
VecTy->getVectorKind());

// Look through the implicit cast. Return the subexpression if its type is
// NewVecTy.
Expand Down
6 changes: 6 additions & 0 deletions clang/test/Sema/fp16vec-sema.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ typedef __fp16 half4 __attribute__ ((vector_size (8)));
typedef float float4 __attribute__ ((vector_size (16)));
typedef short short4 __attribute__ ((vector_size (8)));
typedef int int4 __attribute__ ((vector_size (16)));
typedef __fp16 exthalf4 __attribute__((ext_vector_type(4)));

half4 hv0, hv1;
float4 fv0, fv1;
Expand Down Expand Up @@ -51,3 +52,8 @@ void testFP16Vec(int c) {
hv0++; // expected-error{{cannot increment value of type}}
++hv0; // expected-error{{cannot increment value of type}}
}

void testExtVec(exthalf4 a) {
// Check that the type of "(-a)" is exthalf4.
__fp16 t0 = (-a).z;
}