Skip to content

Commit d429296

Browse files
author
git apple-llvm automerger
committed
Merge commit '450d47080437' from swift/release/6.0 into stable/20230725
2 parents 96ec4bf + 450d470 commit d429296

File tree

3 files changed

+70
-13
lines changed

3 files changed

+70
-13
lines changed

lldb/source/Plugins/ExpressionParser/Swift/SwiftUserExpression.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -731,8 +731,15 @@ exe_scope = exe_ctx.GetBestExecutionContextScope();
731731
return error("could not create a Swift scratch context: ",
732732
m_err.AsCString());
733733

734-
const SymbolContext *sc =
735-
&frame->GetSymbolContext(lldb::eSymbolContextFunction);
734+
// For playgrounds, the target triple should be used for expression
735+
// evaluation, not the current module. This requires disabling precise
736+
// compiler invocations.
737+
//
738+
// To disable precise compiler invocations, pass a null SymbolContext.
739+
const SymbolContext *sc = nullptr;
740+
if (!m_runs_in_playground_or_repl)
741+
sc = &frame->GetSymbolContext(lldb::eSymbolContextFunction);
742+
736743
auto *swift_ast_ctx = m_swift_scratch_ctx->get()->GetSwiftASTContext(sc);
737744
m_swift_ast_ctx =
738745
llvm::dyn_cast_or_null<SwiftASTContextForExpressions>(swift_ast_ctx);

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

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2908,20 +2908,42 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(
29082908
return exe_module_sp->GetArchitecture().GetTriple();
29092909
};
29102910

2911-
llvm::Triple computed_triple;
2912-
llvm::Triple target_triple = target.GetArchitecture().GetTriple();
2911+
ArchSpec module_arch;
2912+
llvm::Triple module_triple;
2913+
if (sc.module_sp) {
2914+
module_arch = sc.module_sp->GetArchitecture();
2915+
module_triple = module_arch.GetTriple();
2916+
}
29132917

2914-
if (target.GetArchitecture().IsFullySpecifiedTriple()) {
2918+
ArchSpec target_arch = target.GetArchitecture();
2919+
llvm::Triple target_triple = target_arch.GetTriple();
2920+
2921+
ArchSpec preferred_arch;
2922+
llvm::Triple preferred_triple;
2923+
if (module_arch && module_arch.IsFullySpecifiedTriple()) {
2924+
LOG_PRINTF(GetLog(LLDBLog::Types),
2925+
"Preferring module triple %s over target triple %s.",
2926+
module_triple.str().c_str(), target_triple.str().c_str());
2927+
preferred_arch = module_arch;
2928+
preferred_triple = module_triple;
2929+
} else {
2930+
// When no viable module triple, fallback to the target triple.
2931+
preferred_arch = target_arch;
2932+
preferred_triple = target_triple;
2933+
}
2934+
2935+
llvm::Triple computed_triple;
2936+
if (preferred_arch.IsFullySpecifiedTriple()) {
29152937
// If a fully specified triple was passed in, for example
29162938
// through CreateTargetWithFileAndTargetTriple(), prefer that.
29172939
LOG_PRINTF(GetLog(LLDBLog::Types), "Fully specified target triple %s.",
2918-
target_triple.str().c_str());
2919-
computed_triple = target_triple;
2940+
preferred_triple.str().c_str());
2941+
computed_triple = preferred_triple;
29202942
} else {
29212943
// Underspecified means that one or more of vendor, os, or os
29222944
// version (Darwin only) is missing.
29232945
LOG_PRINTF(GetLog(LLDBLog::Types), "Underspecified target triple %s.",
2924-
target_triple.str().c_str());
2946+
preferred_triple.str().c_str());
29252947
llvm::VersionTuple platform_version;
29262948
PlatformSP platform_sp(target.GetPlatform());
29272949
if (platform_sp)
@@ -2938,16 +2960,16 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(
29382960
// present, since there might be some ambiguity about the
29392961
// plaform (e.g., ios-macabi runs on the macOS, but uses iOS
29402962
// version numbers).
2941-
if (!platform_version.empty() &&
2942-
target_triple.getEnvironment() == llvm::Triple::UnknownEnvironment) {
2963+
if (!platform_version.empty() && preferred_triple.getEnvironment() ==
2964+
llvm::Triple::UnknownEnvironment) {
29432965
LOG_PRINTF(GetLog(LLDBLog::Types), "Completing triple based on platform.");
29442966

29452967
llvm::SmallString<32> buffer;
29462968
{
29472969
llvm::raw_svector_ostream os(buffer);
2948-
os << target_triple.getArchName() << '-';
2949-
os << target_triple.getVendorName() << '-';
2950-
os << llvm::Triple::getOSTypeName(target_triple.getOS());
2970+
os << preferred_triple.getArchName() << '-';
2971+
os << preferred_triple.getVendorName() << '-';
2972+
os << llvm::Triple::getOSTypeName(preferred_triple.getOS());
29512973
os << platform_version.getAsString();
29522974
}
29532975
computed_triple = llvm::Triple(buffer);

lldb/test/API/lang/swift/deployment_target/TestSwiftDeploymentTarget.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,31 @@ def test_swift_deployment_target_from_macho(self):
6666
self.filecheck('platform shell cat ""%s"' % log, __file__)
6767
# CHECK: SwiftASTContextForExpressions::SetTriple({{.*}}apple-macosx11.0.0
6868
# CHECK-NOT: SwiftASTContextForExpressions::RegisterSectionModules("a.out"){{.*}} AST Data blobs
69+
70+
@skipUnlessDarwin # This test uses macOS triples explicitly.
71+
@skipIfDarwinEmbedded
72+
@skipIf(macos_version=["<", "11.1"])
73+
@skipIf(setting=("symbols.swift-precise-compiler-invocation", "false"))
74+
@swiftTest
75+
def test_swift_precise_compiler_invocation_triple(self):
76+
"""
77+
Ensure expressions prefer the target triple of their module, as it may
78+
differ from the target triple of the target. This is necessary for
79+
explicitly built modules.
80+
"""
81+
self.build()
82+
log = self.getBuildArtifact("types.log")
83+
self.runCmd(f'log enable lldb types -f "{log}"')
84+
lldbutil.run_to_source_breakpoint(
85+
self, "break here", lldb.SBFileSpec("NewerTarget.swift")
86+
)
87+
self.expect(
88+
"image list -t libNewerTarget.dylib",
89+
substrs=["-apple-macosx11.1.0"],
90+
)
91+
self.expect("expression self", substrs=["i = 23"])
92+
self.filecheck(
93+
f'platform shell cat "{log}"', __file__, "-check-prefix=CHECK-PRECISE"
94+
)
95+
# CHECK-PRECISE: SwiftASTContextForExpressions(module: "NewerTarget", cu: "NewerTarget.swift")::CreateInstance() -- Fully specified target triple {{.*}}-apple-macosx11.1.0
96+
# CHECK-PRECISE: SwiftASTContextForExpressions(module: "NewerTarget", cu: "NewerTarget.swift")::SetTriple("{{.*}}-apple-macosx11.1.0")

0 commit comments

Comments
 (0)