diff --git a/lib/CodeGen/AsmPrinter/DebugLocEntry.h b/lib/CodeGen/AsmPrinter/DebugLocEntry.h index 41735fca376..ba05aa71157 100644 --- a/lib/CodeGen/AsmPrinter/DebugLocEntry.h +++ b/lib/CodeGen/AsmPrinter/DebugLocEntry.h @@ -114,8 +114,7 @@ public: DIVariable NextVar(Next.Values[0].Variable); if (Var.getName() == NextVar.getName() && Var.isVariablePiece() && NextVar.isVariablePiece()) { - Values.append(Next.Values.begin(), Next.Values.end()); - sortUniqueValues(); + addValues(Next.Values); End = Next.End; return true; } @@ -139,11 +138,12 @@ public: const MCSymbol *getBeginSym() const { return Begin; } const MCSymbol *getEndSym() const { return End; } const ArrayRef getValues() const { return Values; } - void addValue(Value Val) { - assert(DIVariable(Val.Variable).isVariablePiece() && - "multi-value DebugLocEntries must be pieces"); - Values.push_back(Val); + void addValues(ArrayRef Vals) { + Values.append(Vals.begin(), Vals.end()); sortUniqueValues(); + assert(std::all_of(Values.begin(), Values.end(), [](DebugLocEntry::Value V){ + return DIVariable(V.Variable).isVariablePiece(); + }) && "value must be a piece"); } // Sort the pieces by offset. diff --git a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp index 57dda88b002..a669077f08b 100644 --- a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -1288,8 +1288,9 @@ DwarfDebug::buildLocationList(SmallVectorImpl &DebugLoc, if (!couldMerge) { // Need to add a new DebugLocEntry. Add all values from still // valid non-overlapping pieces. - for (auto Range : OpenRanges) - Loc.addValue(Range.second); + if (OpenRanges.size()) + Loc.addValues(OpenRanges); + DebugLoc.push_back(std::move(Loc)); }