[llvm] [OpenMPOpt] avoid OOB array write (PR #178686)
Jameson Nash via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 29 07:54:53 PST 2026
https://github.com/vtjnash created https://github.com/llvm/llvm-project/pull/178686
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.
>From 96e27c7f791e57e97b0a71b9aaf5b257dc8ec5d1 Mon Sep 17 00:00:00 2001
From: Jameson Nash <vtjnash at gmail.com>
Date: Thu, 29 Jan 2026 10:49:14 -0500
Subject: [PATCH] [OpenMPOpt] avoid OOB array write
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.
---
llvm/lib/Transforms/IPO/OpenMPOpt.cpp | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
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;
+ }
}
}
More information about the llvm-commits
mailing list