NFC: Don't print the location of a diagnostic if it is unknown.

Printing 'loc(unknown)' just clutters the output with unhelpful information.

PiperOrigin-RevId: 257883717
This commit is contained in:
River Riddle 2019-07-12 15:49:38 -07:00 committed by Mehdi Amini
parent 9af156757d
commit fdc2b3f75f
1 changed files with 4 additions and 2 deletions

View File

@ -400,11 +400,13 @@ void SourceMgrDiagnosticHandler::emitDiagnostic(Location loc, Twine message,
// Extract a file location from this loc.
auto fileLoc = getFileLineColLoc(loc);
// If one doesn't exist, then print the location as part of the message.
// If one doesn't exist, then print the raw message without a source location.
if (!fileLoc) {
std::string str;
llvm::raw_string_ostream strOS(str);
strOS << loc << ": " << message;
if (!loc.isa<UnknownLoc>())
strOS << loc << ": ";
strOS << message;
return mgr.PrintMessage(os, llvm::SMLoc(), getDiagKind(kind), strOS.str());
}