[llubi] Truncate struct field offsets exceeding the pointer index width (#213471)
Update computeGEP to implicitly truncate struct field offsets. This fixes crashes in the new test, where the field offset does not fit in the index width. Related https://github.com/llvm/llvm-project/pull/213436 PR: https://github.com/llvm/llvm-project/pull/213471
This commit is contained in:
parent
4671437fb0
commit
8cb8e872e7
2 changed files with 20 additions and 1 deletions
18
llvm/test/tools/llubi/gep-16-bit-addrspace.ll
Normal file
18
llvm/test/tools/llubi/gep-16-bit-addrspace.ll
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
; NOTE: Assertions have been autogenerated by utils/update_llubi_test_checks.py UTC_ARGS: --version 6
|
||||
; RUN: llubi --verbose < %s 2>&1 | FileCheck %s
|
||||
|
||||
target datalayout = "e-m:e-p:16:16"
|
||||
|
||||
%s = type { [65536 x i8], i8 }
|
||||
|
||||
; Offset of the struct's second field does not fit into a 16 bit pointer.
|
||||
define void @main() {
|
||||
%p = alloca i32
|
||||
%a = getelementptr %s, ptr %p, i32 0, i32 1
|
||||
ret void
|
||||
}
|
||||
; CHECK: Entering function: main
|
||||
; CHECK-NEXT: %p = alloca i32, align 4 => ptr 0x8 [p]
|
||||
; CHECK-NEXT: %a = getelementptr %s, ptr %p, i32 0, i32 1 => ptr 0x8 [p]
|
||||
; CHECK-NEXT: ret void
|
||||
; CHECK-NEXT: Exiting function: main
|
||||
|
|
@ -1054,7 +1054,8 @@ Context::computeGEP(GEPOperator &GEP,
|
|||
unsigned ElementIdx = cast<ConstantInt>(V)->getZExtValue();
|
||||
const StructLayout *SL = DL.getStructLayout(STy);
|
||||
// Element offset is in bytes.
|
||||
ApplyScaledOffset(APInt(IndexBitWidth, SL->getElementOffset(ElementIdx)),
|
||||
ApplyScaledOffset(APInt(IndexBitWidth, SL->getElementOffset(ElementIdx),
|
||||
/*isSigned=*/false, /*implicitTrunc=*/true),
|
||||
APInt(IndexBitWidth, 1));
|
||||
continue;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue