[compiler-rt] [flang] [libcxx] [clang] [openmp] [libc] [clang-tools-extra] [lldb] [mlir] [lld] [llvm] fix issue 73559. (PR #74926)

via cfe-commits cfe-commits at lists.llvm.org
Tue Dec 12 13:23:38 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/6] 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;

>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/6] 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 6e4009deaf874..39dd8c68dbbcb 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 eba7ea65beee9..89a97cc96111d 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 f5fa39bd0cb99..bd304260571c4 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/6] 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 89a97cc96111d..1cf16a752cfcd 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);

>From f926f85fcfcf9286f3d4cdf968a0c6df453185e0 Mon Sep 17 00:00:00 2001
From: ChipsSpectre <maximilian.hornung at tum.de>
Date: Mon, 11 Dec 2023 23:41:46 +0100
Subject: [PATCH 4/6] fix test case

---
 clang/test/Parser/cxx-in-c.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/Parser/cxx-in-c.c b/clang/test/Parser/cxx-in-c.c
index bd304260571c4..98f7d5db1778a 100644
--- a/clang/test/Parser/cxx-in-c.c
+++ b/clang/test/Parser/cxx-in-c.c
@@ -3,4 +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}}
+::; // expected-error{{expected identifier or '('}}

>From cf8c575c2a36698f7d03b0561fc63cba7d9e0758 Mon Sep 17 00:00:00 2001
From: ChipsSpectre <maxi.hornung at t-online.de>
Date: Tue, 12 Dec 2023 22:23:15 +0100
Subject: [PATCH 5/6] Update clang/docs/ReleaseNotes.rst

Co-authored-by: Mariya Podchishchaeva <mariya.podchishchaeva at intel.com>
---
 clang/docs/ReleaseNotes.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 59f131ea79465..92a5b5e39edbc 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -641,7 +641,7 @@ 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.
+- Fix crash when using C++ only tokens like ``::`` in C compiler clang.
   Fixes (`#73559 https://github.com/llvm/llvm-project/issues/73559`_)
 
   Before:

>From 331ac5aba3c94518612e041de09072c3ec0811bf Mon Sep 17 00:00:00 2001
From: ChipsSpectre <maxi.hornung at t-online.de>
Date: Tue, 12 Dec 2023 22:23:27 +0100
Subject: [PATCH 6/6] Update clang/test/Parser/cxx-in-c.c

Co-authored-by: Mariya Podchishchaeva <mariya.podchishchaeva at intel.com>
---
 clang/test/Parser/cxx-in-c.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/clang/test/Parser/cxx-in-c.c b/clang/test/Parser/cxx-in-c.c
index 98f7d5db1778a..034a44cdf12bf 100644
--- a/clang/test/Parser/cxx-in-c.c
+++ b/clang/test/Parser/cxx-in-c.c
@@ -3,4 +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 '('}}



More information about the cfe-commits mailing list