[llvm] Reland [AArch64][AsmParser] Directives should clear transitively implied features (#106625) (PR #106850)

Sander de Smalen via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 2 07:31:58 PDT 2024


================
@@ -7075,30 +7075,22 @@ bool AArch64AsmParser::parseDirectiveCPU(SMLoc L) {
 
     bool EnableFeature = !Name.consume_front_insensitive("no");
 
-    bool FoundExtension = false;
-    for (const auto &Extension : ExtensionMap) {
-      if (Extension.Name != Name)
-        continue;
+    auto It = llvm::find_if(ExtensionMap, [&Name](const auto &Extension) {
+      return Extension.Name == Name;
+    });
 
-      if (Extension.Features.none())
-        report_fatal_error("unsupported architectural extension: " + Name);
-
-      FeatureBitset Features = STI.getFeatureBits();
-      FeatureBitset ToggleFeatures =
-          EnableFeature
-              ? STI.SetFeatureBitsTransitively(~Features & Extension.Features)
-              : STI.ToggleFeature(Features & Extension.Features);
-      setAvailableFeatures(ComputeAvailableFeatures(ToggleFeatures));
-      FoundExtension = true;
-
-      break;
+    if (It != std::end(ExtensionMap)) {
+      if (EnableFeature)
+        STI.SetFeatureBitsTransitively(It->Features);
+      else
+        STI.ClearFeatureBitsTransitively(It->Features);
+    } else {
+      Error(CurLoc, "unsupported architectural extension: " + Name);
----------------
sdesmalen-arm wrote:

I would prefer returning directly because it's structurally simpler and helps avoid any future issues with the code that follows after the `Error`. For example, the function returns `false` (no error), where it should have returned `true`. This isn't much of a problem at the moment, because nothing checks the return value of this function, but if it would this would not be correct.

https://github.com/llvm/llvm-project/pull/106850


More information about the llvm-commits mailing list