diff options
author | Florian Hahn <flo@fhahn.com> | 2025-01-18 20:01:07 +0000 |
---|---|---|
committer | Florian Hahn <flo@fhahn.com> | 2025-01-18 20:01:07 +0000 |
commit | 4233a15c9f8e6f77a00a5770a35b70ab8a2705c6 (patch) | |
tree | 976bf4ed00a88aaf1289791a3dd6308c8bcc5c3e /llvm/lib/Transforms/IPO/FunctionAttrs.cpp | |
parent | 2b1e037adb274c515b6ebe7808cc7da6a5b9c3b3 (diff) | |
download | llvm-4233a15c9f8e6f77a00a5770a35b70ab8a2705c6.zip llvm-4233a15c9f8e6f77a00a5770a35b70ab8a2705c6.tar.gz llvm-4233a15c9f8e6f77a00a5770a35b70ab8a2705c6.tar.bz2 |
[FunctionAttrs] Handle zero writes in initializes inference.
ConstantRange's constructor asserts that the range not empty, except if
lower/upper are min or max values.
Check if the length is strictly positive instead of just non-negative so
std::nullopt is returned when the size is 0. If that's the case, the
access doesn't initialize anything.
This should fix a crash when building on macOS with ASan & UBsan after
https://github.com/llvm/llvm-project/pull/97373 /
https://github.com/llvm/llvm-project/pull/117104 landed:
https://green.lab.llvm.org/job/llvm.org/job/clang-stage2-cmake-RgSan/664/console
Diffstat (limited to 'llvm/lib/Transforms/IPO/FunctionAttrs.cpp')
-rw-r--r-- | llvm/lib/Transforms/IPO/FunctionAttrs.cpp | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/IPO/FunctionAttrs.cpp b/llvm/lib/Transforms/IPO/FunctionAttrs.cpp index 56bfc84..17f946e 100644 --- a/llvm/lib/Transforms/IPO/FunctionAttrs.cpp +++ b/llvm/lib/Transforms/IPO/FunctionAttrs.cpp @@ -633,10 +633,12 @@ ArgumentAccessInfo getArgmentAccessInfo(const Instruction *I, [](Value *Length, std::optional<int64_t> Offset) -> std::optional<ConstantRange> { auto *ConstantLength = dyn_cast<ConstantInt>(Length); - if (ConstantLength && Offset && !ConstantLength->isNegative()) + if (ConstantLength && Offset && + ConstantLength->getValue().isStrictlyPositive()) { return ConstantRange( APInt(64, *Offset, true), APInt(64, *Offset + ConstantLength->getSExtValue(), true)); + } return std::nullopt; }; if (auto *SI = dyn_cast<StoreInst>(I)) { |