From 68a07c156e90e76a2129308fe28815e709276424 Mon Sep 17 00:00:00 2001 From: Han Zhu Date: Thu, 9 Mar 2023 01:16:04 -0800 Subject: [PATCH] [SROA] Fix bug where CandidateTys is appended while being iterated Fix a crash when compiling Skia. See https://reviews.llvm.org/D143225#4180342 for more details --- llvm/lib/Transforms/Scalar/SROA.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/llvm/lib/Transforms/Scalar/SROA.cpp b/llvm/lib/Transforms/Scalar/SROA.cpp index 27b6ee8..f221ecf 100644 --- a/llvm/lib/Transforms/Scalar/SROA.cpp +++ b/llvm/lib/Transforms/Scalar/SROA.cpp @@ -2030,7 +2030,10 @@ static VectorType *isVectorPromotionViable(Partition &P, const DataLayout &DL) { if (!VectorType::isValidElementType(Ty)) continue; unsigned TypeSize = DL.getTypeSizeInBits(Ty).getFixedValue(); - for (VectorType *&VTy : CandidateTys) { + // Make a copy of CandidateTys and iterate through it, because we might + // append to CandidateTys in the loop. + SmallVector CandidateTysCopy = CandidateTys; + for (VectorType *&VTy : CandidateTysCopy) { unsigned VectorSize = DL.getTypeSizeInBits(VTy).getFixedValue(); unsigned ElementSize = DL.getTypeSizeInBits(VTy->getElementType()).getFixedValue(); -- 2.7.4