[llvm] [WIP][Attributor] Check range size before constant fold load (PR #151359)
Shilei Tian via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 30 09:13:50 PDT 2025
https://github.com/shiltian created https://github.com/llvm/llvm-project/pull/151359
If the range size doesn't match the type size, it might read wrong data.
>From 35143206ab0da81f80c099351b724515ad4091fc Mon Sep 17 00:00:00 2001
From: Shilei Tian <i at tianshilei.me>
Date: Wed, 30 Jul 2025 12:09:52 -0400
Subject: [PATCH] [WIP][Attributor] Check range size before constant fold load
If the range size doesn't match the type size, it might read wrong data.
---
llvm/lib/Transforms/IPO/Attributor.cpp | 3 +++
1 file changed, 3 insertions(+)
diff --git a/llvm/lib/Transforms/IPO/Attributor.cpp b/llvm/lib/Transforms/IPO/Attributor.cpp
index 077d29f7499a4..3b59ebbbb9322 100644
--- a/llvm/lib/Transforms/IPO/Attributor.cpp
+++ b/llvm/lib/Transforms/IPO/Attributor.cpp
@@ -272,6 +272,9 @@ AA::getInitialValueForObj(Attributor &A, const AbstractAttribute &QueryingAA,
}
if (RangePtr && !RangePtr->offsetOrSizeAreUnknown()) {
+ int64_t StorageSize = DL.getTypeStoreSize(&Ty);
+ if (StorageSize != RangePtr->Size)
+ return nullptr;
APInt Offset = APInt(64, RangePtr->Offset);
return ConstantFoldLoadFromConst(Initializer, &Ty, Offset, DL);
}
More information about the llvm-commits
mailing list