[llvm] [llvm][MC] Fix missing SubArch information when calling lookupTarget (PR #69902)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 23 09:41:51 PDT 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mc
Author: None (huaatian)
<details>
<summary>Changes</summary>
When calling the function 'lookupTarget', in some cases, the SubArch information of the parameter TheTriple gets lost. This modification ensures the integrity of the parameter TheTriple.
---
Full diff: https://github.com/llvm/llvm-project/pull/69902.diff
2 Files Affected:
- (modified) llvm/lib/MC/TargetRegistry.cpp (+2-1)
- (modified) llvm/unittests/MC/TargetRegistry.cpp (+18)
``````````diff
diff --git a/llvm/lib/MC/TargetRegistry.cpp b/llvm/lib/MC/TargetRegistry.cpp
index fa7aaccabcd6109..bfce3f9d4e5b363 100644
--- a/llvm/lib/MC/TargetRegistry.cpp
+++ b/llvm/lib/MC/TargetRegistry.cpp
@@ -43,7 +43,8 @@ const Target *TargetRegistry::lookupTarget(StringRef ArchName,
// given triple.
Triple::ArchType Type = Triple::getArchTypeForLLVMName(ArchName);
if (Type != Triple::UnknownArch)
- TheTriple.setArch(Type);
+ // Set the type of Arch while preserving SubArch, if any.
+ TheTriple.setArch(Type, TheTriple.getSubArch());
} else {
// Get the target specific parser.
std::string TempError;
diff --git a/llvm/unittests/MC/TargetRegistry.cpp b/llvm/unittests/MC/TargetRegistry.cpp
index cc464b7681ce17e..924a55add874697 100644
--- a/llvm/unittests/MC/TargetRegistry.cpp
+++ b/llvm/unittests/MC/TargetRegistry.cpp
@@ -42,4 +42,22 @@ TEST(TargetRegistry, TargetHasArchType) {
ASSERT_NE(Count, 0);
}
+TEST(TargetRegistry, PreserveSubArchInfo) {
+ auto T = Triple("mipsisa64r6el-unknown-linux-gnuabi64");
+ EXPECT_EQ(Triple::mips64el, T.getArch());
+ EXPECT_EQ(Triple::MipsSubArch_r6, T.getSubArch());
+ EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
+ EXPECT_EQ(Triple::Linux, T.getOS());
+ EXPECT_EQ(Triple::GNUABI64, T.getEnvironment());
+ std::string Error;
+ if (!TargetRegistry::lookupTarget("mips64el", T, Error))
+ GTEST_SKIP();
+ EXPECT_EQ(Triple::mips64el, T.getArch());
+ // The SubArch information needs to be preserved.
+ EXPECT_EQ(Triple::MipsSubArch_r6, T.getSubArch());
+ EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
+ EXPECT_EQ(Triple::Linux, T.getOS());
+ EXPECT_EQ(Triple::GNUABI64, T.getEnvironment());
+}
+
} // end namespace
``````````
</details>
https://github.com/llvm/llvm-project/pull/69902
More information about the llvm-commits
mailing list