llvm-project
5702fda2 - [Clang] Fix double revert of a keyword token that was cached before the first fallback (#219799)

Commit
6 hours ago
[Clang] Fix double revert of a keyword token that was cached before the first fallback (#219799) Fixes #214128 When an undeclared name is followed by `<`, the parser tentatively looks for a template-argument list and, on invalid input, can skip all the way to the end of the file. Every token after that point is lexed and cached while the type-trait keywords still have their keyword kind. The first `struct __make_unsigned` then reverts the keyword to an identifier, but the second `struct __make_unsigned` is replayed from the cache with the stale keyword kind, so `TryKeywordIdentFallback` tries to revert the same `IdentifierInfo` again and trips the assertion in `revertTokenIDToIdentifier`. The same thing can happen with any keyword this hack covers (`__is_pod`, `__is_signed`, the transform traits) and with any cached token, since a `Token` is just a snapshot of the classification at lex time. `TryKeywordIdentFallback` now asks the `IdentifierInfo`, which is the source of truth, before doing anything: if the keyword has already been made an identifier for the remainder of the translation unit, the token kind is simply fixed up and no diagnostic or revert happens a second time. First encounters behave exactly as before. LLM tools were used for this contribution. I've reviewed, built, and tested the change myself before pushing to GitHub.
Parents
Loading