Skip to content

Commit c6d5546

Browse files
Thorsten Schütttstellar
Thorsten Schütt
authored andcommitted
[GlobalIsel][AArch64] fix out of range access in regbankselect (#92072)
Fixes #92062 (cherry picked from commit d422e90)
1 parent 9acb41b commit c6d5546

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

llvm/lib/Target/AArch64/GISel/AArch64RegisterBankInfo.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -623,8 +623,11 @@ bool AArch64RegisterBankInfo::isLoadFromFPType(const MachineInstr &MI) const {
623623
EltTy = GV->getValueType();
624624
// Look at the first element of the struct to determine the type we are
625625
// loading
626-
while (StructType *StructEltTy = dyn_cast<StructType>(EltTy))
626+
while (StructType *StructEltTy = dyn_cast<StructType>(EltTy)) {
627+
if (StructEltTy->getNumElements() == 0)
628+
break;
627629
EltTy = StructEltTy->getTypeAtIndex(0U);
630+
}
628631
// Look at the first element of the array to determine its type
629632
if (isa<ArrayType>(EltTy))
630633
EltTy = EltTy->getArrayElementType();

llvm/test/CodeGen/AArch64/pr92062.ll

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 4
2+
; RUN: llc -mtriple=aarch64 -O0 -global-isel %s -o - 2>&1 | FileCheck %s
3+
4+
target triple = "arm64"
5+
6+
@p = external global { {}, { ptr } }
7+
8+
define void @foo() {
9+
; CHECK-LABEL: foo:
10+
; CHECK: // %bb.0: // %bb
11+
; CHECK-NEXT: adrp x8, :got:p
12+
; CHECK-NEXT: ldr x8, [x8, :got_lo12:p]
13+
; CHECK-NEXT: ldr x8, [x8]
14+
; CHECK-NEXT: mov x9, xzr
15+
; CHECK-NEXT: str x8, [x9]
16+
; CHECK-NEXT: ret
17+
bb:
18+
%i1 = load ptr, ptr @p, align 8
19+
store ptr %i1, ptr null, align 8
20+
ret void
21+
}

0 commit comments

Comments
 (0)