[llvm] [Tablegen][NFC] Add a check for duplicate features (PR #94223)

Tomas Matheson via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 3 06:59:08 PDT 2024


https://github.com/tmatheson-arm created https://github.com/llvm/llvm-project/pull/94223

We hit this downstream and the only evidence of the mistake was that the results of `Find` on `SubtargetFeatureKV` were corrupted.

>From ddaf86776b79e7ecace5c61c2357c7e526c70967 Mon Sep 17 00:00:00 2001
From: Tomas Matheson <tomas.matheson at arm.com>
Date: Mon, 3 Jun 2024 14:37:04 +0100
Subject: [PATCH] [Tablegen][NFC] Add a check for duplicate features

We hit this downstream and the only evidence of the mistake was that
the results of Find on SubtargetFeatureKV were corrupted.
---
 llvm/utils/TableGen/SubtargetEmitter.cpp | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/llvm/utils/TableGen/SubtargetEmitter.cpp b/llvm/utils/TableGen/SubtargetEmitter.cpp
index 323470940fec5..1b8893caa3f7d 100644
--- a/llvm/utils/TableGen/SubtargetEmitter.cpp
+++ b/llvm/utils/TableGen/SubtargetEmitter.cpp
@@ -32,6 +32,7 @@
 #include <cstdint>
 #include <iterator>
 #include <map>
+#include <set>
 #include <string>
 #include <vector>
 
@@ -255,6 +256,9 @@ unsigned SubtargetEmitter::FeatureKeyValues(
 
   llvm::sort(FeatureList, LessRecordFieldName());
 
+  // Check that there are no duplicate keys
+  std::set<StringRef> UniqueKeys;
+
   // Begin feature table
   OS << "// Sorted (by key) array of values for CPU features.\n"
      << "extern const llvm::SubtargetFeatureKV " << Target
@@ -283,6 +287,9 @@ unsigned SubtargetEmitter::FeatureKeyValues(
 
     OS << " },\n";
     ++NumFeatures;
+
+    if (!UniqueKeys.insert(CommandLineName).second)
+      PrintFatalError("Duplicate key in SubtargetFeatureKV: " +)
   }
 
   // End feature table



More information about the llvm-commits mailing list