llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Oleksandr Tarasiuk (a-tarasyuk)

<details>
<summary>Changes</summary>

Fixes #<!-- -->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.

---
Full diff: https://github.com/llvm/llvm-project/pull/187859.diff


3 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+1) 
- (modified) clang/lib/Parse/ParseDeclCXX.cpp (+1-1) 
- (modified) clang/test/Parser/static_assert.cpp (+7-5) 


``````````diff
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, ""

``````````

</details>


https://github.com/llvm/llvm-project/pull/187859
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to