aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/ConstantFolding.cpp
diff options
context:
space:
mode:
authorNikita Popov <npopov@redhat.com>2025-06-17 09:30:28 +0200
committerGitHub <noreply@github.com>2025-06-17 09:30:28 +0200
commit80b79ce432bbe12701fd9fe495ff9feeb5e4b9ca (patch)
tree76d8a32e64a80d2d670bcf48d873cc0b3748f588 /llvm/lib/Analysis/ConstantFolding.cpp
parent7e6c1bd3edf4fc19be70587a4ac33a76bab78c02 (diff)
downloadllvm-80b79ce432bbe12701fd9fe495ff9feeb5e4b9ca.zip
llvm-80b79ce432bbe12701fd9fe495ff9feeb5e4b9ca.tar.gz
llvm-80b79ce432bbe12701fd9fe495ff9feeb5e4b9ca.tar.bz2
[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.
Diffstat (limited to 'llvm/lib/Analysis/ConstantFolding.cpp')
-rw-r--r--llvm/lib/Analysis/ConstantFolding.cpp4
1 files changed, 4 insertions, 0 deletions
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<ConstantAggregateZero>(C) || isa<UndefValue>(C))