Skip to content

Commit 816ac8f

Browse files
committed
Rename variables for separation, clarity; Add test
1 parent ab174a1 commit 816ac8f

File tree

2 files changed

+53
-18
lines changed

2 files changed

+53
-18
lines changed

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

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2909,32 +2909,39 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(
29092909
return exe_module_sp->GetArchitecture().GetTriple();
29102910
};
29112911

2912-
ArchSpec active_arch;
2913-
llvm::Triple active_triple;
2912+
ArchSpec module_arch;
2913+
llvm::Triple module_triple;
29142914
if (sc.module_sp) {
2915-
active_arch = sc.module_sp->GetArchitecture();
2916-
active_triple = active_arch.GetTriple();
2915+
module_arch = sc.module_sp->GetArchitecture();
2916+
module_triple = module_arch.GetTriple();
29172917
}
29182918

2919-
// When no module triple, fallback to the target triple.
2920-
if (!active_arch || active_triple == llvm::Triple()) {
2921-
active_arch = target.GetArchitecture();
2922-
active_triple = active_arch.GetTriple();
2919+
ArchSpec target_arch = target.GetArchitecture();
2920+
llvm::Triple target_triple = target_arch.GetTriple();
2921+
2922+
ArchSpec preferred_arch;
2923+
llvm::Triple preferred_triple;
2924+
if (module_arch && module_triple != llvm::Triple()) {
2925+
preferred_arch = module_arch;
2926+
preferred_triple = module_triple;
2927+
} else {
2928+
// When no module triple, fallback to the target triple.
2929+
preferred_arch = target_arch;
2930+
preferred_triple = target_triple;
29232931
}
29242932

29252933
llvm::Triple computed_triple;
2926-
2927-
if (active_arch.IsFullySpecifiedTriple()) {
2934+
if (preferred_arch.IsFullySpecifiedTriple()) {
29282935
// If a fully specified triple was passed in, for example
29292936
// through CreateTargetWithFileAndTargetTriple(), prefer that.
29302937
LOG_PRINTF(GetLog(LLDBLog::Types), "Fully specified target triple %s.",
2931-
active_triple.str().c_str());
2932-
computed_triple = active_arch.GetTriple();
2938+
preferred_triple.str().c_str());
2939+
computed_triple = preferred_triple;
29332940
} else {
29342941
// Underspecified means that one or more of vendor, os, or os
29352942
// version (Darwin only) is missing.
29362943
LOG_PRINTF(GetLog(LLDBLog::Types), "Underspecified target triple %s.",
2937-
active_triple.str().c_str());
2944+
preferred_triple.str().c_str());
29382945
llvm::VersionTuple platform_version;
29392946
PlatformSP platform_sp(target.GetPlatform());
29402947
if (platform_sp)
@@ -2951,16 +2958,16 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(
29512958
// present, since there might be some ambiguity about the
29522959
// plaform (e.g., ios-macabi runs on the macOS, but uses iOS
29532960
// version numbers).
2954-
if (!platform_version.empty() &&
2955-
active_triple.getEnvironment() == llvm::Triple::UnknownEnvironment) {
2961+
if (!platform_version.empty() && preferred_triple.getEnvironment() ==
2962+
llvm::Triple::UnknownEnvironment) {
29562963
LOG_PRINTF(GetLog(LLDBLog::Types), "Completing triple based on platform.");
29572964

29582965
llvm::SmallString<32> buffer;
29592966
{
29602967
llvm::raw_svector_ostream os(buffer);
2961-
os << active_triple.getArchName() << '-';
2962-
os << active_triple.getVendorName() << '-';
2963-
os << llvm::Triple::getOSTypeName(active_triple.getOS());
2968+
os << preferred_triple.getArchName() << '-';
2969+
os << preferred_triple.getVendorName() << '-';
2970+
os << llvm::Triple::getOSTypeName(preferred_triple.getOS());
29642971
os << platform_version.getAsString();
29652972
}
29662973
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)