Skip to content

[rebranch][Support] Add option to print SMDiagnostic into a buffer without the … #8792

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 1 commit into from
May 22, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion llvm/include/llvm/Support/SourceMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ class SMDiagnostic {
ArrayRef<SMFixIt> getFixIts() const { return FixIts; }

void print(const char *ProgName, raw_ostream &S, bool ShowColors = true,
bool ShowKindLabel = true) const;
bool ShowKindLabel = true, bool ShowLocation = true) const;
};

} // end namespace llvm
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Support/SourceMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ static void printSourceLine(raw_ostream &S, StringRef LineContents) {
static bool isNonASCII(char c) { return c & 0x80; }

void SMDiagnostic::print(const char *ProgName, raw_ostream &OS, bool ShowColors,
bool ShowKindLabel) const {
bool ShowKindLabel, bool ShowLocation) const {
ColorMode Mode = ShowColors ? ColorMode::Auto : ColorMode::Disable;

{
Expand All @@ -507,7 +507,7 @@ void SMDiagnostic::print(const char *ProgName, raw_ostream &OS, bool ShowColors,
if (ProgName && ProgName[0])
S << ProgName << ": ";

if (!Filename.empty()) {
if (ShowLocation && !Filename.empty()) {
if (Filename == "-")
S << "<stdin>";
else
Expand Down
12 changes: 12 additions & 0 deletions llvm/unittests/Support/SourceMgrTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -580,3 +580,15 @@ TEST_F(SourceMgrTest, AddIncludedFile) {
"Included from //path/to/includes/search-path-file:3:\n",
Output);
}

TEST_F(SourceMgrTest, PrintWithoutLoc) {
raw_string_ostream OS(Output);
auto Diag =
llvm::SMDiagnostic("file.in", llvm::SourceMgr::DK_Error, "message");
Diag.print(nullptr, OS);
OS.flush();
EXPECT_EQ("file.in: error: message\n", Output);
Output.clear();
Diag.print(nullptr, OS, false, false, false);
EXPECT_EQ("message\n", Output);
}