https://github.com/ChipsSpectre created https://github.com/llvm/llvm-project/pull/74926
As stated in this issue, https://github.com/llvm/llvm-project/issues/73559, clang (C version of clang, not C++) crashes when C++ components are parsed. Even a file which only contains a double-colon "::" leads to this kind of crash. The reason for this behavior is that TryAnnotateCXXScopeToken() of the clang parser assumes to be executed in C++ mode only. But in 2 places in the code, there was no guard to ensure this function is only called in C++ mode. When it is called nonetheless, the aforementioned error is created. >From 8269060e6b50721a847742ff8d0af2c819e52578 Mon Sep 17 00:00:00 2001 From: ChipsSpectre <maximilian.horn...@tum.de> Date: Sat, 9 Dec 2023 12:07:02 +0100 Subject: [PATCH] fix issue 73559. --- clang/lib/Parse/ParseDecl.cpp | 3 ++- clang/lib/Parse/ParseDeclCXX.cpp | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index ece3698967e2f..5d1c19ae07cb5 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 910112ecae964..eba7ea65beee9 100644 --- a/clang/lib/Parse/ParseDeclCXX.cpp +++ b/clang/lib/Parse/ParseDeclCXX.cpp @@ -2702,7 +2702,7 @@ Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS, bool MalformedTypeSpec = false; if (!TemplateInfo.Kind && Tok.isOneOf(tok::identifier, tok::coloncolon, tok::kw___super)) { - if (TryAnnotateCXXScopeToken()) + if (getLangOpts().CPlusPlus && TryAnnotateCXXScopeToken()) MalformedTypeSpec = true; bool isAccessDecl; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits