Skip to content

Commit 05aad6b

Browse files
authored
Merge pull request #8792 from bnbarham/cherry-missing-print
[rebranch][Support] Add option to print SMDiagnostic into a buffer without the …
2 parents 623bcfe + 8838d2c commit 05aad6b

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

llvm/include/llvm/Support/SourceMgr.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ class SMDiagnostic {
329329
ArrayRef<SMFixIt> getFixIts() const { return FixIts; }
330330

331331
void print(const char *ProgName, raw_ostream &S, bool ShowColors = true,
332-
bool ShowKindLabel = true) const;
332+
bool ShowKindLabel = true, bool ShowLocation = true) const;
333333
};
334334

335335
} // end namespace llvm

llvm/lib/Support/SourceMgr.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ static void printSourceLine(raw_ostream &S, StringRef LineContents) {
498498
static bool isNonASCII(char c) { return c & 0x80; }
499499

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

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

510-
if (!Filename.empty()) {
510+
if (ShowLocation && !Filename.empty()) {
511511
if (Filename == "-")
512512
S << "<stdin>";
513513
else

llvm/unittests/Support/SourceMgrTest.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,3 +580,15 @@ TEST_F(SourceMgrTest, AddIncludedFile) {
580580
"Included from //path/to/includes/search-path-file:3:\n",
581581
Output);
582582
}
583+
584+
TEST_F(SourceMgrTest, PrintWithoutLoc) {
585+
raw_string_ostream OS(Output);
586+
auto Diag =
587+
llvm::SMDiagnostic("file.in", llvm::SourceMgr::DK_Error, "message");
588+
Diag.print(nullptr, OS);
589+
OS.flush();
590+
EXPECT_EQ("file.in: error: message\n", Output);
591+
Output.clear();
592+
Diag.print(nullptr, OS, false, false, false);
593+
EXPECT_EQ("message\n", Output);
594+
}

0 commit comments

Comments
 (0)