[llvm] [GlobalIsel][AArch64] fix out of range access in regbankselect (PR #92072)
Thorsten Schütt via llvm-commits
llvm-commits at lists.llvm.org
Mon May 13 23:09:43 PDT 2024
https://github.com/tschuett updated https://github.com/llvm/llvm-project/pull/92072
>From c309616a625506c97df139539b81afae61a2c52a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thorsten=20Sch=C3=BCtt?= <schuett at gmail.com>
Date: Tue, 14 May 2024 07:54:38 +0200
Subject: [PATCH 1/2] [GlobalIsel][AArch64] fix out of range access in
regbankselect
Fixes https://github.com/llvm/llvm-project/issues/92062
---
.../AArch64/GISel/AArch64RegisterBankInfo.cpp | 5 ++++-
llvm/test/CodeGen/AArch64/pr92062.ll | 21 +++++++++++++++++++
2 files changed, 25 insertions(+), 1 deletion(-)
create mode 100644 llvm/test/CodeGen/AArch64/pr92062.ll
diff --git a/llvm/lib/Target/AArch64/GISel/AArch64RegisterBankInfo.cpp b/llvm/lib/Target/AArch64/GISel/AArch64RegisterBankInfo.cpp
index 44ba9f0429e67..7785e020eaaf1 100644
--- a/llvm/lib/Target/AArch64/GISel/AArch64RegisterBankInfo.cpp
+++ b/llvm/lib/Target/AArch64/GISel/AArch64RegisterBankInfo.cpp
@@ -600,8 +600,11 @@ bool AArch64RegisterBankInfo::isLoadFromFPType(const MachineInstr &MI) const {
EltTy = GV->getValueType();
// Look at the first element of the struct to determine the type we are
// loading
- while (StructType *StructEltTy = dyn_cast<StructType>(EltTy))
+ while (StructType *StructEltTy = dyn_cast<StructType>(EltTy)) {
+ if (StructEltTy->getNumElements() == 0)
+ break;
EltTy = StructEltTy->getTypeAtIndex(0U);
+ }
// Look at the first element of the array to determine its type
if (isa<ArrayType>(EltTy))
EltTy = EltTy->getArrayElementType();
diff --git a/llvm/test/CodeGen/AArch64/pr92062.ll b/llvm/test/CodeGen/AArch64/pr92062.ll
new file mode 100644
index 0000000000000..0f911d2571f6d
--- /dev/null
+++ b/llvm/test/CodeGen/AArch64/pr92062.ll
@@ -0,0 +1,21 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 4
+; RUN: llc -mtriple=aarch64 -O0 -global-isel -global-isel-abort=2 -verify-machineinstrs %s -o - 2>&1 | FileCheck %s
+
+target triple = "arm64"
+
+ at p = external global { {}, { ptr } }
+
+define void @foo() {
+; CHECK-LABEL: foo:
+; CHECK: // %bb.0: // %bb
+; CHECK-NEXT: adrp x8, :got:p
+; CHECK-NEXT: ldr x8, [x8, :got_lo12:p]
+; CHECK-NEXT: ldr x8, [x8]
+; CHECK-NEXT: mov x9, xzr
+; CHECK-NEXT: str x8, [x9]
+; CHECK-NEXT: ret
+bb:
+ %i1 = load ptr, ptr @p, align 8
+ store ptr %i1, ptr null, align 8
+ ret void
+}
>From 97b2de8611fe6c6b3dbcadd38d8eefd34542150e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thorsten=20Sch=C3=BCtt?= <schuett at gmail.com>
Date: Tue, 14 May 2024 08:09:08 +0200
Subject: [PATCH 2/2] address review comments
---
llvm/test/CodeGen/AArch64/pr92062.ll | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/test/CodeGen/AArch64/pr92062.ll b/llvm/test/CodeGen/AArch64/pr92062.ll
index 0f911d2571f6d..6111ee0fbe18f 100644
--- a/llvm/test/CodeGen/AArch64/pr92062.ll
+++ b/llvm/test/CodeGen/AArch64/pr92062.ll
@@ -1,5 +1,5 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 4
-; RUN: llc -mtriple=aarch64 -O0 -global-isel -global-isel-abort=2 -verify-machineinstrs %s -o - 2>&1 | FileCheck %s
+; RUN: llc -mtriple=aarch64 -O0 -global-isel %s -o - 2>&1 | FileCheck %s
target triple = "arm64"
More information about the llvm-commits
mailing list