[llvm] [llvm][Tablegen][llvm-tblgen] Added keyword #undef to llvm-tblgen and fixed a small b… (PR #69135)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 16 02:31:47 PDT 2023
================
@@ -664,7 +660,7 @@ tgtok::TokKind TGLexer::prepIsDirective() const {
// It looks like TableGen does not support '\r' as the actual
// carriage return, e.g. getNextChar() treats a single '\r'
// as '\n'. So we do the same here.
- NextChar == '\r')
+ NextChar == '\r' || NextChar == '\0')
----------------
whousemyname wrote:
you are right. It is to solve small bugs in llvm-tblgen.
### Reason for doing this
When I was implementing undef, I found that if the td file ended with #endif, a compilation error would occur.
Take the following program as an example. For TGlexer, if it finds that this macro instruction is ifdef/ifndef and the macro is not defined, it will execute TGLexer::prepSkipRegion. This function will skip some characters until it encounters # , execute TGLexer::prepIsDirective to determine the type of macro, but if #endif happens to be the end of the file, the match will fail, so NextChar == '\0' is added for this.
```
#ifdef MACRO
#endif
```
https://github.com/llvm/llvm-project/pull/69135
More information about the llvm-commits
mailing list