[clang] bded889 - [clang][AArch64] Fix C++11 style initialization of typedef'd vectors (#118956)

via cfe-commits cfe-commits at lists.llvm.org
Fri Dec 6 09:27:49 PST 2024


Author: Benjamin Maxwell
Date: 2024-12-06T17:27:46Z
New Revision: bded8890149e55b9abc9c32cb4a9c883c3daad91

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

LOG: [clang][AArch64] Fix C++11 style initialization of typedef'd vectors (#118956)

Previously, this hit an `llvm_unreachable()` assertion as the type of
`vec_t` did not exactly match `__SVInt8_t`, as it was wrapped in a
typedef.

Comparing the canonical types instead allows the types to match
correctly and avoids the crash.

Fixes #107609

Added: 
    

Modified: 
    clang/lib/CodeGen/CGExprScalar.cpp
    clang/test/CodeGenCXX/aarch64-sve-vector-init.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp
index 4ae8a2b22b1bba..bbf68a4c66192a 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -2102,7 +2102,8 @@ Value *ScalarExprEmitter::VisitInitListExpr(InitListExpr *E) {
       Expr *InitVector = E->getInit(0);
 
       // Initialize from another scalable vector of the same type.
-      if (InitVector->getType() == E->getType())
+      if (InitVector->getType().getCanonicalType() ==
+          E->getType().getCanonicalType())
         return Visit(InitVector);
     }
 

diff  --git a/clang/test/CodeGenCXX/aarch64-sve-vector-init.cpp b/clang/test/CodeGenCXX/aarch64-sve-vector-init.cpp
index f9068364d0dcbb..bb71eb5636652d 100644
--- a/clang/test/CodeGenCXX/aarch64-sve-vector-init.cpp
+++ b/clang/test/CodeGenCXX/aarch64-sve-vector-init.cpp
@@ -1212,3 +1212,20 @@ void test_copy_mf8x3(__clang_svmfloat8x3_t a) {
 void test_copy_mf8x4(__clang_svmfloat8x4_t a) {
   __clang_svmfloat8x4_t b{a};
 }
+
+/// Reduced from: https://github.com/llvm/llvm-project/issues/107609
+using vec_t = __SVInt8_t;
+
+// CHECK-LABEL: define dso_local void @_Z20test_copy_s8_typedefu10__SVInt8_t
+// CHECK-SAME: (<vscale x 16 x i8> [[A:%.*]]) #[[ATTR0]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:    [[A_ADDR:%.*]] = alloca <vscale x 16 x i8>, align 16
+// CHECK-NEXT:    [[VEC:%.*]] = alloca <vscale x 16 x i8>, align 16
+// CHECK-NEXT:    store <vscale x 16 x i8> [[A]], ptr [[A_ADDR]], align 16
+// CHECK-NEXT:    [[TMP0:%.*]] = load <vscale x 16 x i8>, ptr [[A_ADDR]], align 16
+// CHECK-NEXT:    store <vscale x 16 x i8> [[TMP0]], ptr [[VEC]], align 16
+// CHECK-NEXT:    ret void
+//
+void test_copy_s8_typedef(__SVInt8_t a) {
+  vec_t vec{a};
+}


        


More information about the cfe-commits mailing list