Skip to content

Commit a7eadc7

Browse files
Merge pull request #11292 from adrian-prantl/repl-fix-rebranch
[lldb] Fix Swift REPL tests on rebranch
2 parents 5592252 + 38558e6 commit a7eadc7

File tree

21 files changed

+91
-63
lines changed

21 files changed

+91
-63
lines changed

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

Lines changed: 69 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,13 @@
5959
#include "swift/SymbolGraphGen/SymbolGraphOptions.h"
6060

6161
#include "clang/AST/ASTContext.h"
62+
#include "clang/Basic/DarwinSDKInfo.h"
6263
#include "clang/Basic/TargetInfo.h"
6364
#include "clang/Basic/TargetOptions.h"
6465
#include "clang/Driver/Driver.h"
6566
#include "clang/Frontend/CompilerInstance.h"
6667
#include "clang/Frontend/TextDiagnosticPrinter.h"
6768
#include "clang/Lex/Preprocessor.h"
68-
6969
#include "clang/Lex/PreprocessorOptions.h"
7070
#include "llvm/ADT/ArrayRef.h"
7171
#include "llvm/ADT/STLExtras.h"
@@ -2634,6 +2634,7 @@ SwiftASTContext::CreateInstance(lldb::LanguageType language, Module &module,
26342634

26352635
swift::ModuleDecl *stdlib =
26362636
ast_context->getStdlibModule(can_create);
2637+
swift_ast_sp->m_post_first_import = true;
26372638
if (!stdlib || IsDWARFImported(*stdlib)) {
26382639
logError("couldn't load the Swift stdlib");
26392640
return {};
@@ -3031,6 +3032,24 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(
30313032
ConfigureResourceDirs(swift_ast_sp->GetCompilerInvocation(), resource_dir,
30323033
triple);
30333034
ConfigureModuleCachePath(*swift_ast_sp);
3035+
{
3036+
// ModuleInterfaceBuilder creates a separate CompilerInvocation to
3037+
// perform implicit Clang module imports. They will always use the SDK
3038+
// version as deployment target, even if that is in the future. To
3039+
// avoid building modules twice, match this behavior.
3040+
auto darwin_sdk_info = clang::parseDarwinSDKInfo(
3041+
*llvm::vfs::getRealFileSystem(), swift_ast_sp->GetPlatformSDKPath());
3042+
if (!darwin_sdk_info)
3043+
llvm::consumeError(darwin_sdk_info.takeError());
3044+
else if (*darwin_sdk_info) {
3045+
auto sdk_triple = triple;
3046+
sdk_triple.setOSName(std::string(triple.getOSTypeName(triple.getOS())) +
3047+
(*darwin_sdk_info)->getVersion().getAsString());
3048+
auto &ci_args = swift_ast_sp->GetClangImporterOptions().ExtraArgs;
3049+
ci_args.push_back("-target");
3050+
ci_args.push_back(sdk_triple.str());
3051+
}
3052+
}
30343053

30353054
std::vector<swift::PluginSearchOption> plugin_search_options;
30363055
std::vector<std::pair<std::string, bool>> module_search_paths;
@@ -3109,11 +3128,6 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(
31093128
framework_search_paths);
31103129
swift_ast_sp->SetCompilerInvocationLLDBOverrides();
31113130

3112-
if (!swift_ast_sp->GetClangImporter()) {
3113-
logError("couldn't create a ClangImporter");
3114-
return {};
3115-
}
3116-
31173131
// Initialize the compiler plugin search paths.
31183132
auto &opts = swift_ast_sp->GetSearchPathOptions();
31193133
opts.PluginSearchOpts.insert(opts.PluginSearchOpts.end(),
@@ -3173,22 +3187,13 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(
31733187
swift_ast_sp->RegisterSectionModules(*image_sp, module_names);
31743188
}
31753189

3176-
// FIXME: It should be sufficient to just import the sc.comp_unit's module .
3177-
if (!for_expressions && module_sp)
3178-
swift_ast_sp->ImportSectionModules(*module_sp, module_names);
3179-
3180-
if (target_sp)
3181-
LOG_PRINTF(GetLog(LLDBLog::Types), "((Target*)%p) = %p",
3182-
static_cast<void *>(target_sp.get()),
3183-
static_cast<void *>(swift_ast_sp.get()));
3184-
3185-
if (swift_ast_sp->HasFatalErrors()) {
3186-
logError(swift_ast_sp->GetFatalErrors().AsCString());
3187-
return {};
3188-
}
3189-
31903190
{
31913191
auto ast_context = swift_ast_sp->GetASTContext();
3192+
if (!ast_context) {
3193+
logError("couldn't initialize Swift cxompiler");
3194+
return {};
3195+
}
3196+
31923197
// Report progress on module importing by using a callback function in
31933198
// swift::ASTContext
31943199
Progress progress("Importing Swift standard library");
@@ -3209,12 +3214,27 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(
32093214
const bool can_create = true;
32103215
swift::ModuleDecl *stdlib =
32113216
ast_context->getStdlibModule(can_create);
3217+
swift_ast_sp->m_post_first_import = true;
32123218
if (!stdlib || IsDWARFImported(*stdlib)) {
32133219
logError("couldn't load the Swift stdlib");
32143220
return {};
32153221
}
32163222
}
32173223

3224+
// FIXME: It should be sufficient to just import the sc.comp_unit's module .
3225+
if (!for_expressions && module_sp)
3226+
swift_ast_sp->ImportSectionModules(*module_sp, module_names);
3227+
3228+
if (target_sp)
3229+
LOG_PRINTF(GetLog(LLDBLog::Types), "((Target*)%p) = %p",
3230+
static_cast<void *>(target_sp.get()),
3231+
static_cast<void *>(swift_ast_sp.get()));
3232+
3233+
if (swift_ast_sp->HasFatalErrors()) {
3234+
logError(swift_ast_sp->GetFatalErrors().AsCString());
3235+
return {};
3236+
}
3237+
32183238
return swift_ast_sp;
32193239
}
32203240

@@ -3334,6 +3354,7 @@ void SwiftASTContext::SetTriple(const SymbolContext &sc,
33343354

33353355
bool SwiftASTContext::SetTriple(const llvm::Triple triple, Module *module) {
33363356
VALID_OR_RETURN(false);
3357+
assert(!m_post_first_import);
33373358
if (triple.str().empty())
33383359
return false;
33393360

@@ -3496,12 +3517,10 @@ swift::ClangImporterOptions &SwiftASTContext::GetClangImporterOptions() {
34963517
const auto &props = ModuleList::GetGlobalModuleListProperties();
34973518
props.GetClangModulesCachePath().GetPath(path);
34983519
clang_importer_options.ModuleCachePath = std::string(path);
3499-
3500-
FileSpec clang_dir_spec;
3501-
clang_dir_spec = GetClangResourceDir();
3502-
if (FileSystem::Instance().Exists(clang_dir_spec))
3503-
clang_importer_options.OverrideResourceDir = clang_dir_spec.GetPath();
3520+
35043521
clang_importer_options.DebuggerSupport = true;
3522+
// Matches swift/Frontend.cpp
3523+
clang_importer_options.Optimization = "-Os";
35053524
clang_importer_options.PreferSerializedBridgingHeader =
35063525
props.GetSwiftPreferSerializedBridgingHeader();
35073526

@@ -3661,35 +3680,33 @@ ThreadSafeASTContext SwiftASTContext::GetASTContext() {
36613680
auto &clang_importer_options = GetClangImporterOptions();
36623681
if (!m_ast_context_ap->SearchPathOpts.getSDKPath().empty() ||
36633682
TargetHasNoSDK()) {
3664-
if (!clang_importer_options.OverrideResourceDir.empty()) {
3665-
// Create the DWARFImporterDelegate.
3666-
const auto &props = ModuleList::GetGlobalModuleListProperties();
3667-
if (props.GetUseSwiftDWARFImporter())
3668-
m_dwarfimporter_delegate_up =
3669-
std::make_unique<SwiftDWARFImporterDelegate>(*this);
3670-
auto importer_diags = getScopedDiagnosticConsumer();
3671-
clang_importer_ap = swift::ClangImporter::create(
3672-
*m_ast_context_ap, "", m_dependency_tracker.get(),
3673-
m_dwarfimporter_delegate_up.get());
3674-
3675-
// Handle any errors.
3676-
if (!clang_importer_ap || importer_diags->HasErrors()) {
3677-
AddDiagnostic(eSeverityError, "failed to create ClangImporter");
3678-
if (GetLog(LLDBLog::Types)) {
3679-
DiagnosticManager diagnostic_manager;
3680-
importer_diags->PrintDiagnostics(diagnostic_manager);
3681-
std::string underlying_error = diagnostic_manager.GetString();
3682-
HEALTH_LOG_PRINTF("failed to initialize ClangImporter: %s",
3683-
underlying_error.c_str());
3684-
}
3685-
}
3686-
if (clang_importer_ap) {
3687-
auto clangModuleCache = swift::getModuleCachePathFromClang(
3688-
clang_importer_ap->getClangInstance());
3689-
if (!clangModuleCache.empty())
3690-
moduleCachePath = clangModuleCache;
3683+
// Create the DWARFImporterDelegate.
3684+
const auto &props = ModuleList::GetGlobalModuleListProperties();
3685+
if (props.GetUseSwiftDWARFImporter())
3686+
m_dwarfimporter_delegate_up =
3687+
std::make_unique<SwiftDWARFImporterDelegate>(*this);
3688+
auto importer_diags = getScopedDiagnosticConsumer();
3689+
clang_importer_ap = swift::ClangImporter::create(
3690+
*m_ast_context_ap, "", m_dependency_tracker.get(),
3691+
m_dwarfimporter_delegate_up.get());
3692+
3693+
// Handle any errors.
3694+
if (!clang_importer_ap || importer_diags->HasErrors()) {
3695+
AddDiagnostic(eSeverityError, "failed to create ClangImporter");
3696+
if (GetLog(LLDBLog::Types)) {
3697+
DiagnosticManager diagnostic_manager;
3698+
importer_diags->PrintDiagnostics(diagnostic_manager);
3699+
std::string underlying_error = diagnostic_manager.GetString();
3700+
HEALTH_LOG_PRINTF("failed to initialize ClangImporter: %s",
3701+
underlying_error.c_str());
36913702
}
36923703
}
3704+
if (clang_importer_ap) {
3705+
auto clangModuleCache = swift::getModuleCachePathFromClang(
3706+
clang_importer_ap->getClangInstance());
3707+
if (!clangModuleCache.empty())
3708+
moduleCachePath = clangModuleCache;
3709+
}
36933710
}
36943711
LOG_PRINTF(GetLog(LLDBLog::Types), "Using Clang module cache path: %s",
36953712
moduleCachePath.c_str());

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,6 +1003,7 @@ class SwiftASTContext : public TypeSystemSwift {
10031003
bool m_has_explicit_modules = false;
10041004
mutable bool m_reported_fatal_error = false;
10051005
mutable bool m_logged_fatal_error = false;
1006+
bool m_post_first_import = false;
10061007

10071008
/// Whether this is a scratch or a module AST context.
10081009
bool m_is_scratch_context = false;

lldb/test/API/lang/swift/async/tasks/TestSwiftTaskBacktrace.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
class TestCase(TestBase):
77

8+
@skipIf(bugnumber="rdar://159531040")
89
@swiftTest
910
def test_backtrace_task_variable(self):
1011
self.build()
@@ -13,6 +14,7 @@ def test_backtrace_task_variable(self):
1314
)
1415
self.do_backtrace("task")
1516

17+
@skipIf(bugnumber="rdar://159531040")
1618
@swiftTest
1719
def test_backtrace_task_address(self):
1820
self.build()

lldb/test/API/lang/swift/async/tasks/TestSwiftTaskSelect.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from lldbsuite.test.lldbtest import TestBase
44
import lldbsuite.test.lldbutil as lldbutil
55

6-
6+
@skipIf(bugnumber="rdar://159531153")
77
class TestCase(TestBase):
88

99
@swiftTest

lldb/test/API/lang/swift/break_by_partial_name/TestSwiftBreakByPartialName.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from lldbsuite.test.decorators import *
1919
import lldbsuite.test.lldbutil as lldbutil
2020

21-
21+
@skipIf(bugnumber = "rdar://159531198")
2222
class SwiftPartialBreakTest(TestBase):
2323
@swiftTest
2424
def test_swift_partial_break(self):

lldb/test/API/lang/swift/clangimporter/fmodule_flags/TestSwiftFModuleFlags.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import lldbsuite.test.lldbutil as lldbutil
55
import os
66

7+
@skipIf(bugnumber = "rdar://159531233")
78
class TestSwiftFModuleFlags(TestBase):
89
@skipIf(macos_version=["<", "14.0"])
910
@skipIfDarwinEmbedded

lldb/test/API/lang/swift/conditional_breakpoints/TestSwiftConditionalBreakpoint.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from lldbsuite.test.decorators import *
1818
import lldbsuite.test.lldbutil as lldbutil
1919

20-
20+
@skipIf(bugnumber = "rdar://159531288")
2121
class TestSwiftConditionalBreakpoint(TestBase):
2222
@swiftTest
2323
def test_swift_conditional_breakpoint(self):

lldb/test/API/lang/swift/cxx_interop/backward/stepping/TestSwiftBackwardInteropStepping.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from lldbsuite.test.lldbtest import *
66
from lldbsuite.test.decorators import *
77

8-
8+
@skipIf(bugnumber="rdar://159531057")
99
class TestSwiftBackwardInteropStepping(TestBase):
1010

1111
def setup(self, bkpt_str):

lldb/test/API/lang/swift/embedded/frame_variable/TestSwiftEmbeddedFrameVariable.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from lldbsuite.test.decorators import *
44
import lldbsuite.test.lldbutil as lldbutil
55

6-
6+
@skipIf(bugnumber = "rdar://159531308")
77
class TestSwiftEmbeddedFrameVariable(TestBase):
88
@skipUnlessDarwin
99
@swiftTest

lldb/test/API/lang/swift/expression/equality_operators/TestEqualityOperators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def execute_command(command):
3030
(exit_status, output) = subprocess.getstatusoutput(command)
3131
return exit_status
3232

33-
33+
@skipIf(bugnumber = "rdar://159531216")
3434
class TestUnitTests(TestBase):
3535
@swiftTest
3636
@skipIf(debug_info=no_match(["dsym"]), bugnumber="This test is building a dSYM")

0 commit comments

Comments
 (0)