Skip to content

Commit

Permalink
[GlobalIsel][AArch64] fix out of range access in regbankselect (#92072)
Browse files Browse the repository at this point in the history
Fixes #92062

(cherry picked from commit d422e90)
  • Loading branch information
tschuett authored and tstellar committed May 16, 2024
1 parent 9acb41b commit c6d5546
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
5 changes: 4 additions & 1 deletion llvm/lib/Target/AArch64/GISel/AArch64RegisterBankInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -623,8 +623,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();
Expand Down
21 changes: 21 additions & 0 deletions llvm/test/CodeGen/AArch64/pr92062.ll
Original file line number Diff line number Diff line change
@@ -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 %s -o - 2>&1 | FileCheck %s

target triple = "arm64"

@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
}

0 comments on commit c6d5546

Please sign in to comment.