diff --git a/llvm/test/tools/llubi/gep-16-bit-addrspace.ll b/llvm/test/tools/llubi/gep-16-bit-addrspace.ll new file mode 100644 index 000000000000..44333760091e --- /dev/null +++ b/llvm/test/tools/llubi/gep-16-bit-addrspace.ll @@ -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 diff --git a/llvm/tools/llubi/lib/Context.cpp b/llvm/tools/llubi/lib/Context.cpp index 5055b8d1af46..4342c7960f94 100644 --- a/llvm/tools/llubi/lib/Context.cpp +++ b/llvm/tools/llubi/lib/Context.cpp @@ -1054,7 +1054,8 @@ Context::computeGEP(GEPOperator &GEP, unsigned ElementIdx = cast(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; }