[Clang] fix parser recovery for invalid static_assert string messages - #187859
Conversation
|
@llvm/pr-subscribers-clang Author: Oleksandr Tarasiuk (a-tarasyuk) ChangesFixes #187690 This PR fixes parser recovery for invalid Full diff: https://github.com/llvm/llvm-project/pull/187859.diff 3 Files Affected:
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 45234c316eba8..fb674faa42006 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -339,6 +339,7 @@ Bug Fixes in This Version
- Fixed a crash when normalizing constraints involving concept template parameters whose index coincided with non-concept template parameters in the same parameter mapping.
- Fixed a crash caused by accessing dependent diagnostics of a non-dependent context.
- Fixed a crash when substituting into a non-type template parameter that has a type containing an undeduced placeholder type.
+- Fixed a crash when parsing invalid ``static_assert`` declarations with string-literal messages (#GH187690).
Bug Fixes to Compiler Builtins
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp
index 274c354d59808..e3bb52647176f 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -980,7 +980,7 @@ Decl *Parser::ParseStaticAssertDeclaration(SourceLocation &DeclEnd) {
if (getLangOpts().CPlusPlus11) {
for (unsigned I = 0;; ++I) {
const Token &T = GetLookAheadToken(I);
- if (T.is(tok::r_paren))
+ if (T.isOneOf(tok::r_paren, tok::semi, tok::eof))
break;
if (!tokenIsLikeStringLiteral(T, getLangOpts()) || T.hasUDSuffix()) {
ParseAsExpression = true;
diff --git a/clang/test/Parser/static_assert.cpp b/clang/test/Parser/static_assert.cpp
index 4fe7d3cda7b21..52ef8a93cea34 100644
--- a/clang/test/Parser/static_assert.cpp
+++ b/clang/test/Parser/static_assert.cpp
@@ -1,6 +1,8 @@
-// RUN: %clang_cc1 -fsyntax-only -triple=x86_64-linux -std=c++2a -verify=cxx2a %s
-// RUN: %clang_cc1 -fsyntax-only -triple=x86_64-linux -std=c++2c -verify=cxx2c %s
+// RUN: %clang_cc1 -fsyntax-only -triple=x86_64-linux -verify %s
-static_assert(true, "" // cxx2a-warning {{'static_assert' with a user-generated message is a C++26 extension}} \
- // cxx2a-note {{to match this '('}} cxx2c-note {{to match this '('}}
- // cxx2a-error {{expected ')'}} cxx2c-error {{expected ')'}}
+// expected-error@+1 {{unexpected ';' before ')'}}
+static_assert(true, "";);
+
+// expected-error@+2 {{expected ')'}}
+// expected-note@+1 {{to match this '('}}
+static_assert(true, ""
|
|
bisect points to this commit: #102044 it may help you formulate a better fix. |
|
@a-tarasyuk Can I ask why you close this PR? |
|
@cor3ntin, after the latest discussion, I got the impression that the goal was to fully rethink recovery handling, not just for |
|
@a-tarasyuk while we might want to think more about So i think we should land this. |
…llvm#187859) Fixes llvm#187690 --- This PR fixes parser recovery for invalid `static_assert` declarations with string literal messages. The parser now stops the message lookahead on `;` and `eof`, so invalid inputs are diagnosed as parse errors.
…llvm#187859) Fixes llvm#187690 --- This PR fixes parser recovery for invalid `static_assert` declarations with string literal messages. The parser now stops the message lookahead on `;` and `eof`, so invalid inputs are diagnosed as parse errors.
Fixes #187690
This PR fixes parser recovery for invalid
static_assertdeclarations with string literal messages. The parser now stops the message lookahead on;andeof, so invalid inputs are diagnosed as parse errors.