Skip to content

[NFC] [DiagnosticEngine] Improve output for malformed diagnostic messages #28177

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions lib/AST/DiagnosticEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -669,9 +669,8 @@ void DiagnosticEngine::formatDiagnosticText(
}

if (Modifier == "error") {
assert(false && "encountered %error in diagnostic text");
Out << StringRef("<<ERROR>>");
break;
Out << StringRef("<<INTERNAL ERROR: encountered %error in diagnostic text>>");
continue;
}

// Parse the optional argument list for a modifier, which is brace-enclosed.
Expand All @@ -684,12 +683,20 @@ void DiagnosticEngine::formatDiagnosticText(
// Find the digit sequence, and parse it into an argument index.
size_t Length = InText.find_if_not(isdigit);
unsigned ArgIndex;
bool Result = InText.substr(0, Length).getAsInteger(10, ArgIndex);
assert(!Result && "Unparseable argument index value?");
(void)Result;
assert(ArgIndex < Args.size() && "Out-of-range argument index");
bool IndexParseFailed = InText.substr(0, Length).getAsInteger(10, ArgIndex);

if (IndexParseFailed) {
Out << StringRef("<<INTERNAL ERROR: unparseable argument index in diagnostic text>>");
continue;
}

InText = InText.substr(Length);

if (ArgIndex >= Args.size()) {
Out << StringRef("<<INTERNAL ERROR: out-of-range argument index in diagnostic text>>");
continue;
}

// Convert the argument to a string.
formatDiagnosticArgument(Modifier, ModifierArguments, Args, ArgIndex,
FormatOpts, Out);
Expand Down