Author: Corentin Jabot Date: 2025-07-15T18:09:51+02:00 New Revision: 55f1b91d50a0f3706ad62d497d3c8a5ec572d59e
URL: https://github.com/llvm/llvm-project/commit/55f1b91d50a0f3706ad62d497d3c8a5ec572d59e DIFF: https://github.com/llvm/llvm-project/commit/55f1b91d50a0f3706ad62d497d3c8a5ec572d59e.diff LOG: [Clang] Fix a crash when parsing an invalid `decltype` (#148798) We would try to exact an annotated token before checking if it was valid, leading to a crash when `decltype` was the only token that was parsed (which can happen in the absense of opening paren) Fixes #114815 Added: clang/test/Parser/gh114815.cpp Modified: clang/lib/Parse/ParseDeclCXX.cpp Removed: ################################################################################ diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp index 9fe18b0dbcedb..9cae4f9a23ef0 100644 --- a/clang/lib/Parse/ParseDeclCXX.cpp +++ b/clang/lib/Parse/ParseDeclCXX.cpp @@ -1133,13 +1133,6 @@ void Parser::AnnotateExistingDecltypeSpecifier(const DeclSpec &DS, // make sure we have a token we can turn into an annotation token if (PP.isBacktrackEnabled()) { PP.RevertCachedTokens(1); - if (DS.getTypeSpecType() == TST_error) { - // We encountered an error in parsing 'decltype(...)' so lets annotate all - // the tokens in the backtracking cache - that we likely had to skip over - // to get to a token that allows us to resume parsing, such as a - // semi-colon. - EndLoc = PP.getLastCachedTokenLocation(); - } } else PP.EnterToken(Tok, /*IsReinject*/ true); diff --git a/clang/test/Parser/gh114815.cpp b/clang/test/Parser/gh114815.cpp new file mode 100644 index 0000000000000..6a89384e9e66d --- /dev/null +++ b/clang/test/Parser/gh114815.cpp @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -verify %s -std=c++11 -fsyntax-only + +#define ID(X) X +extern int ID(decltype); +// expected-error@-1 {{expected '(' after 'decltype'}} \ +// expected-error@-1 {{expected unqualified-id}} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits