@@ -2906,20 +2906,42 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(
2906
2906
return exe_module_sp->GetArchitecture ().GetTriple ();
2907
2907
};
2908
2908
2909
- llvm::Triple computed_triple;
2910
- llvm::Triple target_triple = target.GetArchitecture ().GetTriple ();
2909
+ ArchSpec module_arch;
2910
+ llvm::Triple module_triple;
2911
+ if (sc.module_sp ) {
2912
+ module_arch = sc.module_sp ->GetArchitecture ();
2913
+ module_triple = module_arch.GetTriple ();
2914
+ }
2911
2915
2912
- if (target.GetArchitecture ().IsFullySpecifiedTriple ()) {
2916
+ ArchSpec target_arch = target.GetArchitecture ();
2917
+ llvm::Triple target_triple = target_arch.GetTriple ();
2918
+
2919
+ ArchSpec preferred_arch;
2920
+ llvm::Triple preferred_triple;
2921
+ if (module_arch && module_arch.IsFullySpecifiedTriple ()) {
2922
+ LOG_PRINTF (GetLog (LLDBLog::Types),
2923
+ " Preferring module triple %s over target triple %s." ,
2924
+ module_triple.str ().c_str (), target_triple.str ().c_str ());
2925
+ preferred_arch = module_arch;
2926
+ preferred_triple = module_triple;
2927
+ } else {
2928
+ // When no viable module triple, fallback to the target triple.
2929
+ preferred_arch = target_arch;
2930
+ preferred_triple = target_triple;
2931
+ }
2932
+
2933
+ llvm::Triple computed_triple;
2934
+ if (preferred_arch.IsFullySpecifiedTriple ()) {
2913
2935
// If a fully specified triple was passed in, for example
2914
2936
// through CreateTargetWithFileAndTargetTriple(), prefer that.
2915
2937
LOG_PRINTF (GetLog (LLDBLog::Types), " Fully specified target triple %s." ,
2916
- target_triple .str ().c_str ());
2917
- computed_triple = target_triple ;
2938
+ preferred_triple .str ().c_str ());
2939
+ computed_triple = preferred_triple ;
2918
2940
} else {
2919
2941
// Underspecified means that one or more of vendor, os, or os
2920
2942
// version (Darwin only) is missing.
2921
2943
LOG_PRINTF (GetLog (LLDBLog::Types), " Underspecified target triple %s." ,
2922
- target_triple .str ().c_str ());
2944
+ preferred_triple .str ().c_str ());
2923
2945
llvm::VersionTuple platform_version;
2924
2946
PlatformSP platform_sp (target.GetPlatform ());
2925
2947
if (platform_sp)
@@ -2936,16 +2958,16 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(
2936
2958
// present, since there might be some ambiguity about the
2937
2959
// plaform (e.g., ios-macabi runs on the macOS, but uses iOS
2938
2960
// version numbers).
2939
- if (!platform_version.empty () &&
2940
- target_triple. getEnvironment () == llvm::Triple::UnknownEnvironment) {
2961
+ if (!platform_version.empty () && preferred_triple. getEnvironment () ==
2962
+ llvm::Triple::UnknownEnvironment) {
2941
2963
LOG_PRINTF (GetLog (LLDBLog::Types), " Completing triple based on platform." );
2942
2964
2943
2965
llvm::SmallString<32 > buffer;
2944
2966
{
2945
2967
llvm::raw_svector_ostream os (buffer);
2946
- os << target_triple .getArchName () << ' -' ;
2947
- os << target_triple .getVendorName () << ' -' ;
2948
- os << llvm::Triple::getOSTypeName (target_triple .getOS ());
2968
+ os << preferred_triple .getArchName () << ' -' ;
2969
+ os << preferred_triple .getVendorName () << ' -' ;
2970
+ os << llvm::Triple::getOSTypeName (preferred_triple .getOS ());
2949
2971
os << platform_version.getAsString ();
2950
2972
}
2951
2973
computed_triple = llvm::Triple (buffer);
0 commit comments