[clang] [clang][AArch64] Fix C++11 style initialization of typedef'd vectors (PR #118956)
Benjamin Maxwell via cfe-commits
cfe-commits at lists.llvm.org
Fri Dec 6 06:06:39 PST 2024
https://github.com/MacDue updated https://github.com/llvm/llvm-project/pull/118956
>From cb9857aad6f84e4ac473f572a828ea5db6d4fd58 Mon Sep 17 00:00:00 2001
From: Benjamin Maxwell <benjamin.maxwell at arm.com>
Date: Fri, 6 Dec 2024 11:42:11 +0000
Subject: [PATCH 1/2] [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
---
clang/lib/CodeGen/CGExprScalar.cpp | 3 ++-
.../aarch64-sve-vector-init-typedef.cpp | 23 +++++++++++++++++++
2 files changed, 25 insertions(+), 1 deletion(-)
create mode 100644 clang/test/CodeGenCXX/aarch64-sve-vector-init-typedef.cpp
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-typedef.cpp b/clang/test/CodeGenCXX/aarch64-sve-vector-init-typedef.cpp
new file mode 100644
index 00000000000000..3ac0fc5f39a566
--- /dev/null
+++ b/clang/test/CodeGenCXX/aarch64-sve-vector-init-typedef.cpp
@@ -0,0 +1,23 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 2
+// RUN: %clang_cc1 -fclang-abi-compat=latest -triple aarch64-none-linux-gnu -target-feature +sve -emit-llvm -o - %s | FileCheck %s
+
+#include <arm_sve.h>
+
+using vec_t = svint8_t;
+
+/// From: https://github.com/llvm/llvm-project/issues/107609
+/// The type of `vec` is a typedef of svint8_t, while svdup_s8 returns the non-typedef'd type.
+
+// CHECK-LABEL: define dso_local <vscale x 16 x i8> @_Z20sve_init_dup_typedefv
+// CHECK-SAME: () #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT: entry:
+// CHECK-NEXT: [[VEC:%.*]] = alloca <vscale x 16 x i8>, align 16
+// CHECK-NEXT: [[TMP0:%.*]] = call <vscale x 16 x i8> @llvm.aarch64.sve.dup.x.nxv16i8(i8 2)
+// CHECK-NEXT: store <vscale x 16 x i8> [[TMP0]], ptr [[VEC]], align 16
+// CHECK-NEXT: [[TMP1:%.*]] = load <vscale x 16 x i8>, ptr [[VEC]], align 16
+// CHECK-NEXT: ret <vscale x 16 x i8> [[TMP1]]
+//
+vec_t sve_init_dup_typedef() {
+ vec_t vec{svdup_s8(2)};
+ return vec;
+}
>From 1f6b3958fc05f8630012097c89d00492675c6b9b Mon Sep 17 00:00:00 2001
From: Benjamin Maxwell <benjamin.maxwell at arm.com>
Date: Fri, 6 Dec 2024 14:05:16 +0000
Subject: [PATCH 2/2] Fixups
---
.../aarch64-sve-vector-init-typedef.cpp | 23 -------------------
.../CodeGenCXX/aarch64-sve-vector-init.cpp | 21 +++++++++++++++++
2 files changed, 21 insertions(+), 23 deletions(-)
delete mode 100644 clang/test/CodeGenCXX/aarch64-sve-vector-init-typedef.cpp
diff --git a/clang/test/CodeGenCXX/aarch64-sve-vector-init-typedef.cpp b/clang/test/CodeGenCXX/aarch64-sve-vector-init-typedef.cpp
deleted file mode 100644
index 3ac0fc5f39a566..00000000000000
--- a/clang/test/CodeGenCXX/aarch64-sve-vector-init-typedef.cpp
+++ /dev/null
@@ -1,23 +0,0 @@
-// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 2
-// RUN: %clang_cc1 -fclang-abi-compat=latest -triple aarch64-none-linux-gnu -target-feature +sve -emit-llvm -o - %s | FileCheck %s
-
-#include <arm_sve.h>
-
-using vec_t = svint8_t;
-
-/// From: https://github.com/llvm/llvm-project/issues/107609
-/// The type of `vec` is a typedef of svint8_t, while svdup_s8 returns the non-typedef'd type.
-
-// CHECK-LABEL: define dso_local <vscale x 16 x i8> @_Z20sve_init_dup_typedefv
-// CHECK-SAME: () #[[ATTR0:[0-9]+]] {
-// CHECK-NEXT: entry:
-// CHECK-NEXT: [[VEC:%.*]] = alloca <vscale x 16 x i8>, align 16
-// CHECK-NEXT: [[TMP0:%.*]] = call <vscale x 16 x i8> @llvm.aarch64.sve.dup.x.nxv16i8(i8 2)
-// CHECK-NEXT: store <vscale x 16 x i8> [[TMP0]], ptr [[VEC]], align 16
-// CHECK-NEXT: [[TMP1:%.*]] = load <vscale x 16 x i8>, ptr [[VEC]], align 16
-// CHECK-NEXT: ret <vscale x 16 x i8> [[TMP1]]
-//
-vec_t sve_init_dup_typedef() {
- vec_t vec{svdup_s8(2)};
- return vec;
-}
diff --git a/clang/test/CodeGenCXX/aarch64-sve-vector-init.cpp b/clang/test/CodeGenCXX/aarch64-sve-vector-init.cpp
index f9068364d0dcbb..407510e957f88c 100644
--- a/clang/test/CodeGenCXX/aarch64-sve-vector-init.cpp
+++ b/clang/test/CodeGenCXX/aarch64-sve-vector-init.cpp
@@ -1,6 +1,8 @@
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 2
// RUN: %clang_cc1 -fclang-abi-compat=latest -triple aarch64-none-linux-gnu -target-feature +sve -emit-llvm -o - %s | FileCheck %s
+#include <arm_sve.h>
+
// CHECK-LABEL: define dso_local void @_Z11test_localsv
// CHECK-SAME: () #[[ATTR0:[0-9]+]] {
// CHECK-NEXT: entry:
@@ -1212,3 +1214,22 @@ void test_copy_mf8x3(__clang_svmfloat8x3_t a) {
void test_copy_mf8x4(__clang_svmfloat8x4_t a) {
__clang_svmfloat8x4_t b{a};
}
+
+using vec_t = svint8_t;
+
+/// From: https://github.com/llvm/llvm-project/issues/107609
+/// The type of `vec` is a typedef of svint8_t, while svdup_s8 returns the non-typedef'd type.
+
+// CHECK-LABEL: define dso_local <vscale x 16 x i8> @_Z20sve_init_dup_typedefv
+// CHECK-SAME: () #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT: entry:
+// CHECK-NEXT: [[VEC:%.*]] = alloca <vscale x 16 x i8>, align 16
+// CHECK-NEXT: [[TMP0:%.*]] = call <vscale x 16 x i8> @llvm.aarch64.sve.dup.x.nxv16i8(i8 2)
+// CHECK-NEXT: store <vscale x 16 x i8> [[TMP0]], ptr [[VEC]], align 16
+// CHECK-NEXT: [[TMP1:%.*]] = load <vscale x 16 x i8>, ptr [[VEC]], align 16
+// CHECK-NEXT: ret <vscale x 16 x i8> [[TMP1]]
+//
+vec_t sve_init_dup_typedef() {
+ vec_t vec{svdup_s8(2)};
+ return vec;
+}
More information about the cfe-commits
mailing list