[AArch64TargetParser]Fix reconstructFromParsedFeatures ignoring negative features (#142236)

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`.
This commit is contained in:
Matthias Braun
2025-06-16 12:55:12 -07:00
committed by GitHub
parent 25781221d6
commit b0378e7ca9
3 changed files with 27 additions and 2 deletions

View File

@@ -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(); }

View File

@@ -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 {};
}

View File

@@ -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 = {"+neon", "-sve", "+sve2"};
ASSERT_THAT(Features, testing::ContainerEq(FeaturesExpected));
}
AArch64ExtensionDependenciesBaseArchTestParams
AArch64ExtensionDependenciesArchData[] = {
// Base architecture features