https://github.com/ChipsSpectre updated https://github.com/llvm/llvm-project/pull/74926
>From 9b703f6fcdb67eb921b3b5cf67b92bbd24144cf9 Mon Sep 17 00:00:00 2001 From: ChipsSpectre <maximilian.horn...@tum.de> Date: Tue, 19 Dec 2023 05:14:06 +0100 Subject: [PATCH] [clang][Parse] `TryAnnotateCXXScopeToken` to be called only when parsing C++ Assume `TryAnnotateCXXScopeToken` to be parsing C++ code in all of its paths. Fixes: https://github.com/llvm/llvm-project/issues/73559. --- clang/docs/ReleaseNotes.rst | 2 ++ clang/lib/Parse/ParseDecl.cpp | 3 ++- clang/lib/Parse/ParseDeclCXX.cpp | 2 ++ clang/test/Parser/cxx-in-c.c | 3 +++ 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 783dc7333af7e2..ce2f56df1d3f3a 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -688,6 +688,8 @@ Bug Fixes in This Version (`#62157 <https://github.com/llvm/llvm-project/issues/62157>`_) and (`#64885 <https://github.com/llvm/llvm-project/issues/64885>`_) and (`#65568 <https://github.com/llvm/llvm-project/issues/65568>`_) +- Fix crash when using C++ only tokens like ``::`` in C compiler clang. + Fixes (`#73559 https://github.com/llvm/llvm-project/issues/73559`_) Bug Fixes to Compiler Builtins ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index ece3698967e2f6..5d1c19ae07cb54 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -3483,7 +3483,8 @@ void Parser::ParseDeclarationSpecifiers( case tok::coloncolon: // ::foo::bar // C++ scope specifier. Annotate and loop, or bail out on error. - if (TryAnnotateCXXScopeToken(EnteringContext)) { + if (getLangOpts().CPlusPlus && + TryAnnotateCXXScopeToken(EnteringContext)) { if (!DS.hasTypeSpecifier()) DS.SetTypeSpecError(); goto DoneWithDeclSpec; diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp index 910112ecae964c..1cf16a752cfcdc 100644 --- a/clang/lib/Parse/ParseDeclCXX.cpp +++ b/clang/lib/Parse/ParseDeclCXX.cpp @@ -2679,6 +2679,8 @@ Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS, ParsedAttributes &AccessAttrs, const ParsedTemplateInfo &TemplateInfo, ParsingDeclRAIIObject *TemplateDiags) { + assert(getLangOpts().CPlusPlus && + "Call sites of this function should be guarded by checking for C++"); if (Tok.is(tok::at)) { if (getLangOpts().ObjC && NextToken().isObjCAtKeyword(tok::objc_defs)) Diag(Tok, diag::err_at_defs_cxx); diff --git a/clang/test/Parser/cxx-in-c.c b/clang/test/Parser/cxx-in-c.c index f5fa39bd0cb99b..034a44cdf12bfa 100644 --- a/clang/test/Parser/cxx-in-c.c +++ b/clang/test/Parser/cxx-in-c.c @@ -3,3 +3,6 @@ // PR9137 void f0(int x) : {}; // expected-error{{expected function body after function declarator}} void f1(int x) try {}; // expected-error{{expected function body after function declarator}} + +// GH73559 +::; // expected-error{{expected identifier or '('}} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits