From 80b79ce432bbe12701fd9fe495ff9feeb5e4b9ca Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Tue, 17 Jun 2025 09:30:28 +0200 Subject: [ConstantFolding] Handle reading from type padding (#144330) ReadDataFromGlobal() did not handle reads from the padding of types (in the sense of type store size != type alloc size, rather than struct padding). Return zero in that case. Fixes https://github.com/llvm/llvm-project/issues/144279. --- llvm/lib/Analysis/ConstantFolding.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'llvm/lib/Analysis/ConstantFolding.cpp') diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp index 2b7a438..b58f9b2 100644 --- a/llvm/lib/Analysis/ConstantFolding.cpp +++ b/llvm/lib/Analysis/ConstantFolding.cpp @@ -432,6 +432,10 @@ bool ReadDataFromGlobal(Constant *C, uint64_t ByteOffset, unsigned char *CurPtr, assert(ByteOffset <= DL.getTypeAllocSize(C->getType()) && "Out of range access"); + // Reading type padding, return zero. + if (ByteOffset >= DL.getTypeStoreSize(C->getType())) + return true; + // If this element is zero or undefined, we can just return since *CurPtr is // zero initialized. if (isa(C) || isa(C)) -- cgit v1.1