[libc-commits] [compiler-rt] [llvm] [lld] [clang] [flang] [libc] [openmp] [clang-tools-extra] [libcxx] [lldb] [mlir] fix issue 73559. (PR #74926)
via libc-commits
libc-commits at lists.llvm.org
Mon Dec 11 13:36:48 PST 2023
https://github.com/ChipsSpectre updated https://github.com/llvm/llvm-project/pull/74926
>From 8269060e6b50721a847742ff8d0af2c819e52578 Mon Sep 17 00:00:00 2001
From: ChipsSpectre <maximilian.hornung at tum.de>
Date: Sat, 9 Dec 2023 12:07:02 +0100
Subject: [PATCH 1/3] 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 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..eba7ea65beee94 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;
>From e8419c3750f7b1cf877b042942204abaab48344b Mon Sep 17 00:00:00 2001
From: ChipsSpectre <maximilian.hornung at tum.de>
Date: Mon, 11 Dec 2023 22:31:10 +0100
Subject: [PATCH 2/3] address review comments.
---
clang/docs/ReleaseNotes.rst | 2 ++
clang/lib/Parse/ParseDeclCXX.cpp | 6 ++++--
clang/test/Parser/cxx-in-c.c | 1 +
3 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 6e4009deaf8746..39dd8c68dbbcb1 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -641,6 +641,8 @@ Bug Fixes in This Version
Fixes (`#67317 <https://github.com/llvm/llvm-project/issues/67317>`_)
- Clang now properly diagnoses use of stand-alone OpenMP directives after a
label (including ``case`` or ``default`` labels).
+- Fix crash when using C++ only tokens like *::* in C compiler clang.
+ Fixes (`#73559 https://github.com/llvm/llvm-project/issues/73559`_)
Before:
diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp
index eba7ea65beee94..89a97cc96111d8 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -2678,7 +2678,9 @@ Parser::DeclGroupPtrTy
Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS,
ParsedAttributes &AccessAttrs,
const ParsedTemplateInfo &TemplateInfo,
- ParsingDeclRAIIObject *TemplateDiags) {
+ 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);
@@ -2702,7 +2704,7 @@ Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS,
bool MalformedTypeSpec = false;
if (!TemplateInfo.Kind &&
Tok.isOneOf(tok::identifier, tok::coloncolon, tok::kw___super)) {
- if (getLangOpts().CPlusPlus && TryAnnotateCXXScopeToken())
+ if (TryAnnotateCXXScopeToken())
MalformedTypeSpec = true;
bool isAccessDecl;
diff --git a/clang/test/Parser/cxx-in-c.c b/clang/test/Parser/cxx-in-c.c
index f5fa39bd0cb99b..bd304260571c4d 100644
--- a/clang/test/Parser/cxx-in-c.c
+++ b/clang/test/Parser/cxx-in-c.c
@@ -3,3 +3,4 @@
// 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}}
+::; // expected-error{{expected that double colon marker does not appear in c}}
>From ac0d1c6d440b9c94af9bf95dc27687e2437ce39b Mon Sep 17 00:00:00 2001
From: ChipsSpectre <maximilian.hornung at tum.de>
Date: Mon, 11 Dec 2023 22:35:17 +0100
Subject: [PATCH 3/3] enforce coding style
---
clang/lib/Parse/ParseDeclCXX.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp
index 89a97cc96111d8..1cf16a752cfcdc 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -2678,9 +2678,9 @@ Parser::DeclGroupPtrTy
Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS,
ParsedAttributes &AccessAttrs,
const ParsedTemplateInfo &TemplateInfo,
- ParsingDeclRAIIObject *TemplateDiags) {
+ ParsingDeclRAIIObject *TemplateDiags) {
assert(getLangOpts().CPlusPlus &&
- "Call sites of this function should be guarded by checking for C++");
+ "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);
More information about the libc-commits
mailing list