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

Rahul Joshi via llvm-commits llvm-commits at lists.llvm.org
Sun Aug 11 16:08:15 PDT 2024


================
@@ -54,9 +74,17 @@ TGLexer::TGLexer(SourceMgr &SM, ArrayRef<std::string> Macros) : SrcMgr(SM) {
   PrepIncludeStack.push_back(
       std::make_unique<std::vector<PreprocessorControlDesc>>());
 
-  // Put all macros defined in the command line into the DefinedMacros set.
-  for (const std::string &MacroName : Macros)
+  // Add all macros defined on the command line to the DefinedMacros set.
+  // Check invalid macro names and print fatal error if we find one.
+  for (const std::string &MacroName : Macros) {
+    const char *Begin = MacroName.c_str();
+    const char *End = lexMacroName(Begin);
----------------
jurahul wrote:

It's not exactly assuming its null terminated, just that we wil hit the end of macro name condition before we run out of characters in the supplied str. For the command line, I suspect the strings are null terminated, but the use in `prepLexMacroName` is likely not, or atleast not obviously looking at the code. So not sure what assert to add here exactly.

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


More information about the llvm-commits mailing list