@@ -2908,20 +2908,42 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(
2908
2908
return exe_module_sp->GetArchitecture ().GetTriple ();
2909
2909
};
2910
2910
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
+ }
2913
2917
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 ()) {
2915
2937
// If a fully specified triple was passed in, for example
2916
2938
// through CreateTargetWithFileAndTargetTriple(), prefer that.
2917
2939
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 ;
2920
2942
} else {
2921
2943
// Underspecified means that one or more of vendor, os, or os
2922
2944
// version (Darwin only) is missing.
2923
2945
LOG_PRINTF (GetLog (LLDBLog::Types), " Underspecified target triple %s." ,
2924
- target_triple .str ().c_str ());
2946
+ preferred_triple .str ().c_str ());
2925
2947
llvm::VersionTuple platform_version;
2926
2948
PlatformSP platform_sp (target.GetPlatform ());
2927
2949
if (platform_sp)
@@ -2938,16 +2960,16 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(
2938
2960
// present, since there might be some ambiguity about the
2939
2961
// plaform (e.g., ios-macabi runs on the macOS, but uses iOS
2940
2962
// 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) {
2943
2965
LOG_PRINTF (GetLog (LLDBLog::Types), " Completing triple based on platform." );
2944
2966
2945
2967
llvm::SmallString<32 > buffer;
2946
2968
{
2947
2969
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 ());
2951
2973
os << platform_version.getAsString ();
2952
2974
}
2953
2975
computed_triple = llvm::Triple (buffer);
0 commit comments