@@ -217,12 +217,12 @@ uint64_t MCAssembler::computeFragmentSize(const MCFragment &F) const {
217217 auto &FF = cast<MCFillFragment>(F);
218218 int64_t NumValues = 0 ;
219219 if (!FF.getNumValues ().evaluateKnownAbsolute (NumValues, *this )) {
220- reportError (FF.getLoc (), " expected assembly-time absolute expression" );
220+ recordError (FF.getLoc (), " expected assembly-time absolute expression" );
221221 return 0 ;
222222 }
223223 int64_t Size = NumValues * FF.getValueSize ();
224224 if (Size < 0 ) {
225- reportError (FF.getLoc (), " invalid number of bytes" );
225+ recordError (FF.getLoc (), " invalid number of bytes" );
226226 return 0 ;
227227 }
228228 return Size;
@@ -266,7 +266,7 @@ uint64_t MCAssembler::computeFragmentSize(const MCFragment &F) const {
266266 const MCOrgFragment &OF = cast<MCOrgFragment>(F);
267267 MCValue Value;
268268 if (!OF.getOffset ().evaluateAsValue (Value, *this )) {
269- reportError (OF.getLoc (), " expected assembly-time absolute expression" );
269+ recordError (OF.getLoc (), " expected assembly-time absolute expression" );
270270 return 0 ;
271271 }
272272
@@ -275,14 +275,14 @@ uint64_t MCAssembler::computeFragmentSize(const MCFragment &F) const {
275275 if (const auto *SA = Value.getAddSym ()) {
276276 uint64_t Val;
277277 if (!getSymbolOffset (*SA, Val)) {
278- reportError (OF.getLoc (), " expected absolute expression" );
278+ recordError (OF.getLoc (), " expected absolute expression" );
279279 return 0 ;
280280 }
281281 TargetLocation += Val;
282282 }
283283 int64_t Size = TargetLocation - FragmentOffset;
284284 if (Size < 0 || Size >= 0x40000000 ) {
285- reportError (OF.getLoc (), " invalid .org offset '" + Twine (TargetLocation) +
285+ recordError (OF.getLoc (), " invalid .org offset '" + Twine (TargetLocation) +
286286 " ' (at offset '" + Twine (FragmentOffset) +
287287 " ')" );
288288 return 0 ;
@@ -825,6 +825,7 @@ void MCAssembler::writeSectionData(raw_ostream &OS,
825825 for (const MCFragment &F : *Sec)
826826 writeFragment (OS, *this , F);
827827
828+ flushPendingErrors ();
828829 assert (getContext ().hadError () ||
829830 OS.tell () - Start == getSectionAddressSize (*Sec));
830831}
@@ -878,6 +879,8 @@ void MCAssembler::layout() {
878879 // Finalize the layout, including fragment lowering.
879880 getBackend ().finishLayout (*this );
880881
882+ flushPendingErrors ();
883+
881884 DEBUG_WITH_TYPE (" mc-dump" , {
882885 errs () << " assembler backend - final-layout\n --\n " ;
883886 dump (); });
@@ -968,6 +971,7 @@ void MCAssembler::Finish() {
968971 stats::ObjectBytes += getWriter ().writeObject ();
969972
970973 HasLayout = false ;
974+ assert (PendingErrors.empty ());
971975}
972976
973977bool MCAssembler::fixupNeedsRelaxation (const MCFixup &Fixup,
@@ -1222,6 +1226,7 @@ bool MCAssembler::relaxFragment(MCFragment &F) {
12221226
12231227bool MCAssembler::layoutOnce () {
12241228 ++stats::RelaxationSteps;
1229+ PendingErrors.clear ();
12251230
12261231 bool Changed = false ;
12271232 for (MCSection &Sec : *this )
@@ -1235,6 +1240,16 @@ void MCAssembler::reportError(SMLoc L, const Twine &Msg) const {
12351240 getContext ().reportError (L, Msg);
12361241}
12371242
1243+ void MCAssembler::recordError (SMLoc Loc, const Twine &Msg) const {
1244+ PendingErrors.emplace_back (Loc, Msg.str ());
1245+ }
1246+
1247+ void MCAssembler::flushPendingErrors () const {
1248+ for (auto &Err : PendingErrors)
1249+ reportError (Err.first , Err.second );
1250+ PendingErrors.clear ();
1251+ }
1252+
12381253#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
12391254LLVM_DUMP_METHOD void MCAssembler::dump () const {
12401255 raw_ostream &OS = errs ();
0 commit comments