[llvm] [TableGen] Detect invalid -D arguments and fail. (PR #102813)
Rahul Joshi via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 12 09:26:10 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:
I don't think that is true. For example, the std::string that is passed into the Macro is constructed using StringRef::str() in CommandLine.h here:
```
// Return true on error.
bool parse(Option &, StringRef, StringRef Arg, std::string &Value) {
Value = Arg.str();
return false;
}
```
so I don't think we can assume its null terminated. Which means that the common function I added will need to accept a StringRef, and the call from prepLexMacroName() has to pass in the appropriate length (of the string if it knows, or std::string::npos to retain the current behavior. Let me make that change, so that code functionally identical to the existing one.
https://github.com/llvm/llvm-project/pull/102813
More information about the llvm-commits
mailing list