llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Matthias Braun (MatzeB) <details> <summary>Changes</summary> The `targetFeatureToExtension` function used by reconstructFromParsedFeatures only found positive `+FEATURE` strings, but not negative `-FEATURE` strings. Extend the function to handle both to fix `reconstructFromParsedFeatures`. --- Full diff: https://github.com/llvm/llvm-project/pull/142236.diff 3 Files Affected: - (added) clang/test/CodeGen/aarch64-always-inline-feature-bug.c (+8) - (modified) llvm/lib/TargetParser/AArch64TargetParser.cpp (+3-2) - (modified) llvm/unittests/TargetParser/TargetParserTest.cpp (+16) ``````````diff diff --git a/clang/test/CodeGen/aarch64-always-inline-feature-bug.c b/clang/test/CodeGen/aarch64-always-inline-feature-bug.c new file mode 100644 index 0000000000000..27c3983c66d2b --- /dev/null +++ b/clang/test/CodeGen/aarch64-always-inline-feature-bug.c @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 -triple aarch64-- -target-feature +neon -target-feature +sve\ +// RUN: -target-feature -sve -emit-llvm %s -o - | FileCheck %s + +// Reproducer for bug where clang would reject always_inline for unrelated +// target features if they were disable with `-feature` on the command line. +// CHECK: @bar +__attribute__((always_inline)) __attribute__((target("neon"))) void foo() {} +void bar() { foo(); } diff --git a/llvm/lib/TargetParser/AArch64TargetParser.cpp b/llvm/lib/TargetParser/AArch64TargetParser.cpp index e13c6e6d28c2b..4a2523440f0f0 100644 --- a/llvm/lib/TargetParser/AArch64TargetParser.cpp +++ b/llvm/lib/TargetParser/AArch64TargetParser.cpp @@ -60,7 +60,7 @@ uint64_t AArch64::getFMVPriority(ArrayRef<StringRef> Features) { ExtensionSet FeatureBits; for (const StringRef Feature : Features) { std::optional<FMVInfo> FMV = parseFMVExtension(Feature); - if (!FMV) { + if (!FMV && Feature.starts_with('+')) { if (std::optional<ExtensionInfo> Info = targetFeatureToExtension(Feature)) FMV = lookupFMVByID(Info->ID); } @@ -181,7 +181,8 @@ std::optional<AArch64::FMVInfo> AArch64::parseFMVExtension(StringRef FMVExt) { std::optional<AArch64::ExtensionInfo> AArch64::targetFeatureToExtension(StringRef TargetFeature) { for (const auto &E : Extensions) - if (TargetFeature == E.PosTargetFeature) + if (TargetFeature == E.PosTargetFeature || + TargetFeature == E.NegTargetFeature) return E; return {}; } diff --git a/llvm/unittests/TargetParser/TargetParserTest.cpp b/llvm/unittests/TargetParser/TargetParserTest.cpp index f4c93334ac682..468ef57cb5b9b 100644 --- a/llvm/unittests/TargetParser/TargetParserTest.cpp +++ b/llvm/unittests/TargetParser/TargetParserTest.cpp @@ -1831,6 +1831,22 @@ TEST_P(AArch64ExtensionDependenciesBaseCPUTestFixture, } } +TEST(TargetParserTest, testAArch64ReconstructFromParsedFeatures) { + AArch64::ExtensionSet Extensions; + std::vector<std::string> FeatureOptions = { + "-sve2", "-Baz", "+sve", "+FooBar", "+sve2", "+neon", "-sve", + }; + std::vector<std::string> NonExtensions; + Extensions.reconstructFromParsedFeatures(FeatureOptions, NonExtensions); + + std::vector<std::string> NonExtensionsExpected = {"-Baz", "+FooBar"}; + ASSERT_THAT(NonExtensions, testing::ContainerEq(NonExtensionsExpected)); + std::vector<StringRef> Features; + Extensions.toLLVMFeatureList(Features); + std::vector<StringRef> FeaturesExpected = {"+sve2", "+neon", "-sve"}; + ASSERT_THAT(FeaturesExpected, testing::ContainerEq(FeaturesExpected)); +} + AArch64ExtensionDependenciesBaseArchTestParams AArch64ExtensionDependenciesArchData[] = { // Base architecture features `````````` </details> https://github.com/llvm/llvm-project/pull/142236 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits