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
diff --git a/lib/IR/Diagnostics.cpp b/lib/IR/Diagnostics.cpp
index 50de2b1..076a9b2 100644
--- a/lib/IR/Diagnostics.cpp
+++ b/lib/IR/Diagnostics.cpp
@@ -400,11 +400,13 @@
// 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());
}