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 &indices, llvm::SmallVector 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(indexAttr[a]); auto memberIndicesB = cast(indexAttr[b]);