[llvm] f621e76 - [llubi] Make sure the allocated address can be represented (#230656)

via llvm-commits llvm-commits at lists.llvm.org
Sat Oct 10 09:32:30 PDT 2026


Author: Yingwei Zheng
Date: 2026-10-11T00:32:25+08:00
New Revision: f621e76b80d908f393934999f6835235c383bca5

URL: https://github.com/llvm/llvm-project/commit/f621e76b80d908f393934999f6835235c383bca5
DIFF: https://github.com/llvm/llvm-project/commit/f621e76b80d908f393934999f6835235c383bca5.diff

LOG: [llubi] Make sure the allocated address can be represented (#230656)

`deriveFromMemoryObject` assumes that the address always fits in the
address space. Check this in `Context::allocate` to avoid crashes.

The test is generated by DeepSeek-V4.1-Flash.

Added: 
    llvm/test/tools/llubi/alloca_addr_overflow.ll

Modified: 
    llvm/tools/llubi/lib/Context.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/test/tools/llubi/alloca_addr_overflow.ll b/llvm/test/tools/llubi/alloca_addr_overflow.ll
new file mode 100644
index 0000000000000..ee8e80b0b68f4
--- /dev/null
+++ b/llvm/test/tools/llubi/alloca_addr_overflow.ll
@@ -0,0 +1,14 @@
+; NOTE: Assertions have been autogenerated by utils/update_llubi_test_checks.py UTC_ARGS: --version 6
+; RUN: not llubi --verbose < %s 2>&1 | FileCheck %s
+
+target datalayout = "e-p:16:16"
+
+define void @main() {
+  %a = alloca i8, align 65536
+  ret void
+}
+; CHECK: Entering function: main
+; CHECK-NEXT: Stacktrace:
+; CHECK-NEXT: #0   %a = alloca i8, align 65536 at @main <stdin>:7
+; CHECK-NEXT: Error: Insufficient stack space.
+; CHECK-NEXT: error: Execution of function 'main' failed.

diff  --git a/llvm/tools/llubi/lib/Context.cpp b/llvm/tools/llubi/lib/Context.cpp
index e78263a2bab76..ff4d14b5a2c1b 100644
--- a/llvm/tools/llubi/lib/Context.cpp
+++ b/llvm/tools/llubi/lib/Context.cpp
@@ -1109,6 +1109,10 @@ Context::allocate(uint64_t Size, uint64_t Align, StringRef Name, unsigned AS,
   if (SaturatingAdd(UsedMem, AllocateSize) >= MaxMem)
     return nullptr;
   uint64_t AlignedAddr = alignTo(AllocationBase, Align);
+  unsigned AddressBW = DL.getAddressSizeInBits(AS);
+  // Make sure the address can be represented.
+  if (!isUIntN(AddressBW, AlignedAddr))
+    return nullptr;
   auto MemObj = makeIntrusiveRefCnt<MemoryObject>(
       AlignedAddr, Size, Name, AS, InitKind, AllocKind, IsIRGlobalValue);
   MemoryObjects[AlignedAddr] = MemObj;


        


More information about the llvm-commits mailing list