Skip to content

Commit 37d3ce7

Browse files
authored
Merge pull request #28177 from brentdax/diagnostics-in-your-diagnostics
[NFC] [DiagnosticEngine] Improve output for malformed diagnostic messages
2 parents a3c1925 + 4f8756d commit 37d3ce7

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
@@ -681,9 +681,8 @@ void DiagnosticEngine::formatDiagnosticText(
681681
}
682682

683683
if (Modifier == "error") {
684-
assert(false && "encountered %error in diagnostic text");
685-
Out << StringRef("<<ERROR>>");
686-
break;
684+
Out << StringRef("<<INTERNAL ERROR: encountered %error in diagnostic text>>");
685+
continue;
687686
}
688687

689688
// Parse the optional argument list for a modifier, which is brace-enclosed.
@@ -696,12 +695,20 @@ void DiagnosticEngine::formatDiagnosticText(
696695
// Find the digit sequence, and parse it into an argument index.
697696
size_t Length = InText.find_if_not(isdigit);
698697
unsigned ArgIndex;
699-
bool Result = InText.substr(0, Length).getAsInteger(10, ArgIndex);
700-
assert(!Result && "Unparseable argument index value?");
701-
(void)Result;
702-
assert(ArgIndex < Args.size() && "Out-of-range argument index");
698+
bool IndexParseFailed = InText.substr(0, Length).getAsInteger(10, ArgIndex);
699+
700+
if (IndexParseFailed) {
701+
Out << StringRef("<<INTERNAL ERROR: unparseable argument index in diagnostic text>>");
702+
continue;
703+
}
704+
703705
InText = InText.substr(Length);
704706

707+
if (ArgIndex >= Args.size()) {
708+
Out << StringRef("<<INTERNAL ERROR: out-of-range argument index in diagnostic text>>");
709+
continue;
710+
}
711+
705712
// Convert the argument to a string.
706713
formatDiagnosticArgument(Modifier, ModifierArguments, Args, ArgIndex,
707714
FormatOpts, Out);

0 commit comments

Comments
 (0)