FileCheck string substitution block parsing code only report an invalid
variable name in a string variable use if it starts with a forbidden
character. It does not report anything if there are unparsed characters
after the variable name, i.e. [[X-Y]] is parsed as [[X]] and no error is
returned. This commit fixes that.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
llvm/lib/FileCheck/FileCheck.cpp | ||
---|---|---|
460 | I wonder if it would make more sense to add the check to this function, somewhere around here. This is the "parseVariable" function after all, so seems like the logical place to reject invalid variable names, rather than the place it is currently detected. What do you think? | |
llvm/test/FileCheck/simple-var-capture.txt | ||
22 | I would suggest you also want an invalid variable name which is a definition (e.g. [[X-Y:.+]]) or something like that. | |
llvm/unittests/FileCheck/FileCheckTest.cpp | ||
1347 | Ditto - consider also checking for a definition with an invalid name. |
llvm/lib/FileCheck/FileCheck.cpp | ||
---|---|---|
460 | A trailer has to be allowed when parsing a variable use because it could be [[@LINE+1]]. If the variable is a pseudo variable, parsing is deferred to the numeric substitution block parsing. Otherwise any trailer is an error. Perhaps it's time to remove all uses of [[@LINE]] in favor of [[#@LINE]] | |
llvm/test/FileCheck/simple-var-capture.txt | ||
22 | The new code is only executed for string variable use. String variable definition and pseudo variable use different codepath. | |
llvm/unittests/FileCheck/FileCheckTest.cpp | ||
1347 | See line 1339 for a test for that already. |
llvm/lib/FileCheck/FileCheck.cpp | ||
---|---|---|
460 | This function already knows whether it is a pseudo variable, so doesn't that mean you can do something like if(!IsPseudo) /*error if trailer*/? |
llvm/lib/FileCheck/FileCheck.cpp | ||
---|---|---|
460 | parseVariable is also called for numeric expression where it's fine to have a trailer after a variable ([[#FOO+2]]). I would need to distinguish 3 states:
That's why I suggested removing legacy @LINE expression, it would reduce this to 2 options which can be dealt with a AllowTrailer (false by default) parameter. |
LGTM! I don't think there's a pressing need to get rid of the legacy pseudo variables, but I'm also not opposed to it, if you think it's worth doing.
llvm/lib/FileCheck/FileCheck.cpp | ||
---|---|---|
460 | Ah, thanks. Didn't realise this was used elsewhere. |
Sorry it seems I forgot to run the whole testsuite when I put this up for review. The patch found 3 issues:
https://reviews.llvm.org/D98852
https://reviews.llvm.org/D98853
https://reviews.llvm.org/D98854
I wonder if it would make more sense to add the check to this function, somewhere around here. This is the "parseVariable" function after all, so seems like the logical place to reject invalid variable names, rather than the place it is currently detected. What do you think?