https://github.com/hongtaihu updated https://github.com/llvm/llvm-project/pull/209554
>From f12ccf82cb4193900a58639ac5e796c447095aaf Mon Sep 17 00:00:00 2001 From: hongtaihu <[email protected]> Date: Wed, 15 Jul 2026 00:48:22 +0800 Subject: [PATCH] [clang] Fix infinite loop when parsing `::` in C mode (#208044) In `isTypeSpecifierQualifier`, the `case tok::coloncolon` tries to annotate `::` as a C++ scope token via `TryAnnotateTypeOrScopeToken`. In C mode, `ParseOptionalCXXScopeSpecifier` is gated on `CPlusPlus`, so the annotation does nothing and the token remains `::`. The code then recursively calls `isTypeSpecifierQualifier(getCurToken())`, hitting the same `::` token again in an infinite loop. Fix by returning `false` when the current token is still `::` after the failed annotation attempt, cleanly answering "this is not a type specifier qualifier" and breaking the cycle. Fixes https://github.com/llvm/llvm-project/issues/208044 --- clang/lib/Parse/ParseDecl.cpp | 2 ++ clang/test/Parser/coloncolon-c-mode.c | 4 ++++ 2 files changed, 6 insertions(+) create mode 100644 clang/test/Parser/coloncolon-c-mode.c diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index 88f07bb104fcb..335dd4087b687 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -5692,6 +5692,8 @@ bool Parser::isTypeSpecifierQualifier(const Token &Tok) { if (TryAnnotateTypeOrScopeToken()) return true; + if (getCurToken().is(tok::coloncolon)) + return false; return isTypeSpecifierQualifier(getCurToken()); // GNU attributes support. diff --git a/clang/test/Parser/coloncolon-c-mode.c b/clang/test/Parser/coloncolon-c-mode.c new file mode 100644 index 0000000000000..832655825530a --- /dev/null +++ b/clang/test/Parser/coloncolon-c-mode.c @@ -0,0 +1,4 @@ +// Regression test for GH-208044: clang should not hang when parsing +// `::` in C mode. +// RUN: %clang_cc1 -x c -std=c23 -fsyntax-only %s +int sink = (::i); _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
