Skip to content

Commit

Permalink
[clang][AArch64] Fix C++11 style initialization of typedef'd vectors (#…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
MacDue authored Dec 6, 2024
1 parent b9aa155 commit bded889
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
3 changes: 2 additions & 1 deletion clang/lib/CodeGen/CGExprScalar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
17 changes: 17 additions & 0 deletions clang/test/CodeGenCXX/aarch64-sve-vector-init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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};
}

0 comments on commit bded889

Please sign in to comment.