<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/125177>125177</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            clang allows invalid unicode escapes in identifiers (only after first character)
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          mrolle45
      </td>
    </tr>
</table>

<pre>
    The clang lexer, after seeing an ASCII identifier starting character, uses `LexIdentifierContinue()` to get the rest of the token.  If it sees a \uxxxx or \Uxxxxxxxx escape, it consumes this as the next character in the identifier.
However, **it does not check if this is a valid unicode continuation character.**

To demonstrate this, I wrote some lines which try to #define the identifier as a macro, and then see if this succeeds by invoking the macro.  I used a number of invalid unicode characters, including surrogate codepoints and codepoints above the maximum allowed value.  I included one valid unicode character, \u03b4.  I also tested the unicode characters without the leading ascii characters, and clang correctly does not recognize the invalid ones as identifiers

Here is the demo program and the result of invoking `clang -E`.

```c
#define X\u00B0() X\u00B0 is an identifier.
X\u00B0()
#define X\u03B4() X\u03B4 is an identifier.
X\u03B4()
#define X\uD800() X\uD800 is an identifier.
X\u00B0()
#define X\U10000000() X\U10000000 is an identifier.
X\U10000000()
#define \u00B0() \u00B0 is an identifier.
\u00B0()
#define \u03B4() \u03B4 is an identifier.
\u03B4()
#define \uD800() \uD800 is an identifier.
\u00B0()
#define \U10000000() \U10000000 is an identifier.
\U10000000()

X° is an identifier.     -- wrong

Xδ is an identifier.

X° is an identifier.     -- wrong

X is an identifier.     -- wrong

\u00B0()

δ is an identifier.

\u00B0()

\U10000000()


```

</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJycVUuP4jgQ_jXmUmrkOITHIQe6Z9Ag7W1npL06TpF4x7GR7fDYX78qhwE6TbMPC4nYqfrqq68qZRmCbixiyYpXVnyZyD62zpedd8bgrJhUrj6X31sEZaRtwOA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