Index: include/lldb/Utility/ArchSpec.h =================================================================== --- include/lldb/Utility/ArchSpec.h +++ include/lldb/Utility/ArchSpec.h @@ -377,19 +377,19 @@ } bool TripleVendorIsUnspecifiedUnknown() const { - return m_triple.getVendor() == llvm::Triple::UnknownVendor && - m_triple.getVendorName().empty(); + return m_triple.getVendor() == llvm::Triple::UnknownVendor; } bool TripleOSWasSpecified() const { return !m_triple.getOSName().empty(); } - bool TripleEnvironmentWasSpecified() const { - return !m_triple.getEnvironmentName().empty(); + bool TripleOSIsUnspecifiedUnknown() const { + return m_triple.getOS() == llvm::Triple::UnknownOS; } - bool TripleOSIsUnspecifiedUnknown() const { - return m_triple.getOS() == llvm::Triple::UnknownOS && - m_triple.getOSName().empty(); + bool TripleEnvironmentWasSpecified() const { return m_triple.hasEnvironment(); } + + bool TripleEnvironmentIsUnspecifiedUnknown() const { + return m_triple.getEnvironment() == llvm::Triple::UnknownEnvironment; } //------------------------------------------------------------------ Index: source/Utility/ArchSpec.cpp =================================================================== --- source/Utility/ArchSpec.cpp +++ source/Utility/ArchSpec.cpp @@ -903,10 +903,10 @@ if (other.GetCore() != eCore_uknownMach64) UpdateCore(); } - if (GetTriple().getEnvironment() == llvm::Triple::UnknownEnvironment && - !TripleVendorWasSpecified()) { - if (other.TripleVendorWasSpecified()) - GetTriple().setEnvironment(other.GetTriple().getEnvironment()); + if (TripleEnvironmentIsUnspecifiedUnknown() && + !other.TripleEnvironmentIsUnspecifiedUnknown() && + !TripleVendorWasSpecified() && other.TripleVendorWasSpecified()) { + GetTriple().setEnvironment(other.GetTriple().getEnvironment()); } // If this and other are both arm ArchSpecs and this ArchSpec is a generic // "some kind of arm" spec but the other ArchSpec is a specific arm core, Index: unittests/Utility/ArchSpecTest.cpp =================================================================== --- unittests/Utility/ArchSpecTest.cpp +++ unittests/Utility/ArchSpecTest.cpp @@ -232,3 +232,58 @@ EXPECT_FALSE(ArchSpec()); EXPECT_TRUE(ArchSpec("x86_64-pc-linux")); } + +TEST(ArchSpecTest, TripleComponentsWereSpecified) { + { + ArchSpec A("x86-unknown-unknown"); + ASSERT_FALSE(A.TripleVendorWasSpecified()); + ASSERT_FALSE(A.TripleOSWasSpecified()); + ASSERT_FALSE(A.TripleEnvironmentWasSpecified()); + + ASSERT_TRUE(A.TripleVendorIsUnspecifiedUnknown()); + ASSERT_TRUE(A.TripleOSIsUnspecifiedUnknown()); + ASSERT_TRUE(A.TripleEnvironmentIsUnspecifiedUnknown()); + } + { + ArchSpec A("arm-pc-linux-android"); + ASSERT_TRUE(A.TripleVendorWasSpecified()); + ASSERT_TRUE(A.TripleOSWasSpecified()); + ASSERT_TRUE(A.TripleEnvironmentWasSpecified()); + + ASSERT_FALSE(A.TripleVendorIsUnspecifiedUnknown()); + ASSERT_FALSE(A.TripleOSIsUnspecifiedUnknown()); + ASSERT_FALSE(A.TripleEnvironmentIsUnspecifiedUnknown()); + } + { + ArchSpec A("aarch64-unknown-linux-android"); + ASSERT_TRUE(A.TripleVendorWasSpecified()); + ASSERT_TRUE(A.TripleOSWasSpecified()); + ASSERT_TRUE(A.TripleEnvironmentWasSpecified()); + + ASSERT_TRUE(A.TripleVendorIsUnspecifiedUnknown()); + ASSERT_FALSE(A.TripleOSIsUnspecifiedUnknown()); + ASSERT_FALSE(A.TripleEnvironmentIsUnspecifiedUnknown()); + } + { + ArchSpec A(""); + ASSERT_FALSE(A.TripleVendorWasSpecified()); + ASSERT_FALSE(A.TripleOSWasSpecified()); + ASSERT_FALSE(A.TripleEnvironmentWasSpecified()); + + ASSERT_TRUE(A.TripleVendorIsUnspecifiedUnknown()); + ASSERT_TRUE(A.TripleOSIsUnspecifiedUnknown()); + ASSERT_TRUE(A.TripleEnvironmentIsUnspecifiedUnknown()); + } + { + ArchSpec A("arm---"); + // Note: llvm::Triple::normalize interprets empty-string as "unknown" + // instead of unspecified. + ASSERT_TRUE(A.TripleVendorWasSpecified()); + ASSERT_TRUE(A.TripleOSWasSpecified()); + ASSERT_TRUE(A.TripleEnvironmentWasSpecified()); + + ASSERT_TRUE(A.TripleVendorIsUnspecifiedUnknown()); + ASSERT_TRUE(A.TripleOSIsUnspecifiedUnknown()); + ASSERT_TRUE(A.TripleEnvironmentIsUnspecifiedUnknown()); + } +}