diff --git a/lib/Support/ARMTargetParser.cpp b/lib/Support/ARMTargetParser.cpp index 360e64a5a5f..3c3c2103a5c 100644 --- a/lib/Support/ARMTargetParser.cpp +++ b/lib/Support/ARMTargetParser.cpp @@ -498,10 +498,13 @@ bool ARM::appendArchExtFeatures( return false; for (const auto AE : ARCHExtNames) { - if (Negated && (AE.ID & ID) == ID && AE.NegFeature) - Features.push_back(AE.NegFeature); - else if (AE.ID == ID && AE.Feature) - Features.push_back(AE.Feature); + if (Negated) { + if ((AE.ID & ID) == ID && AE.NegFeature) + Features.push_back(AE.NegFeature); + } else { + if ((AE.ID & ID) == AE.ID && AE.Feature) + Features.push_back(AE.Feature); + } } if (CPU == "") diff --git a/unittests/Support/TargetParserTest.cpp b/unittests/Support/TargetParserTest.cpp index dbdaedd3892..9349f767014 100644 --- a/unittests/Support/TargetParserTest.cpp +++ b/unittests/Support/TargetParserTest.cpp @@ -637,6 +637,27 @@ TEST(TargetParserTest, ARMArchExtFeature) { } } +static bool +testArchExtDependency(const char *ArchExt, + const std::initializer_list &Expected) { + std::vector Features; + + if (!ARM::appendArchExtFeatures("", ARM::ArchKind::ARMV8_1MMainline, ArchExt, + Features)) + return false; + + return llvm::all_of(Expected, [&](StringRef Ext) { + return llvm::is_contained(Features, Ext); + }); +} + +TEST(TargetParserTest, ARMArchExtDependencies) { + EXPECT_TRUE(testArchExtDependency("mve", {"+mve", "+dsp"})); + EXPECT_TRUE(testArchExtDependency("mve.fp", {"+mve.fp", "+mve", "+dsp"})); + EXPECT_TRUE(testArchExtDependency("nodsp", {"-dsp", "-mve", "-mve.fp"})); + EXPECT_TRUE(testArchExtDependency("nomve", {"-mve", "-mve.fp"})); +} + TEST(TargetParserTest, ARMparseHWDiv) { const char *hwdiv[] = {"thumb", "arm", "arm,thumb", "thumb,arm"};