Index: llvm/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp =================================================================== --- llvm/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp +++ llvm/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp @@ -41,7 +41,7 @@ template void TestAllForms() { - Triple Triple = getHostTripleForAddrSize(sizeof(AddrType)); + Triple Triple = getDefaultTargetTripleForAddrSize(sizeof(AddrType)); if (!isConfigurationSupported(Triple)) return; @@ -455,7 +455,7 @@ } template void TestChildren() { - Triple Triple = getHostTripleForAddrSize(sizeof(AddrType)); + Triple Triple = getDefaultTargetTripleForAddrSize(sizeof(AddrType)); if (!isConfigurationSupported(Triple)) return; @@ -585,7 +585,7 @@ } template void TestReferences() { - Triple Triple = getHostTripleForAddrSize(sizeof(AddrType)); + Triple Triple = getDefaultTargetTripleForAddrSize(sizeof(AddrType)); if (!isConfigurationSupported(Triple)) return; @@ -835,7 +835,7 @@ } template void TestAddresses() { - Triple Triple = getHostTripleForAddrSize(sizeof(AddrType)); + Triple Triple = getDefaultTargetTripleForAddrSize(sizeof(AddrType)); if (!isConfigurationSupported(Triple)) return; @@ -1007,7 +1007,7 @@ } TEST(DWARFDebugInfo, TestStringOffsets) { - Triple Triple = getHostTripleForAddrSize(sizeof(void *)); + Triple Triple = getDefaultTargetTripleForDefaultAddrSize(); if (!isConfigurationSupported(Triple)) return; @@ -1071,7 +1071,7 @@ } TEST(DWARFDebugInfo, TestEmptyStringOffsets) { - Triple Triple = getHostTripleForAddrSize(sizeof(void *)); + Triple Triple = getDefaultTargetTripleForDefaultAddrSize(); if (!isConfigurationSupported(Triple)) return; @@ -1100,7 +1100,7 @@ } TEST(DWARFDebugInfo, TestRelations) { - Triple Triple = getHostTripleForAddrSize(sizeof(void *)); + Triple Triple = getDefaultTargetTripleForDefaultAddrSize(); if (!isConfigurationSupported(Triple)) return; @@ -1287,7 +1287,7 @@ } TEST(DWARFDebugInfo, TestChildIterators) { - Triple Triple = getHostTripleForAddrSize(sizeof(void *)); + Triple Triple = getDefaultTargetTripleForDefaultAddrSize(); if (!isConfigurationSupported(Triple)) return; @@ -1401,7 +1401,7 @@ } TEST(DWARFDebugInfo, TestAttributeIterators) { - Triple Triple = getHostTripleForAddrSize(sizeof(void *)); + Triple Triple = getDefaultTargetTripleForDefaultAddrSize(); if (!isConfigurationSupported(Triple)) return; @@ -1463,7 +1463,7 @@ } TEST(DWARFDebugInfo, TestFindRecurse) { - Triple Triple = getHostTripleForAddrSize(sizeof(void *)); + Triple Triple = getDefaultTargetTripleForDefaultAddrSize(); if (!isConfigurationSupported(Triple)) return; @@ -1677,7 +1677,7 @@ } TEST(DWARFDebugInfo, TestFindAttrs) { - Triple Triple = getHostTripleForAddrSize(sizeof(void *)); + Triple Triple = getDefaultTargetTripleForDefaultAddrSize(); if (!isConfigurationSupported(Triple)) return; @@ -1740,7 +1740,7 @@ } TEST(DWARFDebugInfo, TestImplicitConstAbbrevs) { - Triple Triple = getHostTripleForAddrSize(sizeof(void *)); + Triple Triple = getDefaultTargetTripleForDefaultAddrSize(); if (!isConfigurationSupported(Triple)) return; Index: llvm/unittests/DebugInfo/DWARF/DWARFDebugLineTest.cpp =================================================================== --- llvm/unittests/DebugInfo/DWARF/DWARFDebugLineTest.cpp +++ llvm/unittests/DebugInfo/DWARF/DWARFDebugLineTest.cpp @@ -37,7 +37,7 @@ } bool setupGenerator(uint16_t Version = 4) { - Triple T = getHostTripleForAddrSize(8); + Triple T = getDefaultTargetTripleForAddrSize(8); if (!isConfigurationSupported(T)) return false; auto ExpectedGenerator = Generator::create(T, Version); @@ -50,8 +50,9 @@ Context = createContext(); assert(Context != nullptr && "test state is not valid"); const DWARFObject &Obj = Context->getDWARFObj(); - LineData = DWARFDataExtractor(Obj, Obj.getLineSection(), - sys::IsLittleEndianHost, 8); + LineData = DWARFDataExtractor( + Obj, Obj.getLineSection(), + getDefaultTargetTripleForAddrSize(8).isLittleEndian(), 8); } std::unique_ptr createContext() { Index: llvm/unittests/DebugInfo/DWARF/DwarfUtils.h =================================================================== --- llvm/unittests/DebugInfo/DWARF/DwarfUtils.h +++ llvm/unittests/DebugInfo/DWARF/DwarfUtils.h @@ -18,7 +18,8 @@ namespace dwarf { namespace utils { -Triple getHostTripleForAddrSize(uint8_t AddrSize); +Triple getDefaultTargetTripleForAddrSize(uint8_t AddrSize); +Triple getDefaultTargetTripleForDefaultAddrSize(); bool isConfigurationSupported(Triple &T); } // end namespace utils Index: llvm/unittests/DebugInfo/DWARF/DwarfUtils.cpp =================================================================== --- llvm/unittests/DebugInfo/DWARF/DwarfUtils.cpp +++ llvm/unittests/DebugInfo/DWARF/DwarfUtils.cpp @@ -25,9 +25,23 @@ } } -Triple llvm::dwarf::utils::getHostTripleForAddrSize(uint8_t AddrSize) { - Triple T(Triple::normalize(LLVM_HOST_TRIPLE)); +Triple llvm::dwarf::utils::getDefaultTargetTripleForDefaultAddrSize() { + // There are cases where the LLVM_DEFAULT_TARGET_TRIPLE may be empty, so + // fall back to the host triple if it is. + Triple T((*LLVM_DEFAULT_TARGET_TRIPLE == '\0') + ? Triple::normalize(LLVM_HOST_TRIPLE) + : Triple::normalize(LLVM_DEFAULT_TARGET_TRIPLE)); + return T; +} + +Triple llvm::dwarf::utils::getDefaultTargetTripleForAddrSize(uint8_t AddrSize) { + Triple T = getDefaultTargetTripleForDefaultAddrSize(); + + assert((AddrSize == 4 || AddrSize == 8) && + "Only 32-bit/64-bit address size variants are supported"); + // If a 32-bit/64-bit address size was specified, try to convert the triple + // if it is for the wrong variant. if (AddrSize == 8 && T.isArch32Bit()) return T.get64BitArchVariant(); if (AddrSize == 4 && T.isArch64Bit())