[llvm] [TableGen] Detect invalid -D arguments and fail. (PR #102813)

Sergei Barannikov via llvm-commits llvm-commits at lists.llvm.org
Sun Aug 11 10:26:14 PDT 2024


================
@@ -42,6 +42,25 @@ struct {
   { tgtok::Endif, "endif" },
   { tgtok::Define, "define" }
 };
+
+// Returns true if `MacroName` is a valid macro name. Valid macro names match
+// the regular expression [a-zA-Z_][0-9a-zA-Z_]* (see prepLexMacroName).
+bool IsValidMacroName(StringRef MacroName) {
+  if (MacroName.size() == 0)
+    return false;
+
+  char First = MacroName[0];
+  if (First != '_' && !isalpha(First))
+    return false;
+
+  // Match the rest of the identifier regex: [0-9a-zA-Z_]*
+  for (char Rest : MacroName.drop_front())
+    if (Rest != '_' && !isalpha(Rest) && !isdigit(Rest))
+      return false;
+
+  return true;
+}
+
 } // end anonymous namespace
----------------
s-barannikov wrote:

https://llvm.org/docs/CodingStandards.html#anonymous-namespaces

> Because of this, we have a simple guideline: make anonymous namespaces as small as possible, and only use them for class declarations.


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


More information about the llvm-commits mailing list