diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h --- a/clang/lib/CodeGen/CodeGenFunction.h +++ b/clang/lib/CodeGen/CodeGenFunction.h @@ -722,7 +722,7 @@ ActiveFlag.isValid()}; size_t OldSize = LifetimeExtendedCleanupStack.size(); - LifetimeExtendedCleanupStack.resize( + LifetimeExtendedCleanupStack.resize_for_overwrite( LifetimeExtendedCleanupStack.size() + sizeof(Header) + Header.Size + (Header.IsConditional ? sizeof(ActiveFlag) : 0)); diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -2090,7 +2090,7 @@ // Convert List to what ConstantArray needs. SmallVector UsedArray; - UsedArray.resize(List.size()); + UsedArray.resize_for_overwrite(List.size()); for (unsigned i = 0, e = List.size(); i != e; ++i) { UsedArray[i] = llvm::ConstantExpr::getPointerBitCastOrAddrSpaceCast( diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -285,8 +285,8 @@ Lines.clear(); while (!PPLevelBranchIndex.empty() && PPLevelBranchIndex.back() + 1 >= PPLevelBranchCount.back()) { - PPLevelBranchIndex.resize(PPLevelBranchIndex.size() - 1); - PPLevelBranchCount.resize(PPLevelBranchCount.size() - 1); + PPLevelBranchIndex.pop_back(); + PPLevelBranchCount.pop_back(); } if (!PPLevelBranchIndex.empty()) { ++PPLevelBranchIndex.back(); diff --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp --- a/clang/lib/Lex/Lexer.cpp +++ b/clang/lib/Lex/Lexer.cpp @@ -355,7 +355,7 @@ return StringRef(tokenBegin, length); // Hard case, we need to relex the characters into the string. - buffer.resize(length); + buffer.resize_for_overwrite(length); buffer.resize(getSpellingSlow(token, tokenBegin, options, buffer.data())); return StringRef(buffer.data(), buffer.size()); } diff --git a/clang/lib/Lex/LiteralSupport.cpp b/clang/lib/Lex/LiteralSupport.cpp --- a/clang/lib/Lex/LiteralSupport.cpp +++ b/clang/lib/Lex/LiteralSupport.cpp @@ -1281,7 +1281,7 @@ "Assumes sizeof(wchar) on target is <= 64"); SmallVector codepoint_buffer; - codepoint_buffer.resize(end - begin); + codepoint_buffer.resize_for_overwrite(end - begin); uint32_t *buffer_begin = &codepoint_buffer.front(); uint32_t *buffer_end = buffer_begin + codepoint_buffer.size(); @@ -1543,11 +1543,11 @@ SizeBound *= CharByteWidth; // Size the temporary buffer to hold the result string data. - ResultBuf.resize(SizeBound); + ResultBuf.resize_for_overwrite(SizeBound); // Likewise, but for each string piece. SmallString<512> TokenBuf; - TokenBuf.resize(MaxTokenLength); + TokenBuf.resize_for_overwrite(MaxTokenLength); // Loop over all the strings, getting their spelling, and expanding them to // wide strings as appropriate. @@ -1835,7 +1835,7 @@ unsigned ByteNo) const { // Get the spelling of the token. SmallString<32> SpellingBuffer; - SpellingBuffer.resize(Tok.getLength()); + SpellingBuffer.resize_for_overwrite(Tok.getLength()); bool StringInvalid = false; const char *SpellingPtr = &SpellingBuffer[0]; diff --git a/clang/lib/Lex/Preprocessor.cpp b/clang/lib/Lex/Preprocessor.cpp --- a/clang/lib/Lex/Preprocessor.cpp +++ b/clang/lib/Lex/Preprocessor.cpp @@ -472,7 +472,7 @@ // Resize the buffer if we need to copy into it. if (Tok.needsCleaning()) - Buffer.resize(Tok.getLength()); + Buffer.resize_for_overwrite(Tok.getLength()); const char *Ptr = Buffer.data(); unsigned Len = getSpelling(Tok, Ptr, Invalid); diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -3447,7 +3447,7 @@ static void ConvertUTF8ToWideString(unsigned CharByteWidth, StringRef Source, SmallString<32> &Target) { - Target.resize(CharByteWidth * (Source.size() + 1)); + Target.resize_for_overwrite(CharByteWidth * (Source.size() + 1)); char *ResultPtr = &Target[0]; const llvm::UTF8 *ErrorPtr; bool success = @@ -3663,7 +3663,7 @@ // the buffer in case the token is copied to the buffer. If getSpelling() // returns a StringRef to the memory buffer, it should have a null char at // the EOF, so it is also safe. - SpellingBuffer.resize(Tok.getLength() + 1); + SpellingBuffer.resize_for_overwrite(Tok.getLength() + 1); // Get the spelling of the token, which eliminates trigraphs, etc. bool Invalid = false; diff --git a/lldb/source/Core/ValueObject.cpp b/lldb/source/Core/ValueObject.cpp --- a/lldb/source/Core/ValueObject.cpp +++ b/lldb/source/Core/ValueObject.cpp @@ -192,7 +192,7 @@ if (!first_update && CanProvideValue()) { need_compare_checksums = true; - old_checksum.resize(m_value_checksum.size()); + old_checksum.resize_for_overwrite(m_value_checksum.size()); std::copy(m_value_checksum.begin(), m_value_checksum.end(), old_checksum.begin()); } diff --git a/lldb/source/Host/common/LZMA.cpp b/lldb/source/Host/common/LZMA.cpp --- a/lldb/source/Host/common/LZMA.cpp +++ b/lldb/source/Host/common/LZMA.cpp @@ -122,7 +122,7 @@ if (auto err = uncompressedSize.takeError()) return err; - Uncompressed.resize(*uncompressedSize); + Uncompressed.resize_for_overwrite(*uncompressedSize); // Decompress xz buffer to buffer. uint64_t memlimit = UINT64_MAX; diff --git a/lldb/source/Utility/VASprintf.cpp b/lldb/source/Utility/VASprintf.cpp --- a/lldb/source/Utility/VASprintf.cpp +++ b/lldb/source/Utility/VASprintf.cpp @@ -25,7 +25,7 @@ va_list copy_args; va_copy(copy_args, args); - buf.resize(buf.capacity()); + buf.resize_for_overwrite(buf.capacity()); // Write up to `capacity` bytes, ignoring the current size. int length = ::vsnprintf(buf.data(), buf.size(), fmt, args); if (length < 0) { @@ -37,7 +37,7 @@ if (size_t(length) >= buf.size()) { // The error formatted string didn't fit into our buffer, resize it to the // exact needed size, and retry - buf.resize(length + 1); + buf.resize_for_overwrite(length + 1); length = ::vsnprintf(buf.data(), buf.size(), fmt, copy_args); if (length < 0) { buf = error; diff --git a/llvm/lib/CodeGen/MachineLICM.cpp b/llvm/lib/CodeGen/MachineLICM.cpp --- a/llvm/lib/CodeGen/MachineLICM.cpp +++ b/llvm/lib/CodeGen/MachineLICM.cpp @@ -357,9 +357,8 @@ if (PreRegAlloc) { // Estimate register pressure during pre-regalloc pass. unsigned NumRPS = TRI->getNumRegPressureSets(); - RegPressure.resize(NumRPS); - std::fill(RegPressure.begin(), RegPressure.end(), 0); - RegLimit.resize(NumRPS); + RegPressure.assign(NumRPS, 0); + RegLimit.resize_for_overwrite(NumRPS); for (unsigned i = 0, e = NumRPS; i != e; ++i) RegLimit[i] = TRI->getRegPressureSetLimit(MF, i); } diff --git a/llvm/lib/CodeGen/TargetSchedule.cpp b/llvm/lib/CodeGen/TargetSchedule.cpp --- a/llvm/lib/CodeGen/TargetSchedule.cpp +++ b/llvm/lib/CodeGen/TargetSchedule.cpp @@ -67,7 +67,7 @@ STI->initInstrItins(InstrItins); unsigned NumRes = SchedModel.getNumProcResourceKinds(); - ResourceFactors.resize(NumRes); + ResourceFactors.resize_for_overwrite(NumRes); ResourceLCM = SchedModel.IssueWidth; for (unsigned Idx = 0; Idx < NumRes; ++Idx) { unsigned NumUnits = SchedModel.getProcResource(Idx)->NumUnits; diff --git a/llvm/lib/DebugInfo/CodeView/TypeStreamMerger.cpp b/llvm/lib/DebugInfo/CodeView/TypeStreamMerger.cpp --- a/llvm/lib/DebugInfo/CodeView/TypeStreamMerger.cpp +++ b/llvm/lib/DebugInfo/CodeView/TypeStreamMerger.cpp @@ -371,7 +371,7 @@ MergingTypeTableBuilder &Dest = isIdRecord(Type.kind()) ? *DestIdStream : *DestTypeStream; - RemapStorage.resize(AlignedSize); + RemapStorage.resize_for_overwrite(AlignedSize); ArrayRef Result = DoSerialize(RemapStorage); if (!Result.empty()) DestIdx = Dest.insertRecordBytes(Result); diff --git a/llvm/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp b/llvm/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp --- a/llvm/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp @@ -403,7 +403,7 @@ if (!AS.isValidOffsetForDataOfSize(C.tell(), AugmentationStringSize)) return HeaderError(createStringError(errc::illegal_byte_sequence, "cannot read header augmentation")); - AugmentationString.resize(AugmentationStringSize); + AugmentationString.resize_for_overwrite(AugmentationStringSize); AS.getU8(C, reinterpret_cast(AugmentationString.data()), AugmentationStringSize); *Offset = C.tell(); diff --git a/llvm/lib/MC/MCAsmStreamer.cpp b/llvm/lib/MC/MCAsmStreamer.cpp --- a/llvm/lib/MC/MCAsmStreamer.cpp +++ b/llvm/lib/MC/MCAsmStreamer.cpp @@ -2027,9 +2027,7 @@ // representation. We do this by making a per-bit map to the fixup item index, // then trying to display it as nicely as possible. SmallVector FixupMap; - FixupMap.resize(Code.size() * 8); - for (unsigned i = 0, e = Code.size() * 8; i != e; ++i) - FixupMap[i] = 0; + FixupMap.assign(Code.size() * 8, 0); for (unsigned i = 0, e = Fixups.size(); i != e; ++i) { MCFixup &F = Fixups[i]; diff --git a/llvm/lib/MC/MCDwarf.cpp b/llvm/lib/MC/MCDwarf.cpp --- a/llvm/lib/MC/MCDwarf.cpp +++ b/llvm/lib/MC/MCDwarf.cpp @@ -330,7 +330,7 @@ // Emit the strings without perturbing the offsets we used. LineStrings.finalizeInOrder(); SmallString<0> Data; - Data.resize(LineStrings.getSize()); + Data.resize_for_overwrite(LineStrings.getSize()); LineStrings.write((uint8_t *)Data.data()); MCOS->emitBinaryData(Data.str()); } diff --git a/llvm/lib/MC/MCParser/AsmParser.cpp b/llvm/lib/MC/MCParser/AsmParser.cpp --- a/llvm/lib/MC/MCParser/AsmParser.cpp +++ b/llvm/lib/MC/MCParser/AsmParser.cpp @@ -5995,8 +5995,8 @@ // Merge the various outputs and inputs. Output are expected first. if (NumOutputs || NumInputs) { unsigned NumExprs = NumOutputs + NumInputs; - OpDecls.resize(NumExprs); - Constraints.resize(NumExprs); + OpDecls.resize_for_overwrite(NumExprs); + Constraints.resize_for_overwrite(NumExprs); for (unsigned i = 0; i < NumOutputs; ++i) { OpDecls[i] = std::make_pair(OutputDecls[i], OutputDeclsAddressOf[i]); Constraints[i] = OutputConstraints[i]; diff --git a/llvm/lib/MC/MCParser/MasmParser.cpp b/llvm/lib/MC/MCParser/MasmParser.cpp --- a/llvm/lib/MC/MCParser/MasmParser.cpp +++ b/llvm/lib/MC/MCParser/MasmParser.cpp @@ -7139,8 +7139,8 @@ // Merge the various outputs and inputs. Output are expected first. if (NumOutputs || NumInputs) { unsigned NumExprs = NumOutputs + NumInputs; - OpDecls.resize(NumExprs); - Constraints.resize(NumExprs); + OpDecls.resize_for_overwrite(NumExprs); + Constraints.resize_for_overwrite(NumExprs); for (unsigned i = 0; i < NumOutputs; ++i) { OpDecls[i] = std::make_pair(OutputDecls[i], OutputDeclsAddressOf[i]); Constraints[i] = OutputConstraints[i]; diff --git a/llvm/lib/MC/MCStreamer.cpp b/llvm/lib/MC/MCStreamer.cpp --- a/llvm/lib/MC/MCStreamer.cpp +++ b/llvm/lib/MC/MCStreamer.cpp @@ -150,7 +150,7 @@ const APInt Swapped = ShouldSwap ? Value.byteSwap() : Value; const unsigned Size = Value.getBitWidth() / 8; SmallString<10> Tmp; - Tmp.resize(Size); + Tmp.resize_for_overwrite(Size); StoreIntToMemory(Swapped, reinterpret_cast(Tmp.data()), Size); emitBytes(Tmp.str()); } @@ -350,7 +350,7 @@ static void copyBytesForDefRange(SmallString<20> &BytePrefix, codeview::SymbolKind SymKind, const T &DefRangeHeader) { - BytePrefix.resize(2 + sizeof(T)); + BytePrefix.resize_for_overwrite(2 + sizeof(T)); codeview::ulittle16_t SymKindLE = codeview::ulittle16_t(SymKind); memcpy(&BytePrefix[0], &SymKindLE, 2); memcpy(&BytePrefix[2], &DefRangeHeader, sizeof(T)); diff --git a/llvm/lib/MC/StringTableBuilder.cpp b/llvm/lib/MC/StringTableBuilder.cpp --- a/llvm/lib/MC/StringTableBuilder.cpp +++ b/llvm/lib/MC/StringTableBuilder.cpp @@ -59,7 +59,7 @@ void StringTableBuilder::write(raw_ostream &OS) const { assert(isFinalized()); SmallString<0> Data; - Data.resize(getSize()); + Data.resize_for_overwrite(getSize()); write((uint8_t *)Data.data()); OS << Data; } diff --git a/llvm/lib/MC/WinCOFFObjectWriter.cpp b/llvm/lib/MC/WinCOFFObjectWriter.cpp --- a/llvm/lib/MC/WinCOFFObjectWriter.cpp +++ b/llvm/lib/MC/WinCOFFObjectWriter.cpp @@ -860,7 +860,7 @@ COFFSymbol *File = createSymbol(".file"); File->Data.SectionNumber = COFF::IMAGE_SYM_DEBUG; File->Data.StorageClass = COFF::IMAGE_SYM_CLASS_FILE; - File->Aux.resize(Count); + File->Aux.resize_for_overwrite(Count); unsigned Offset = 0; unsigned Length = Name.size(); diff --git a/llvm/lib/Object/IRSymtab.cpp b/llvm/lib/Object/IRSymtab.cpp --- a/llvm/lib/Object/IRSymtab.cpp +++ b/llvm/lib/Object/IRSymtab.cpp @@ -327,7 +327,7 @@ // We are about to fill in the header's range fields, so reserve space for it // and copy it in afterwards. - Symtab.resize(sizeof(storage::Header)); + Symtab.resize_for_overwrite(sizeof(storage::Header)); writeRange(Hdr.Modules, Mods); writeRange(Hdr.Comdats, Comdats); writeRange(Hdr.Symbols, Syms); @@ -370,7 +370,7 @@ return std::move(E); StrtabBuilder.finalizeInOrder(); - FC.Strtab.resize(StrtabBuilder.getSize()); + FC.Strtab.resize_for_overwrite(StrtabBuilder.getSize()); StrtabBuilder.write((uint8_t *)FC.Strtab.data()); FC.TheReader = {{FC.Symtab.data(), FC.Symtab.size()}, diff --git a/llvm/lib/Object/MachOObjectFile.cpp b/llvm/lib/Object/MachOObjectFile.cpp --- a/llvm/lib/Object/MachOObjectFile.cpp +++ b/llvm/lib/Object/MachOObjectFile.cpp @@ -867,7 +867,7 @@ " LC_BUILD_VERSION_COMMAND has incorrect cmdsize"); auto Start = Load.Ptr + sizeof(MachO::build_version_command); - BuildTools.resize(BVC.ntools); + BuildTools.resize_for_overwrite(BVC.ntools); for (unsigned i = 0; i < BVC.ntools; ++i) BuildTools[i] = Start + i * sizeof(MachO::build_tool_version); diff --git a/llvm/lib/Support/ConvertUTFWrapper.cpp b/llvm/lib/Support/ConvertUTFWrapper.cpp --- a/llvm/lib/Support/ConvertUTFWrapper.cpp +++ b/llvm/lib/Support/ConvertUTFWrapper.cpp @@ -160,7 +160,7 @@ // UTF-8 encoding. Allocate one extra byte for the null terminator though, // so that someone calling DstUTF16.data() gets a null terminated string. // We resize down later so we don't have to worry that this over allocates. - DstUTF16.resize(SrcUTF8.size()+1); + DstUTF16.resize_for_overwrite(SrcUTF8.size() + 1); UTF16 *Dst = &DstUTF16[0]; UTF16 *DstEnd = Dst + DstUTF16.size(); diff --git a/llvm/lib/Support/PrettyStackTrace.cpp b/llvm/lib/Support/PrettyStackTrace.cpp --- a/llvm/lib/Support/PrettyStackTrace.cpp +++ b/llvm/lib/Support/PrettyStackTrace.cpp @@ -243,7 +243,7 @@ } const int Size = SizeOrError + 1; // '\0' - Str.resize(Size); + Str.resize_for_overwrite(Size); va_start(AP, Format); vsnprintf(Str.data(), Size, Format, AP); va_end(AP); diff --git a/llvm/lib/Support/raw_ostream.cpp b/llvm/lib/Support/raw_ostream.cpp --- a/llvm/lib/Support/raw_ostream.cpp +++ b/llvm/lib/Support/raw_ostream.cpp @@ -331,7 +331,7 @@ SmallVector V; while (true) { - V.resize(NextBufferSize); + V.resize_for_overwrite(NextBufferSize); // Try formatting into the SmallVector. size_t BytesUsed = Fmt.print(V.data(), NextBufferSize);