Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Dec 6, 2024

Conversation

MacDue
Copy link
Member

@MacDue MacDue commented Dec 6, 2024

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

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 llvm#107609
@MacDue MacDue requested a review from paulwalker-arm December 6, 2024 11:49
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:codegen labels Dec 6, 2024
@llvmbot
Copy link
Member

llvmbot commented Dec 6, 2024

@llvm/pr-subscribers-clang-codegen

@llvm/pr-subscribers-clang

Author: Benjamin Maxwell (MacDue)

Changes

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


Full diff: https://github.com/llvm/llvm-project/pull/118956.diff

2 Files Affected:

  • (modified) clang/lib/CodeGen/CGExprScalar.cpp (+2-1)
  • (added) clang/test/CodeGenCXX/aarch64-sve-vector-init-typedef.cpp (+23)
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;
+}

@MacDue MacDue merged commit bded889 into llvm:main Dec 6, 2024
8 checks passed
@MacDue MacDue deleted the fix_typedef_init_sve branch December 6, 2024 17:27
broxigarchen pushed a commit to broxigarchen/llvm-project that referenced this pull request Dec 10, 2024
…lvm#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 llvm#107609
chrsmcgrr pushed a commit to RooflineAI/llvm-project that referenced this pull request Dec 12, 2024
…lvm#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 llvm#107609
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:codegen clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

clang++-17, clang++-18 and clang++-19 segfault when using aliased ARM64 SVE intrinsic types
3 participants