[Mlir-commits] [mlir] [MLIR][OpenMP] Bail early in sortMapIndices if indices are the same (PR #169474)
Aiden Grossman
llvmlistbot at llvm.org
Tue Nov 25 01:05:09 PST 2025
https://github.com/boomanaiden154 created https://github.com/llvm/llvm-project/pull/169474
If we are given the same index in the comparator callback, simply return false. Otherwise we will end up adding invalid items to occludedChildren, causing extra items to get removed that should not be, resulting in failures that manifest in different forms (assertions, asan failures, ubsan failures, etc.).
>From f9e3946a2fb772f86f6fbebc044078dab4e548d0 Mon Sep 17 00:00:00 2001
From: Aiden Grossman <aidengrossman at google.com>
Date: Tue, 25 Nov 2025 09:00:18 +0000
Subject: [PATCH] [MLIR][OpenMP] Bail early in sortMapIndices if indices are
the same
If we are given the same index in the comparator callback, simply return
false. Otherwise we will end up adding invalid items to
occludedChildren, causing extra items to get removed that should not be,
resulting in failures that manifest in different forms (assertions, asan
failures, ubsan failures, etc.).
---
.../LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
index 5511f4f1af1ad..98775c2d18bd4 100644
--- a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
@@ -4095,6 +4095,12 @@ static void sortMapIndices(llvm::SmallVectorImpl<size_t> &indices,
llvm::SmallVector<size_t> occludedChildren;
llvm::sort(
indices.begin(), indices.end(), [&](const size_t a, const size_t b) {
+ // Bail early if we are asked to look at the same index. If we do not
+ // bail early, we can end up mistakenly adding indices to
+ // occludedChildren. This can occur with some types of libc++ hardening.
+ if (a == b)
+ return false;
+
auto memberIndicesA = cast<ArrayAttr>(indexAttr[a]);
auto memberIndicesB = cast<ArrayAttr>(indexAttr[b]);
More information about the Mlir-commits
mailing list