[Lldb-commits] [lldb] r354933 - [Utility] Remove Triple{Environment, OS, Vendor}IsUnspecifiedUnknown from ArchSpec
Alex Langford via lldb-commits
lldb-commits at lists.llvm.org
Tue Feb 26 15:50:20 PST 2019
Author: xiaobai
Date: Tue Feb 26 15:50:19 2019
New Revision: 354933
URL: http://llvm.org/viewvc/llvm-project?rev=354933&view=rev
Log:
[Utility] Remove Triple{Environment,OS,Vendor}IsUnspecifiedUnknown from ArchSpec
Summary:
These functions should always return the opposite of the
`Triple{Environment,OS,Vendor}WasSpecified` functions. Unspecified unknown is
the same as unspecified, which is why one set of functions should give us what
we want. It's possible to have specified unknown, which is why we can't just
rely on checking the enum values of vendor/os/environment. We must also ensure
that the names of these are empty and not "unknown".
Differential Revision: https://reviews.llvm.org/D58653
Modified:
lldb/trunk/include/lldb/Utility/ArchSpec.h
lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
lldb/trunk/source/Utility/ArchSpec.cpp
lldb/trunk/unittests/Utility/ArchSpecTest.cpp
Modified: lldb/trunk/include/lldb/Utility/ArchSpec.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Utility/ArchSpec.h?rev=354933&r1=354932&r2=354933&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Utility/ArchSpec.h (original)
+++ lldb/trunk/include/lldb/Utility/ArchSpec.h Tue Feb 26 15:50:19 2019
@@ -376,20 +376,10 @@ public:
return !m_triple.getVendorName().empty();
}
- bool TripleVendorIsUnspecifiedUnknown() const {
- return m_triple.getVendor() == llvm::Triple::UnknownVendor &&
- m_triple.getVendorName().empty();
- }
-
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 &&
- m_triple.getOSName().empty();
+ return m_triple.hasEnvironment();
}
//------------------------------------------------------------------
Modified: lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp?rev=354933&r1=354932&r2=354933&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp (original)
+++ lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp Tue Feb 26 15:50:19 2019
@@ -3309,7 +3309,7 @@ ArchSpec ObjectFileELF::GetArchitecture(
}
if (CalculateType() == eTypeCoreFile &&
- m_arch_spec.TripleOSIsUnspecifiedUnknown()) {
+ !m_arch_spec.TripleOSWasSpecified()) {
// Core files don't have section headers yet they have PT_NOTE program
// headers that might shed more light on the architecture
for (const elf::ELFProgramHeader &H : ProgramHeaders()) {
Modified: lldb/trunk/source/Utility/ArchSpec.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Utility/ArchSpec.cpp?rev=354933&r1=354932&r2=354933&view=diff
==============================================================================
--- lldb/trunk/source/Utility/ArchSpec.cpp (original)
+++ lldb/trunk/source/Utility/ArchSpec.cpp Tue Feb 26 15:50:19 2019
@@ -889,10 +889,9 @@ bool ArchSpec::ContainsOnlyArch(const ll
}
void ArchSpec::MergeFrom(const ArchSpec &other) {
- if (TripleVendorIsUnspecifiedUnknown() &&
- !other.TripleVendorIsUnspecifiedUnknown())
+ if (!TripleVendorWasSpecified() && other.TripleVendorWasSpecified())
GetTriple().setVendor(other.GetTriple().getVendor());
- if (TripleOSIsUnspecifiedUnknown() && !other.TripleOSIsUnspecifiedUnknown())
+ if (!TripleOSWasSpecified() && other.TripleVendorWasSpecified())
GetTriple().setOS(other.GetTriple().getOS());
if (GetTriple().getArch() == llvm::Triple::UnknownArch) {
GetTriple().setArch(other.GetTriple().getArch());
@@ -903,8 +902,8 @@ void ArchSpec::MergeFrom(const ArchSpec
if (other.GetCore() != eCore_uknownMach64)
UpdateCore();
}
- if (GetTriple().getEnvironment() == llvm::Triple::UnknownEnvironment &&
- !TripleVendorWasSpecified()) {
+ if (!TripleEnvironmentWasSpecified() &&
+ other.TripleEnvironmentWasSpecified() && !TripleVendorWasSpecified()) {
if (other.TripleVendorWasSpecified())
GetTriple().setEnvironment(other.GetTriple().getEnvironment());
}
Modified: lldb/trunk/unittests/Utility/ArchSpecTest.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Utility/ArchSpecTest.cpp?rev=354933&r1=354932&r2=354933&view=diff
==============================================================================
--- lldb/trunk/unittests/Utility/ArchSpecTest.cpp (original)
+++ lldb/trunk/unittests/Utility/ArchSpecTest.cpp Tue Feb 26 15:50:19 2019
@@ -232,3 +232,76 @@ TEST(ArchSpecTest, OperatorBool) {
EXPECT_FALSE(ArchSpec());
EXPECT_TRUE(ArchSpec("x86_64-pc-linux"));
}
+
+TEST(ArchSpecTest, TripleComponentsWereSpecified) {
+ {
+ ArchSpec A("");
+ ArchSpec B("-");
+ ArchSpec C("--");
+ ArchSpec D("---");
+
+ ASSERT_FALSE(A.TripleVendorWasSpecified());
+ ASSERT_FALSE(A.TripleOSWasSpecified());
+ ASSERT_FALSE(A.TripleEnvironmentWasSpecified());
+
+ ASSERT_FALSE(B.TripleVendorWasSpecified());
+ ASSERT_FALSE(B.TripleOSWasSpecified());
+ ASSERT_FALSE(B.TripleEnvironmentWasSpecified());
+
+ ASSERT_FALSE(C.TripleVendorWasSpecified());
+ ASSERT_FALSE(C.TripleOSWasSpecified());
+ ASSERT_FALSE(C.TripleEnvironmentWasSpecified());
+
+ ASSERT_FALSE(D.TripleVendorWasSpecified());
+ ASSERT_FALSE(D.TripleOSWasSpecified());
+ ASSERT_FALSE(D.TripleEnvironmentWasSpecified());
+ }
+ {
+ // TODO: llvm::Triple::normalize treats the missing components from these
+ // triples as specified unknown components instead of unspecified
+ // components. We need to either change the behavior in llvm or work around
+ // this in lldb.
+ ArchSpec A("armv7");
+ ArchSpec B("armv7-");
+ ArchSpec C("armv7--");
+ ArchSpec D("armv7---");
+
+ ASSERT_FALSE(A.TripleVendorWasSpecified());
+ ASSERT_FALSE(A.TripleOSWasSpecified());
+ ASSERT_FALSE(A.TripleEnvironmentWasSpecified());
+
+ ASSERT_TRUE(B.TripleVendorWasSpecified());
+ ASSERT_FALSE(B.TripleOSWasSpecified());
+ ASSERT_FALSE(B.TripleEnvironmentWasSpecified());
+
+ ASSERT_TRUE(C.TripleVendorWasSpecified());
+ ASSERT_TRUE(C.TripleOSWasSpecified());
+ ASSERT_FALSE(C.TripleEnvironmentWasSpecified());
+
+ ASSERT_TRUE(D.TripleVendorWasSpecified());
+ ASSERT_TRUE(D.TripleOSWasSpecified());
+ ASSERT_TRUE(D.TripleEnvironmentWasSpecified());
+ }
+ {
+ ArchSpec A("x86_64-unknown");
+ ArchSpec B("powerpc-unknown-linux");
+ ArchSpec C("i386-pc-windows-msvc");
+ ArchSpec D("aarch64-unknown-linux-android");
+
+ ASSERT_TRUE(A.TripleVendorWasSpecified());
+ ASSERT_FALSE(A.TripleOSWasSpecified());
+ ASSERT_FALSE(A.TripleEnvironmentWasSpecified());
+
+ ASSERT_TRUE(B.TripleVendorWasSpecified());
+ ASSERT_TRUE(B.TripleOSWasSpecified());
+ ASSERT_FALSE(B.TripleEnvironmentWasSpecified());
+
+ ASSERT_TRUE(C.TripleVendorWasSpecified());
+ ASSERT_TRUE(C.TripleOSWasSpecified());
+ ASSERT_TRUE(C.TripleEnvironmentWasSpecified());
+
+ ASSERT_TRUE(D.TripleVendorWasSpecified());
+ ASSERT_TRUE(D.TripleOSWasSpecified());
+ ASSERT_TRUE(D.TripleEnvironmentWasSpecified());
+ }
+}
More information about the lldb-commits
mailing list