Skip to content

Commit c3988ba

Browse files
committed
[lldb] Remove redundant severity substring within a diagnostic message. (llvm#76111)
For example, the following message has the severity string "error: " twice. > "error: <EXPR>:3:1: error: cannot find 'bogus' in scope This method already appends the severity string in the beginning, but with this fix, it also removes a secondary instance, if applicable. Note that this change only removes the *first* redundant substring. I considered putting the removal logic in a loop, but I decided that if something is generating more than one redundant severity substring, then that's a problem the message's source should probably fix. rdar://114203423
1 parent 2a0affb commit c3988ba

File tree

9 files changed

+21
-12
lines changed

9 files changed

+21
-12
lines changed

lldb/source/Expression/DiagnosticManager.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,20 @@ static const char *StringForSeverity(DiagnosticSeverity severity) {
4646

4747
std::string DiagnosticManager::GetString(char separator) {
4848
std::string ret;
49+
llvm::raw_string_ostream stream(ret);
4950

5051
for (const auto &diagnostic : Diagnostics()) {
51-
ret.append(StringForSeverity(diagnostic->GetSeverity()));
52-
ret.append(std::string(diagnostic->GetMessage()));
53-
ret.push_back(separator);
52+
llvm::StringRef severity = StringForSeverity(diagnostic->GetSeverity());
53+
stream << severity;
54+
55+
llvm::StringRef message = diagnostic->GetMessage();
56+
std::string searchable_message = message.lower();
57+
auto severity_pos = message.find(severity);
58+
stream << message.take_front(severity_pos);
59+
60+
if (severity_pos != llvm::StringRef::npos)
61+
stream << message.drop_front(severity_pos + severity.size());
62+
stream << separator;
5463
}
5564

5665
return ret;

lldb/test/API/lang/objc/modules-compile-error/TestModulesCompileError.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def test(self):
2121
"expr @import LLDBTestModule",
2222
error=True,
2323
substrs=[
24-
"module.h:4:1: error: unknown type name 'syntax_error_for_lldb_to_find'",
24+
"module.h:4:1: unknown type name 'syntax_error_for_lldb_to_find'",
2525
"syntax_error_for_lldb_to_find // comment that tests source printing",
2626
"could not build module 'LLDBTestModule'",
2727
],

lldb/test/API/lang/swift/playgrounds-repl/invalid_input/TestInvalidInput.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def do_test(self):
4747
self.assertTrue(is_error)
4848
error = self.get_stream_data(result)
4949
self.assertIn("left side of mutating operator", error, "Error messages do not match")
50-
self.assertIn(":15:3: error: left side of mutating operator", error, "Error line number does not match")
50+
self.assertIn(":15:3: left side of mutating operator", error, "Error line number does not match")
5151

5252
# Execute revised block
5353
result, output = self.execute_code("Input3.swift")

lldb/test/Shell/SwiftREPL/DiagnosticOptions.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111

1212
_ = "An unterminated string
13-
// DIAGNOSTIC: error: unterminated string literal [lex_unterminated_string]{{$}}
14-
// LOCALIZED: error: chaîne non terminée littérale{{$}}
13+
// DIAGNOSTIC: unterminated string literal [lex_unterminated_string]{{$}}
14+
// LOCALIZED: chaîne non terminée littérale{{$}}
1515
:quit
1616

1717

lldb/test/Shell/SwiftREPL/ImportError.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
// RUN: %lldb --repl < %s 2>&1 | FileCheck %s
55

66
import ModuleThatDoesNotExist
7-
// CHECK: error: no such module 'ModuleThatDoesNotExist'
7+
// CHECK: no such module 'ModuleThatDoesNotExist'
88
// CHECK-NOT: fixed expression suggested

lldb/test/Shell/SwiftREPL/LookupAfterImport.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// RUN: %lldb --repl="-I%t -L%t -lA" < %s 2>&1 | FileCheck %s
99

1010
"".foo()
11-
// CHECK: error: value of type 'String' has no member 'foo'
11+
// CHECK: value of type 'String' has no member 'foo'
1212

1313
import A
1414

lldb/test/Shell/SwiftREPL/LookupWithAttributedImport.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ let y = Bar(baz: 123)
1515
// CHECK: baz = 123
1616

1717
let x = Foo(bar:42)
18-
// CHECK: error: repl.swift:{{.*}}: error: cannot find 'Foo' in scope
18+
// CHECK: error: repl.swift:{{.*}}: cannot find 'Foo' in scope
1919

2020
@testable import Test
2121

lldb/test/Shell/SwiftREPL/OpenClass.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ class Baz: Foo {
2626
override func foo() -> Int { return 4 }
2727
}
2828

29-
// CHECK: error: overriding non-open instance method outside of its defining module
29+
// CHECK: overriding non-open instance method outside of its defining module

lldb/test/Shell/SwiftREPL/PropertyWrapperTopLevel.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,5 @@
3434

3535
@A var anA: Int = 1
3636

37-
// CHECK: error: property wrappers are not yet supported in top-level code
37+
// CHECK: property wrappers are not yet supported in top-level code
3838
// CHECK-NEXT: @A var anA: Int = 1

0 commit comments

Comments
 (0)