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