[clang] 350d43f - Fix a bug where an extended vector of __fp16 was being converted to a

Akira Hatanaka via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 24 18:07:56 PDT 2022


Author: Akira Hatanaka
Date: 2022-03-24T18:06:10-07:00
New Revision: 350d43f1efd711d057cdb53decabb6f32491dff0

URL: https://github.com/llvm/llvm-project/commit/350d43f1efd711d057cdb53decabb6f32491dff0
DIFF: https://github.com/llvm/llvm-project/commit/350d43f1efd711d057cdb53decabb6f32491dff0.diff

LOG: Fix a bug where an extended vector of __fp16 was being converted to a
generic vector type

rdar://86109177

Added: 
    

Modified: 
    clang/lib/Sema/SemaExpr.cpp
    clang/test/Sema/fp16vec-sema.c

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 9ad279788660b..ae48db03e06c9 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -10069,9 +10069,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.

diff  --git a/clang/test/Sema/fp16vec-sema.c b/clang/test/Sema/fp16vec-sema.c
index f61ad4c91e89d..80936cd622f7c 100644
--- a/clang/test/Sema/fp16vec-sema.c
+++ b/clang/test/Sema/fp16vec-sema.c
@@ -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;
@@ -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;
+}


        


More information about the cfe-commits mailing list