[clang] [Clang][Parser] Fix crash of clang when using C++ constructs like :: in C code (PR #74926)

2024-01-04 Thread via cfe-commits

https://github.com/cor3ntin closed 
https://github.com/llvm/llvm-project/pull/74926
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Parser] Fix crash of clang when using C++ constructs like :: in C code (PR #74926)

2024-01-04 Thread via cfe-commits

cor3ntin wrote:

Thanks for working on that!

https://github.com/llvm/llvm-project/pull/74926
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Parser] Fix crash of clang when using C++ constructs like :: in C code (PR #74926)

2024-01-04 Thread via cfe-commits

https://github.com/cor3ntin approved this pull request.


https://github.com/llvm/llvm-project/pull/74926
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Parser] Fix crash of clang when using C++ constructs like :: in C code (PR #74926)

2024-01-02 Thread via cfe-commits

ChipsSpectre wrote:

Sorry @tbaederr, I made a mistake in fixing the ReleaseNotes.

Now I added the missing brackets to the link for this issue in the ReleaseNotes.

Could you merge the pull request now?

https://github.com/llvm/llvm-project/pull/74926
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Parser] Fix crash of clang when using C++ constructs like :: in C code (PR #74926)

2024-01-02 Thread via cfe-commits

https://github.com/ChipsSpectre updated 
https://github.com/llvm/llvm-project/pull/74926

>From 92ae6f1d822e704cfc8f03d6582772758af3aa66 Mon Sep 17 00:00:00 2001
From: ChipsSpectre 
Date: Tue, 2 Jan 2024 17:14:21 +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  | 6 --
 clang/lib/Parse/ParseDecl.cpp| 3 ++-
 clang/lib/Parse/ParseDeclCXX.cpp | 2 ++
 clang/test/Parser/cxx-in-c.c | 3 +++
 4 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 0c8fec691bf3c9..9a1f7d9f0bcd33 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -685,9 +685,11 @@ Bug Fixes in This Version
   (`#65568 `_)
 - Fix an issue where clang doesn't respect detault template arguments that
   are added in a later redeclaration for CTAD.
-  Fixes (#69987 `_)
+  Fixes (`#69987 `_)
 - Fix an issue where CTAD fails for explicit type conversion.
-  Fixes (#64347 `_)
+  Fixes (`#64347 `_)
+- Fix crash when using C++ only tokens like ``::`` in C compiler clang.
+  Fixes (`#73559 `_)
 
 
 Bug Fixes to Compiler Builtins
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index ed006f9d67de45..b60ae293ef8c20 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..d97081da4200de 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 &&
+ "ParseCXXClassMemberDeclaration should only be called in C++ mode");
   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


[clang] [Clang][Parser] Fix crash of clang when using C++ constructs like :: in C code (PR #74926)

2023-12-31 Thread Timm Baeder via cfe-commits

tbaederr wrote:

The documentation build still fails fwiw.

https://github.com/llvm/llvm-project/pull/74926
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Parser] Fix crash of clang when using C++ constructs like :: in C code (PR #74926)

2023-12-30 Thread via cfe-commits

ChipsSpectre wrote:

@tbaederr The build is fixed now. Can you merge the pull request?

Since I have no write access to llvm-project, it seems I can not do it on my 
own:

![Screenshot](https://github.com/llvm/llvm-project/assets/11499442/e0fb925f-a72a-4c1e-827f-cb39c99faa4c)


https://github.com/llvm/llvm-project/pull/74926
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Parser] Fix crash of clang when using C++ constructs like :: in C code (PR #74926)

2023-12-30 Thread via cfe-commits

https://github.com/ChipsSpectre updated 
https://github.com/llvm/llvm-project/pull/74926

>From cb46f3aab771133e3987c65bcbd1f6011792e74c Mon Sep 17 00:00:00 2001
From: ChipsSpectre 
Date: Sat, 30 Dec 2023 23:01:12 +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  | 6 --
 clang/lib/Parse/ParseDecl.cpp| 3 ++-
 clang/lib/Parse/ParseDeclCXX.cpp | 2 ++
 clang/test/Parser/cxx-in-c.c | 3 +++
 4 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 0c8fec691bf3c9..da9b78b60bee8c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -685,9 +685,11 @@ Bug Fixes in This Version
   (`#65568 `_)
 - Fix an issue where clang doesn't respect detault template arguments that
   are added in a later redeclaration for CTAD.
-  Fixes (#69987 `_)
+  Fixes (`#69987 `_)
 - Fix an issue where CTAD fails for explicit type conversion.
-  Fixes (#64347 `_)
+  Fixes (`#64347 `_)
+- 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 ed006f9d67de45..b60ae293ef8c20 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..d97081da4200de 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 &&
+ "ParseCXXClassMemberDeclaration should only be called in C++ mode");
   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


[clang] [Clang][Parser] Fix crash of clang when using C++ constructs like :: in C code (PR #74926)

2023-12-30 Thread Timm Baeder via cfe-commits

tbaederr wrote:

The build fails though, with this error:

``
tools/clang/docs/ReleaseNotes.rst:691:Unknown target name: "#73559 
https://github.com/llvm/llvm-project/issues/73559";
``

https://github.com/llvm/llvm-project/pull/74926
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Parser] Fix crash of clang when using C++ constructs like :: in C code (PR #74926)

2023-12-30 Thread Timm Baeder via cfe-commits

tbaederr wrote:

It doesn't need a specific approval, just _any_. And @shafik has already 
approved this PR, so it can now be merged.

https://github.com/llvm/llvm-project/pull/74926
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Parser] Fix crash of clang when using C++ constructs like :: in C code (PR #74926)

2023-12-28 Thread via cfe-commits

ChipsSpectre wrote:

@tahonermann @AaronBallman @nicolasvasilache @dcaballe Could you please approve 
this issue?

The bug is fixed and already approved twice, but the pull request can not be 
landed without your approval.

https://github.com/llvm/llvm-project/pull/74926
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Parser] Fix crash of clang when using C++ constructs like :: in C code (PR #74926)

2023-12-20 Thread Shafik Yaghmour via cfe-commits

https://github.com/shafik approved this pull request.

If you have addressed all review comments and no one has asked you to wait to 
land the PR then you can land once you get an approval.

https://github.com/llvm/llvm-project/pull/74926
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Parser] Fix crash of clang when using C++ constructs like :: in C code (PR #74926)

2023-12-20 Thread via cfe-commits

ChipsSpectre wrote:

@cor3ntin thank you for your fast review!

Is it possible to merge it after your approval, or is it needed to wait for all 
reviewers?

https://github.com/llvm/llvm-project/pull/74926
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Parser] Fix crash of clang when using C++ constructs like :: in C code (PR #74926)

2023-12-20 Thread via cfe-commits

https://github.com/cor3ntin approved this pull request.

Thanks for working on this! It looks good now

https://github.com/llvm/llvm-project/pull/74926
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Parser] Fix crash of clang when using C++ constructs like :: in C code (PR #74926)

2023-12-20 Thread via cfe-commits

ChipsSpectre wrote:

ok @cor3ntin, the nit is addressed.

Is the pull request now ready to be merged?

https://github.com/llvm/llvm-project/pull/74926
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Parser] Fix crash of clang when using C++ constructs like :: in C code (PR #74926)

2023-12-20 Thread via cfe-commits

https://github.com/ChipsSpectre updated 
https://github.com/llvm/llvm-project/pull/74926

>From b8bd6e9551da9aefec0597e9ed84cdee2af58344 Mon Sep 17 00:00:00 2001
From: ChipsSpectre 
Date: Wed, 20 Dec 2023 17:43:13 +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 39b9176865fc04..a83c102b320df3 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -688,6 +688,8 @@ Bug Fixes in This Version
   Fixes (#69987 `_)
 - Fix an issue where CTAD fails for explicit type conversion.
   Fixes (#64347 `_)
+- 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 ed006f9d67de45..b60ae293ef8c20 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..d97081da4200de 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 &&
+ "ParseCXXClassMemberDeclaration should only be called in C++ mode");
   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


[clang] [Clang][Parser] Fix crash of clang when using C++ constructs like :: in C code (PR #74926)

2023-12-20 Thread via cfe-commits

https://github.com/cor3ntin commented:

Thanks for fixing this bug.
LGTM modulo nit

https://github.com/llvm/llvm-project/pull/74926
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Parser] Fix crash of clang when using C++ constructs like :: in C code (PR #74926)

2023-12-20 Thread via cfe-commits


@@ -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++");

cor3ntin wrote:

```suggestion
 "ParseCXXClassMemberDeclaration should only be called in C++ mode");
```

https://github.com/llvm/llvm-project/pull/74926
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Parser] Fix crash of clang when using C++ constructs like :: in C code (PR #74926)

2023-12-19 Thread via cfe-commits

ChipsSpectre wrote:

The Fork is now rebased on main, so the conflict in `ReleaseNotes.rst` is 
resolved.

@tbaederr Do you think it is ready to be merged now?

https://github.com/llvm/llvm-project/pull/74926
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Parser] Fix crash of clang when using C++ constructs like :: in C code (PR #74926)

2023-12-19 Thread via cfe-commits

https://github.com/ChipsSpectre updated 
https://github.com/llvm/llvm-project/pull/74926

>From a08d9029445087b78d19715991c426106d9b0ca6 Mon Sep 17 00:00:00 2001
From: ChipsSpectre 
Date: Wed, 20 Dec 2023 07:33:20 +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 39b9176865fc04..a83c102b320df3 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -688,6 +688,8 @@ Bug Fixes in This Version
   Fixes (#69987 `_)
 - Fix an issue where CTAD fails for explicit type conversion.
   Fixes (#64347 `_)
+- 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 ed006f9d67de45..b60ae293ef8c20 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


[clang] [Clang][Parser] Fix crash of clang when using C++ constructs like :: in C code (PR #74926)

2023-12-19 Thread via cfe-commits

https://github.com/ChipsSpectre updated 
https://github.com/llvm/llvm-project/pull/74926

>From 28a5e6ffab5ec5fef7edce58c4dbdebffcfaabe3 Mon Sep 17 00:00:00 2001
From: ChipsSpectre 
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  | 3 ++-
 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(+), 2 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 39b9176865fc04..dd945f3eca4629 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -688,7 +688,8 @@ Bug Fixes in This Version
   Fixes (#69987 `_)
 - Fix an issue where CTAD fails for explicit type conversion.
   Fixes (#64347 `_)
-
+- 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 ed006f9d67de45..b60ae293ef8c20 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


[clang] [Clang][Parser] Fix crash of clang when using C++ constructs like :: in C code (PR #74926)

2023-12-18 Thread Timm Baeder via cfe-commits

tbaederr wrote:

There's a conflict in the `ReleaseNotes.rst` again unfortunately :(

https://github.com/llvm/llvm-project/pull/74926
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Parser] Fix crash of clang when using C++ constructs like :: in C code (PR #74926)

2023-12-18 Thread via cfe-commits

ChipsSpectre wrote:

@shafik ok, done 

https://github.com/llvm/llvm-project/pull/74926
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Parser] Fix crash of clang when using C++ constructs like :: in C code (PR #74926)

2023-12-18 Thread via cfe-commits

https://github.com/ChipsSpectre edited 
https://github.com/llvm/llvm-project/pull/74926
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits