Skip to content

Commit cb9857a

Browse files
committed
[clang][AArch64] Fix C++11 style initialization of typedef'd vectors
Previously, this hit an `llvm_unreachable()` assertion as the type of `vec_t` did not exactly match the return type of `svdup_s8`, as it was wrapped in a typedef. Comparing the canonical types instead allows the types to match correctly and avoids the crash. Fixes #107609
1 parent 3dbff90 commit cb9857a

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

clang/lib/CodeGen/CGExprScalar.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2102,7 +2102,8 @@ Value *ScalarExprEmitter::VisitInitListExpr(InitListExpr *E) {
21022102
Expr *InitVector = E->getInit(0);
21032103

21042104
// Initialize from another scalable vector of the same type.
2105-
if (InitVector->getType() == E->getType())
2105+
if (InitVector->getType().getCanonicalType() ==
2106+
E->getType().getCanonicalType())
21062107
return Visit(InitVector);
21072108
}
21082109

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 2
2+
// RUN: %clang_cc1 -fclang-abi-compat=latest -triple aarch64-none-linux-gnu -target-feature +sve -emit-llvm -o - %s | FileCheck %s
3+
4+
#include <arm_sve.h>
5+
6+
using vec_t = svint8_t;
7+
8+
/// From: https://github.com/llvm/llvm-project/issues/107609
9+
/// The type of `vec` is a typedef of svint8_t, while svdup_s8 returns the non-typedef'd type.
10+
11+
// CHECK-LABEL: define dso_local <vscale x 16 x i8> @_Z20sve_init_dup_typedefv
12+
// CHECK-SAME: () #[[ATTR0:[0-9]+]] {
13+
// CHECK-NEXT: entry:
14+
// CHECK-NEXT: [[VEC:%.*]] = alloca <vscale x 16 x i8>, align 16
15+
// CHECK-NEXT: [[TMP0:%.*]] = call <vscale x 16 x i8> @llvm.aarch64.sve.dup.x.nxv16i8(i8 2)
16+
// CHECK-NEXT: store <vscale x 16 x i8> [[TMP0]], ptr [[VEC]], align 16
17+
// CHECK-NEXT: [[TMP1:%.*]] = load <vscale x 16 x i8>, ptr [[VEC]], align 16
18+
// CHECK-NEXT: ret <vscale x 16 x i8> [[TMP1]]
19+
//
20+
vec_t sve_init_dup_typedef() {
21+
vec_t vec{svdup_s8(2)};
22+
return vec;
23+
}

0 commit comments

Comments
 (0)