Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fc10361

Browse files
Merge pull request swiftlang#9230 from adrian-prantl/diagnose-warnings-sc-6.0
[swift-lldb] Port TypeSystem::DiagnoseWarnings() to precise compiler …
2 parents 8f7798a + 48cc29d commit fc10361

File tree

10 files changed

+69
-53
lines changed

10 files changed

+69
-53
lines changed

lldb/include/lldb/Symbol/TypeSystem.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,8 @@ class TypeSystem : public PluginInterface,
558558
/// have a way to communicate errors. This method can be called by a
559559
/// process to tell the TypeSystem to send any diagnostics to the
560560
/// process so they can be surfaced to the user.
561-
virtual void DiagnoseWarnings(Process &process, Module &module) const;
561+
virtual void DiagnoseWarnings(Process &process,
562+
const SymbolContext &sc) const;
562563

563564
virtual std::optional<llvm::json::Value> ReportStatistics();
564565

lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp

+25-13
Original file line numberDiff line numberDiff line change
@@ -1166,13 +1166,14 @@ static void printASTValidationError(
11661166
LLDB_LOG(log, " -- {0}", ExtraOpt);
11671167
}
11681168

1169-
void SwiftASTContext::DiagnoseWarnings(Process &process, Module &module) const {
1170-
if (!HasDiagnostics())
1169+
void SwiftASTContext::DiagnoseWarnings(Process &process,
1170+
const SymbolContext &sc) const {
1171+
if (!sc.module_sp || !HasDiagnostics())
11711172
return;
11721173
auto debugger_id = process.GetTarget().GetDebugger().GetID();
11731174
std::string msg;
11741175
llvm::raw_string_ostream(msg) << "Cannot load Swift type information for "
1175-
<< module.GetFileSpec().GetPath();
1176+
<< sc.module_sp->GetFileSpec().GetPath();
11761177
Debugger::ReportWarning(msg, debugger_id, &m_swift_import_warning);
11771178
StreamAllDiagnostics(debugger_id);
11781179
}
@@ -2111,7 +2112,8 @@ ProcessModule(Module &module, std::string m_description,
21112112
std::vector<swift::PluginSearchOption> &plugin_search_options,
21122113
std::vector<std::string> &module_search_paths,
21132114
std::vector<std::pair<std::string, bool>> &framework_search_paths,
2114-
std::vector<std::string> &extra_clang_args) {
2115+
std::vector<std::string> &extra_clang_args,
2116+
std::string &error) {
21152117
{
21162118
llvm::raw_string_ostream ss(m_description);
21172119
ss << "::ProcessModule(" << '"';
@@ -2215,8 +2217,7 @@ ProcessModule(Module &module, std::string m_description,
22152217
return;
22162218
bool found_swift_modules = false;
22172219
bool got_serialized_options = false;
2218-
llvm::SmallString<0> error;
2219-
llvm::raw_svector_ostream errs(error);
2220+
llvm::raw_string_ostream errs(error);
22202221
swift::CompilerInvocation invocation;
22212222
auto ast_file_datas = module.GetASTData(eLanguageTypeSwift);
22222223
std::string module_name = module.GetSpecificationDescription();
@@ -2365,7 +2366,7 @@ SwiftASTContext::CreateInstance(lldb::LanguageType language, Module &module,
23652366
bool got_serialized_options = false;
23662367
llvm::SmallString<0> error;
23672368
llvm::raw_svector_ostream errs(error);
2368-
// Implicit search paths will be discovered by ValidateSecionModules().
2369+
// Implicit search paths will be discovered by ValidateSectionModules().
23692370
bool discover_implicit_search_paths = false;
23702371
auto ast_file_datas = module.GetASTData(eLanguageTypeSwift);
23712372
std::string module_name = module.GetSpecificationDescription();
@@ -2436,6 +2437,7 @@ SwiftASTContext::CreateInstance(lldb::LanguageType language, Module &module,
24362437
const bool use_all_compiler_flags = false;
24372438
const bool is_target_module = true;
24382439

2440+
std::string error;
24392441
StringRef module_filter;
24402442
std::vector<swift::PluginSearchOption> plugin_search_options;
24412443
std::vector<std::string> extra_clang_args = swift_ast_sp->GetClangArguments();
@@ -2444,7 +2446,10 @@ SwiftASTContext::CreateInstance(lldb::LanguageType language, Module &module,
24442446
ProcessModule(module, m_description, discover_implicit_search_paths,
24452447
use_all_compiler_flags, is_target_module, module_filter, triple,
24462448
plugin_search_options, module_search_paths,
2447-
framework_search_paths, extra_clang_args);
2449+
framework_search_paths, extra_clang_args, error);
2450+
if (!error.empty())
2451+
swift_ast_sp->AddDiagnostic(eSeverityError, error);
2452+
24482453
// Apply the working directory to all relative paths.
24492454
StringRef overrideOpts = target ? target->GetSwiftClangOverrideOptions() : "";
24502455
swift_ast_sp->AddExtraClangArgs(extra_clang_args, overrideOpts);
@@ -2800,14 +2805,15 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(
28002805

28012806
for (ModuleSP module_sp : target.GetImages().Modules())
28022807
if (module_sp) {
2808+
std::string error;
28032809
StringRef module_filter;
28042810
std::vector<std::string> extra_clang_args;
28052811
ProcessModule(*module_sp, m_description, discover_implicit_search_paths,
28062812
use_all_compiler_flags,
28072813
target.GetExecutableModulePointer() == module_sp.get(),
28082814
module_filter, triple, plugin_search_options,
28092815
module_search_paths, framework_search_paths,
2810-
extra_clang_args);
2816+
extra_clang_args, error);
28112817
swift_ast_sp->AddExtraClangArgs(extra_clang_args,
28122818
target.GetSwiftClangOverrideOptions());
28132819
}
@@ -3137,14 +3143,17 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(
31373143
/*is_system*/ false});
31383144
ModuleSP module_sp = sc.module_sp;
31393145
if (module_sp) {
3146+
std::string error;
31403147
StringRef module_filter = swift_module_name;
31413148
std::vector<std::string> extra_clang_args;
31423149
ProcessModule(*module_sp, m_description, discover_implicit_search_paths,
31433150
use_all_compiler_flags,
31443151
target.GetExecutableModulePointer() == module_sp.get(),
31453152
module_filter, triple, plugin_search_options,
3146-
module_search_paths, framework_search_paths,
3147-
extra_clang_args);
3153+
module_search_paths, framework_search_paths, extra_clang_args,
3154+
error);
3155+
if (!error.empty())
3156+
swift_ast_sp->AddDiagnostic(eSeverityError, error);
31483157
swift_ast_sp->AddExtraClangArgs(extra_clang_args,
31493158
target.GetSwiftClangOverrideOptions());
31503159
}
@@ -5602,13 +5611,16 @@ void SwiftASTContextForExpressions::ModulesDidLoad(ModuleList &module_list) {
56025611
lldb::ModuleSP module_sp = module_list.GetModuleAtIndex(mi);
56035612
if (!module_sp)
56045613
continue;
5614+
std::string error;
56055615
StringRef module_filter;
56065616
ProcessModule(*module_sp, m_description, discover_implicit_search_paths,
56075617
use_all_compiler_flags,
56085618
target_sp->GetExecutableModulePointer() == module_sp.get(),
56095619
module_filter, GetTriple(), plugin_search_options,
5610-
module_search_paths, framework_search_paths,
5611-
extra_clang_args);
5620+
module_search_paths, framework_search_paths, extra_clang_args,
5621+
error);
5622+
if (!error.empty())
5623+
AddDiagnostic(eSeverityError, error);
56125624
// If the use-all-compiler-flags setting is enabled, the
56135625
// expression context is supposed to merge all search paths
56145626
// from all dylibs.

lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -485,8 +485,9 @@ class SwiftASTContext : public TypeSystemSwift {
485485
/// Return only fatal errors.
486486
Status GetFatalErrors() const;
487487
/// Notify the Process about any Swift or ClangImporter errors.
488-
void DiagnoseWarnings(Process &process, Module &module) const override;
489-
488+
void DiagnoseWarnings(Process &process,
489+
const SymbolContext &sc) const override;
490+
490491
bool SetColorizeDiagnostics(bool b);
491492

492493
void PrintDiagnostics(DiagnosticManager &diagnostic_manager,

lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.cpp

+4-5
Original file line numberDiff line numberDiff line change
@@ -2059,11 +2059,10 @@ Status TypeSystemSwiftTypeRef::IsCompatible() {
20592059
}
20602060

20612061
void TypeSystemSwiftTypeRef::DiagnoseWarnings(Process &process,
2062-
Module &module) const {
2063-
// This gets called only from Thread::FrameSelectedCallback(StackFrame)
2064-
// and is of limited usefuleness.
2065-
if (auto *swift_ast_context = GetSwiftASTContextOrNull(nullptr))
2066-
swift_ast_context->DiagnoseWarnings(process, module);
2062+
const SymbolContext &sc) const {
2063+
// This gets called only from Thread::FrameSelectedCallback(StackFrame).
2064+
if (auto *swift_ast_context = GetSwiftASTContextOrNull(&sc))
2065+
swift_ast_context->DiagnoseWarnings(process, sc);
20672066
}
20682067

20692068
plugin::dwarf::DWARFASTParser *TypeSystemSwiftTypeRef::GetDWARFParser() {

lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ class TypeSystemSwiftTypeRef : public TypeSystemSwift {
108108
bool SupportsLanguage(lldb::LanguageType language) override;
109109
Status IsCompatible() override;
110110

111-
void DiagnoseWarnings(Process &process, Module &module) const override;
111+
void DiagnoseWarnings(Process &process,
112+
const SymbolContext &sc) const override;
112113
plugin::dwarf::DWARFASTParser *GetDWARFParser() override;
113114
// CompilerDecl functions
114115
ConstString DeclGetName(void *opaque_decl) override {

lldb/source/Symbol/TypeSystem.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,8 @@ bool TypeSystem::IsMeaninglessWithoutDynamicResolution(void *type) {
161161
return false;
162162
}
163163

164-
void TypeSystem::DiagnoseWarnings(Process &process, Module &module) const {}
164+
void TypeSystem::DiagnoseWarnings(Process &process,
165+
const SymbolContext &sc) const {}
165166

166167
Status TypeSystem::IsCompatible() {
167168
// Assume a language is compatible. Override this virtual function

lldb/source/Target/Thread.cpp

+18-7
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@
5353
#include "lldb/Utility/StreamString.h"
5454
#include "lldb/lldb-enumerations.h"
5555

56+
#ifdef LLDB_ENABLE_SWIFT
57+
#include "Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.h"
58+
#endif
59+
5660
#include <memory>
5761
#include <optional>
5862

@@ -343,13 +347,20 @@ void Thread::FrameSelectedCallback(StackFrame *frame) {
343347
GetProcess()->PrintWarningToolchainMismatch(sc);
344348
#endif
345349
}
346-
SymbolContext msc = frame->GetSymbolContext(eSymbolContextModule);
347-
if (msc.module_sp)
348-
msc.module_sp->ForEachTypeSystem([&](lldb::TypeSystemSP ts) {
349-
if (ts)
350-
ts->DiagnoseWarnings(*GetProcess(), *msc.module_sp);
351-
return true;
352-
});
350+
#ifdef LLDB_ENABLE_SWIFT
351+
{
352+
SymbolContext msc =
353+
frame->GetSymbolContext(eSymbolContextFunction | eSymbolContextModule);
354+
Status error;
355+
ExecutionContext exe_ctx;
356+
frame->CalculateExecutionContext(exe_ctx);
357+
if (auto *exe_scope = exe_ctx.GetBestExecutionContextScope())
358+
if (auto target = frame->CalculateTarget())
359+
if (auto swift_ast_ctx =
360+
target->GetSwiftScratchContext(error, *exe_scope, false))
361+
swift_ast_ctx->get()->DiagnoseWarnings(*GetProcess(), msc);
362+
}
363+
#endif
353364
}
354365

355366
lldb::StopInfoSP Thread::GetStopInfo() {

lldb/test/API/lang/swift/expression/import_search_paths/TestSwiftImportSearchPaths.py

+3-9
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,10 @@ class TestSwiftImportSearchPaths(lldbtest.TestBase):
99
NO_DEBUG_INFO_TESTCASE = True
1010
mydir = lldbtest.TestBase.compute_mydir(__file__)
1111

12-
@skipIf(bugnumber='rdar://135553659')
1312
@swiftTest
1413
def test_positive(self):
1514
self.do_test('true')
1615

17-
@skipIf(bugnumber='rdar://135553659')
1816
@swiftTest
1917
def test_negative(self):
2018
self.do_test('false')
@@ -39,12 +37,8 @@ def do_test(self, flag):
3937
prefix = 'POSITIVE'
4038
else:
4139
prefix = 'NEGATIVE'
42-
self.filecheck('platform shell cat "%s"' % types_log, __file__,
43-
'--check-prefix=CHECK_MOD_'+prefix)
4440
self.filecheck('platform shell cat "%s"' % types_log, __file__,
4541
'--check-prefix=CHECK_EXP_'+prefix)
46-
# CHECK_MOD_POSITIVE: SwiftASTContextForModule("a.out")::LogConfiguration(){{.*hidden$}}
47-
# CHECK_MOD_NEGATIVE: SwiftASTContextForModule("a.out")::LogConfiguration(){{.*hidden$}}
48-
# CHECK_EXP_POSITIVE: SwiftASTContextForExpressions::LogConfiguration(){{.*hidden$}}
49-
# CHECK_EXP_NEGATIVE-NOT: SwiftASTContextForExpressions::LogConfiguration(){{.*hidden$}}
50-
# CHECK_EXP_NEGATIVE: SwiftASTContextForExpressions::LogConfiguration(){{.*}}Extra clang arguments
42+
# CHECK_EXP_POSITIVE: SwiftASTContextForExpressions{{.*}}::LogConfiguration(){{.*hidden$}}
43+
# CHECK_EXP_NEGATIVE-NOT: SwiftASTContextForExpressions{{.*}}::LogConfiguration(){{.*hidden$}}
44+
# CHECK_EXP_NEGATIVE: SwiftASTContextForExpressions{{.*}}::LogConfiguration(){{.*}}Extra clang arguments

lldb/test/API/repl/cpp_exceptions/TestSwiftCPPExceptionsInREPL.py

+10-13
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import swift
1414
import lldbsuite.test.lldbutil as lldbutil
1515
from lldbsuite.test.lldbtest import *
16-
from lldbsuite.test import decorators
16+
from lldbsuite.test.decorators import *
1717

1818

1919
class TestSwiftREPLExceptions(TestBase):
@@ -23,32 +23,29 @@ class TestSwiftREPLExceptions(TestBase):
2323
# each debug info format.
2424
NO_DEBUG_INFO_TESTCASE = True
2525

26-
@decorators.skipUnlessDarwin
27-
@decorators.swiftTest
28-
def test_set_repl_mode_exceptions(self):
26+
@skipUnlessDarwin
27+
@swiftTest
28+
def DISABLED_test_set_repl_mode_exceptions(self):
2929
""" Test that SetREPLMode turns off trapping exceptions."""
30-
return
3130
self.build()
3231
self.main_source_file = lldb.SBFileSpec("main.swift")
3332
self.do_repl_mode_test()
3433

35-
@decorators.skipUnlessDarwin
36-
@decorators.swiftTest
34+
@skipUnlessDarwin
35+
@swiftTest
3736
def test_repl_exceptions(self):
3837
""" Test the lldb --repl turns off trapping exceptions."""
3938
self.build()
4039
self.do_repl_test()
4140

42-
def setUp(self):
43-
# Call super's setUp().
44-
TestBase.setUp(self)
45-
46-
@decorators.skipIfRemote
41+
@skipIfRemote
4742
def do_repl_test(self):
4843
sdk_root = ""
4944
with open(self.getBuildArtifact("sdkroot.txt"), 'r') as f:
5045
sdk_root = f.readlines()[0]
5146
self.assertGreater(len(sdk_root), 0)
47+
if sdk_root[-1] == '\n':
48+
sdk_root = sdk_root[:-1]
5249
build_dir = self.getBuildDir()
5350
repl_args = [lldbtest_config.lldbExec, "-x", "--repl=-enable-objc-interop -sdk %s -L%s -I%s"%(sdk_root, build_dir, build_dir)]
5451
repl_proc = subprocess.Popen(repl_args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, cwd=build_dir)
@@ -71,7 +68,7 @@ def do_repl_mode_test(self):
7168
lldb.SBFileSpec(os.path.join(wd, filename)))
7269
self.assertFalse(err.Fail(), 'Failed to copy ' + filename)
7370
(target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self,
74-
"Set a breakpoint here", self.main_source_file)
71+
"Set a breakpoint here", self.main_source_file)
7572

7673
frame = thread.GetFrameAtIndex(0)
7774
options = lldb.SBExpressionOptions()

lldb/test/Shell/Swift/MissingVFSOverlay.test

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Test that error messages from constructing ClangImporter
22
# are surfaced to the user.
3-
# REQUIRES: 135553659
43
# REQUIRES: swift
54

65
# RUN: rm -rf %t && mkdir %t && cd %t

0 commit comments

Comments
 (0)