-
Notifications
You must be signed in to change notification settings - Fork 10.7k
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
[Support] Add option to print SMDiagnostic into a buffer without the filename and location info #92050
Merged
jansvoboda11
merged 1 commit into
llvm:main
from
artemcm:artemcm/ConfigurableLocationDisableOnSMDiagPrint
May 14, 2024
Merged
[Support] Add option to print SMDiagnostic into a buffer without the filename and location info #92050
jansvoboda11
merged 1 commit into
llvm:main
from
artemcm:artemcm/ConfigurableLocationDisableOnSMDiagPrint
May 14, 2024
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@llvm/pr-subscribers-llvm-support Author: Artem Chikin (artemcm) ChangesFull diff: https://github.com/llvm/llvm-project/pull/92050.diff 3 Files Affected:
diff --git a/llvm/include/llvm/Support/SourceMgr.h b/llvm/include/llvm/Support/SourceMgr.h
index 6f5bee7f8cc22..7a4b6de1162da 100644
--- a/llvm/include/llvm/Support/SourceMgr.h
+++ b/llvm/include/llvm/Support/SourceMgr.h
@@ -317,7 +317,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
diff --git a/llvm/lib/Support/SourceMgr.cpp b/llvm/lib/Support/SourceMgr.cpp
index ebeff87c39549..6eaa8783a5319 100644
--- a/llvm/lib/Support/SourceMgr.cpp
+++ b/llvm/lib/Support/SourceMgr.cpp
@@ -482,7 +482,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;
{
@@ -491,7 +491,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
diff --git a/llvm/unittests/Support/SourceMgrTest.cpp b/llvm/unittests/Support/SourceMgrTest.cpp
index cbd17ff476890..ebc8869c2fd3a 100644
--- a/llvm/unittests/Support/SourceMgrTest.cpp
+++ b/llvm/unittests/Support/SourceMgrTest.cpp
@@ -532,3 +532,13 @@ TEST_F(SourceMgrTest, FixitForTab) {
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);
+}
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
…filename and location info
artemcm
force-pushed
the
artemcm/ConfigurableLocationDisableOnSMDiagPrint
branch
from
May 14, 2024 00:01
cbf509f
to
bf16f8e
Compare
jansvoboda11
approved these changes
May 14, 2024
artemcm
added a commit
to apple/llvm-project
that referenced
this pull request
May 14, 2024
…filename and location info (llvm#92050)
nkcsgexi
added a commit
to apple/llvm-project
that referenced
this pull request
May 14, 2024
…ionDisableOnSMDiagPrint [Support] Add option to print SMDiagnostic into a buffer without the filename and location info (llvm#92050)
mub-at-arm
pushed a commit
to mub-at-arm/llvm-project
that referenced
this pull request
May 16, 2024
…filename and location info (llvm#92050)
bnbarham
pushed a commit
to apple/llvm-project
that referenced
this pull request
May 22, 2024
…filename and location info (llvm#92050) (cherry picked from commit 26e30de)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.