Avoid triple corruption while merging core info

Summary:
This patch fixes a bug where when target triple created from elf information
is arm-*-linux-eabihf and platform triple is armv8l-*-linux-gnueabihf. Merging
both triple results in armv8l--unknown-unknown.

This happens because we order a triple update while calling CoreUpdated and
CoreUpdated creates a new triple with no vendor or environment information.

Making sure we do not update triple and just update to more specific core
fixes the issue.

Reviewers: labath, jasonmolenda, clayborg

Reviewed By: jasonmolenda

Subscribers: jankratochvil, kristof.beyls, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D70155
This commit is contained in:
Muhammad Omair Javaid 2019-12-05 13:04:04 +05:00
parent e00e5d3347
commit 8b8185bb1b
2 changed files with 36 additions and 1 deletions

View File

@ -868,7 +868,7 @@ void ArchSpec::MergeFrom(const ArchSpec &other) {
IsCompatibleMatch(other) && GetCore() == ArchSpec::eCore_arm_generic &&
other.GetCore() != ArchSpec::eCore_arm_generic) {
m_core = other.GetCore();
CoreUpdated(true);
CoreUpdated(false);
}
if (GetFlags() == 0) {
SetFlags(other.GetFlags());

View File

@ -216,6 +216,41 @@ TEST(ArchSpecTest, MergeFrom) {
EXPECT_EQ(llvm::Triple::EnvironmentType::UnknownEnvironment,
A.GetTriple().getEnvironment());
}
{
ArchSpec A("arm--linux-eabihf");
ArchSpec B("armv8l--linux-gnueabihf");
EXPECT_TRUE(A.IsValid());
EXPECT_TRUE(B.IsValid());
EXPECT_EQ(llvm::Triple::ArchType::arm, A.GetTriple().getArch());
EXPECT_EQ(llvm::Triple::ArchType::arm, B.GetTriple().getArch());
EXPECT_EQ(ArchSpec::eCore_arm_generic, A.GetCore());
EXPECT_EQ(ArchSpec::eCore_arm_armv8l, B.GetCore());
EXPECT_EQ(llvm::Triple::VendorType::UnknownVendor,
A.GetTriple().getVendor());
EXPECT_EQ(llvm::Triple::VendorType::UnknownVendor,
B.GetTriple().getVendor());
EXPECT_EQ(llvm::Triple::OSType::Linux, A.GetTriple().getOS());
EXPECT_EQ(llvm::Triple::OSType::Linux, B.GetTriple().getOS());
EXPECT_EQ(llvm::Triple::EnvironmentType::EABIHF,
A.GetTriple().getEnvironment());
EXPECT_EQ(llvm::Triple::EnvironmentType::GNUEABIHF,
B.GetTriple().getEnvironment());
A.MergeFrom(B);
EXPECT_EQ(llvm::Triple::ArchType::arm, A.GetTriple().getArch());
EXPECT_EQ(ArchSpec::eCore_arm_armv8l, A.GetCore());
EXPECT_EQ(llvm::Triple::VendorType::UnknownVendor,
A.GetTriple().getVendor());
EXPECT_EQ(llvm::Triple::OSType::Linux, A.GetTriple().getOS());
EXPECT_EQ(llvm::Triple::EnvironmentType::EABIHF,
A.GetTriple().getEnvironment());
}
}
TEST(ArchSpecTest, MergeFromMachOUnknown) {