[clang] f0b2a1a - ASTMatchers: Avoid using SmallVector::set_size()

Duncan P. N. Exon Smith via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 11 17:01:53 PST 2022


Author: Duncan P. N. Exon Smith
Date: 2022-01-11T17:01:46-08:00
New Revision: f0b2a1a629dab17f2ea161a9281d8dc63b37a7a0

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

LOG: ASTMatchers: Avoid using SmallVector::set_size()

Update `variadicMatcherDescriptor` to assert on reserved capacity and
to call `emplace_back()` instead of calling `set_size()` and constructing
the element in-place.

Differential Revision: https://reviews.llvm.org/D115379

Added: 
    

Modified: 
    clang/lib/ASTMatchers/Dynamic/Marshallers.h

Removed: 
    


################################################################################
diff  --git a/clang/lib/ASTMatchers/Dynamic/Marshallers.h b/clang/lib/ASTMatchers/Dynamic/Marshallers.h
index 2b4d9b6a7e852..3e9c4f31b84d3 100644
--- a/clang/lib/ASTMatchers/Dynamic/Marshallers.h
+++ b/clang/lib/ASTMatchers/Dynamic/Marshallers.h
@@ -524,8 +524,9 @@ variadicMatcherDescriptor(StringRef MatcherName, SourceRange NameRange,
       }
       return {};
     }
-    InnerArgs.set_size(i + 1);
-    InnerArgsPtr[i] = new (&InnerArgs[i]) ArgT(ArgTraits::get(Value));
+    assert(InnerArgs.size() < InnerArgs.capacity());
+    InnerArgs.emplace_back(ArgTraits::get(Value));
+    InnerArgsPtr[i] = &InnerArgs[i];
   }
   return outvalueToVariantMatcher(Func(InnerArgsPtr));
 }


        


More information about the cfe-commits mailing list