[llvm] 68a07c1 - [SROA] Fix bug where CandidateTys is appended while being iterated

Han Zhu via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 9 01:20:35 PST 2023


Author: Han Zhu
Date: 2023-03-09T01:20:08-08:00
New Revision: 68a07c156e90e76a2129308fe28815e709276424

URL: https://github.com/llvm/llvm-project/commit/68a07c156e90e76a2129308fe28815e709276424
DIFF: https://github.com/llvm/llvm-project/commit/68a07c156e90e76a2129308fe28815e709276424.diff

LOG: [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

Added: 
    

Modified: 
    llvm/lib/Transforms/Scalar/SROA.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/SROA.cpp b/llvm/lib/Transforms/Scalar/SROA.cpp
index 27b6ee86e0511..f221ecf548ffe 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<VectorType *, 4> CandidateTysCopy = CandidateTys;
+    for (VectorType *&VTy : CandidateTysCopy) {
       unsigned VectorSize = DL.getTypeSizeInBits(VTy).getFixedValue();
       unsigned ElementSize =
           DL.getTypeSizeInBits(VTy->getElementType()).getFixedValue();


        


More information about the llvm-commits mailing list