[clang-format] Prevent re-assigning type on finalized tokens (#210763)

Prevents a finalized token inside modifyContext from being reassigned
through the setType member function by checking if the token is
finalized.

This ensures ill-defined code like does not trigger an assertion failure
during reformatting.
Fixes #210509
This commit is contained in:
johnnyb2543 2026-07-30 17:28:08 -04:00 committed by GitHub
parent f279abcc81
commit 2d0b45bc0a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 3 additions and 1 deletions

View file

@ -2308,7 +2308,8 @@ private:
}
if (Previous->opensScope())
break;
if (Previous->isOneOf(TT_BinaryOperator, TT_UnaryOperator) &&
if (!Previous->isTypeFinalized() &&
Previous->isOneOf(TT_BinaryOperator, TT_UnaryOperator) &&
Previous->isPointerOrReference() && Previous->Previous &&
Previous->Previous->isNot(tok::equal)) {
Previous->setType(TT_PointerOrReference);

View file

@ -22562,6 +22562,7 @@ TEST_F(FormatTest, DoNotCrashOnInvalidInput) {
verifyNoCrash("[[ [a] ]]");
verifyNoCrash(
"#xxxx??x<xxxxxxx||??x<xxxxxxx and xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
verifyNoCrash("a &alias & =");
}
TEST_F(FormatTest, FormatsTableGenCode) {