Skip to content

Commit 51dd3ec

Browse files
[MLIR][OpenMP] Bail early in sortMapIndices if indices are the same (#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.).
1 parent e1b0873 commit 51dd3ec

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4095,6 +4095,12 @@ static void sortMapIndices(llvm::SmallVectorImpl<size_t> &indices,
40954095
llvm::SmallVector<size_t> occludedChildren;
40964096
llvm::sort(
40974097
indices.begin(), indices.end(), [&](const size_t a, const size_t b) {
4098+
// Bail early if we are asked to look at the same index. If we do not
4099+
// bail early, we can end up mistakenly adding indices to
4100+
// occludedChildren. This can occur with some types of libc++ hardening.
4101+
if (a == b)
4102+
return false;
4103+
40984104
auto memberIndicesA = cast<ArrayAttr>(indexAttr[a]);
40994105
auto memberIndicesB = cast<ArrayAttr>(indexAttr[b]);
41004106

0 commit comments

Comments
 (0)