llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Chen Miao (ChenMiaoi)

<details>
<summary>Changes</summary>

Only recognize parenthesized direct initializers in C++ mode. This avoids an 
assertion when a malformed GNU attribute in C is followed by a parenthesized 
expression list:

```c
int a __attribute__ ) (1, 2);
```

Fixes #<!-- -->225045

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


2 Files Affected:

- (modified) clang/lib/Parse/ParseDecl.cpp (+1-1) 
- (modified) clang/test/Parser/attributes.c (+5) 


``````````diff
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index 6ab03e8a7fc4a..9793cd19c6206 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -2536,7 +2536,7 @@ Decl 
*Parser::ParseDeclarationAfterDeclaratorAndAttributes(
   // If a '==' or '+=' is found, suggest a fixit to '='.
   if (isTokenEqualOrEqualTypo())
     TheInitKind = InitKind::Equal;
-  else if (Tok.is(tok::l_paren))
+  else if (getLangOpts().CPlusPlus && Tok.is(tok::l_paren))
     TheInitKind = InitKind::CXXDirect;
   else if (getLangOpts().CPlusPlus11 && Tok.is(tok::l_brace) &&
            (!CurParsedObjCImpl || !D.isFunctionDeclarator()))
diff --git a/clang/test/Parser/attributes.c b/clang/test/Parser/attributes.c
index c73505d9f547d..a648f581cd7e6 100644
--- a/clang/test/Parser/attributes.c
+++ b/clang/test/Parser/attributes.c
@@ -116,3 +116,8 @@ __attribute__(()) struct t;
 void f5() {
   __attribute__(()) struct t;
 }
+
+// GH225045: attribute recovery must not parse a C++ direct initializer in C.
+// expected-error@+2 {{expected '(' after 'attribute'}}
+// expected-error@+1 {{expected ';' after top level declarator}}
+int a __attribute__ ) (1, 2);

``````````

</details>


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

Reply via email to