Skip to content

Commit 4f8756d

Browse files
committed
[NFC] [DiagnosticEngine] Improve output for malformed diagnostic messages
This is NFC as long as you assume there are no bad diagnostics.
1 parent 7837a3d commit 4f8756d

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

lib/AST/DiagnosticEngine.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -669,9 +669,8 @@ void DiagnosticEngine::formatDiagnosticText(
669669
}
670670

671671
if (Modifier == "error") {
672-
assert(false && "encountered %error in diagnostic text");
673-
Out << StringRef("<<ERROR>>");
674-
break;
672+
Out << StringRef("<<INTERNAL ERROR: encountered %error in diagnostic text>>");
673+
continue;
675674
}
676675

677676
// Parse the optional argument list for a modifier, which is brace-enclosed.
@@ -684,12 +683,20 @@ void DiagnosticEngine::formatDiagnosticText(
684683
// Find the digit sequence, and parse it into an argument index.
685684
size_t Length = InText.find_if_not(isdigit);
686685
unsigned ArgIndex;
687-
bool Result = InText.substr(0, Length).getAsInteger(10, ArgIndex);
688-
assert(!Result && "Unparseable argument index value?");
689-
(void)Result;
690-
assert(ArgIndex < Args.size() && "Out-of-range argument index");
686+
bool IndexParseFailed = InText.substr(0, Length).getAsInteger(10, ArgIndex);
687+
688+
if (IndexParseFailed) {
689+
Out << StringRef("<<INTERNAL ERROR: unparseable argument index in diagnostic text>>");
690+
continue;
691+
}
692+
691693
InText = InText.substr(Length);
692694

695+
if (ArgIndex >= Args.size()) {
696+
Out << StringRef("<<INTERNAL ERROR: out-of-range argument index in diagnostic text>>");
697+
continue;
698+
}
699+
693700
// Convert the argument to a string.
694701
formatDiagnosticArgument(Modifier, ModifierArguments, Args, ArgIndex,
695702
FormatOpts, Out);

0 commit comments

Comments
 (0)