[clang] [clang-format] Support of TableGen identifiers beginning with a number. (PR #78571)

Hirofumi Nakamura via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 18 05:14:42 PST 2024


hnakamura5 wrote:

I checked simply the corner cases in unittest of this patch with the following sample.

```
// test_id.td
class 01234Vector<int i> {
  int 2dVector = 0x1abc;
  int invalid_num = 0x1234x;
  int 0x1234x = i;
}

def Def: 01234Vector<1>;
```

The followings are the result of 
```
llvm-tblgen .\test_id.td
```

(1) With the whole sample code above.
```
.\test_id.td:4:27: error: expected ';' after declaration
  int invalid_num = 0x1234x;
                           ^ ← This caret points to the last x.
```
We can see `0x1234x` is not lexed as a valid token.

(2) When the line of invalid_num is commented out from the sample.
```
.\test_id.td:5:7: error: Expected identifier in declaration
  int 0x1234x = i;
      ^ ← This caret points to the first 0.
```
`0x1234x` is NOT an identifier.

(3) Additionally, the line of  int 0x1234x = i is commented out.
```
.\test_id.td:2:23: warning: unused template argument: 01234Vector:i
class 01234Vector<int i> {
                      ^
------------- Classes -----------------
class 01234Vector<int 01234Vector:i = ?> {
  int 2dVector = 6844;
}
------------- Defs -----------------
def Def {       // 01234Vector
  int 2dVector = 6844;
}
```
This is the result after the process completes. 

So the following remained code has valid syntax.
```
class 01234Vector<int i> {
  int 2dVector = 0x1abc;
}

def Def: 01234Vector<1>;
```


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


More information about the cfe-commits mailing list