[llvm] 41f81ad - [Tablegen][NFC] Add a check for duplicate features (#94223)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 11 09:51:28 PDT 2024
Author: Tomas Matheson
Date: 2024-06-11T17:51:25+01:00
New Revision: 41f81ad73583bfff7c7dc1caeacbbb783d004e9c
URL: https://github.com/llvm/llvm-project/commit/41f81ad73583bfff7c7dc1caeacbbb783d004e9c
DIFF: https://github.com/llvm/llvm-project/commit/41f81ad73583bfff7c7dc1caeacbbb783d004e9c.diff
LOG: [Tablegen][NFC] Add a check for duplicate features (#94223)
We hit this downstream and the only evidence of the mistake was that the
results of `Find` on `SubtargetFeatureKV` were corrupted.
Added:
Modified:
llvm/utils/TableGen/SubtargetEmitter.cpp
Removed:
################################################################################
diff --git a/llvm/utils/TableGen/SubtargetEmitter.cpp b/llvm/utils/TableGen/SubtargetEmitter.cpp
index 323470940fec5..60a0402103ce0 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,10 @@ unsigned SubtargetEmitter::FeatureKeyValues(
OS << " },\n";
++NumFeatures;
+
+ if (!UniqueKeys.insert(CommandLineName).second)
+ PrintFatalError("Duplicate key in SubtargetFeatureKV: " +
+ CommandLineName);
}
// End feature table
More information about the llvm-commits
mailing list