[llvm] [OpenMPOpt] avoid OOB array write (PR #178686)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 29 07:55:28 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-transforms
Author: Jameson Nash (vtjnash)
<details>
<summary>Changes</summary>
When analysis reaches code with UB at runtime, this write needs to be ignored to avoid corrupting memory with UB at compile time.
Drive-by finding during review of
https://github.com/llvm/llvm-project/pull/178356.
---
Full diff: https://github.com/llvm/llvm-project/pull/178686.diff
1 Files Affected:
- (modified) llvm/lib/Transforms/IPO/OpenMPOpt.cpp (+5-2)
``````````diff
diff --git a/llvm/lib/Transforms/IPO/OpenMPOpt.cpp b/llvm/lib/Transforms/IPO/OpenMPOpt.cpp
index 1f52f9a78b907..f415fa3cfcf97 100644
--- a/llvm/lib/Transforms/IPO/OpenMPOpt.cpp
+++ b/llvm/lib/Transforms/IPO/OpenMPOpt.cpp
@@ -909,8 +909,11 @@ struct OffloadArray {
GetPointerBaseWithConstantOffset(S->getPointerOperand(), Offset, DL);
if (Dst == &Array) {
int64_t Idx = Offset / PointerSize;
- StoredValues[Idx] = getUnderlyingObject(S->getValueOperand());
- LastAccesses[Idx] = S;
+ // Ignore updates that must be UB (probably in dead code at runtime)
+ if ((uint64_t)Idx < NumValues) {
+ StoredValues[Idx] = getUnderlyingObject(S->getValueOperand());
+ LastAccesses[Idx] = S;
+ }
}
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/178686
More information about the llvm-commits
mailing list