[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
This commit is contained in:
Han Zhu
2023-03-09 01:16:04 -08:00
parent 61ed64954b
commit 68a07c156e

View File

@@ -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<VectorType *, 4> CandidateTysCopy = CandidateTys;
for (VectorType *&VTy : CandidateTysCopy) {
unsigned VectorSize = DL.getTypeSizeInBits(VTy).getFixedValue();
unsigned ElementSize =
DL.getTypeSizeInBits(VTy->getElementType()).getFixedValue();