================
@@ -1970,6 +2024,13 @@ Sema::ConditionResult 
Parser::ParseCXXCondition(StmtResult *InitStmt,
   DeclSpec DS(AttrFactory);
   ParseSpecifierQualifierList(DS, AS_none, DeclSpecContext::DSC_condition);
 
+  // The Declarator's DeclarationAttrs only accepts [[]] and keyword 
attributes;
+  // move any GNU attributes onto the DeclSpec instead.
+  if (!getLangOpts().CPlusPlus)
----------------
bassiounix wrote:

The reason for the crash is this assert and the intended use of `Declarator`

```cpp
  /// `DS` and `DeclarationAttrs` must outlive the `Declarator`. In particular,
  /// take care not to pass temporary objects for these parameters.
  ///
  /// `DeclarationAttrs` contains [[]] attributes from the
  /// attribute-specifier-seq at the beginning of a declaration, which appertain
  /// to the declared entity itself. Attributes with other syntax (e.g. GNU)
  /// should not be placed in this attribute list; if they occur at the
  /// beginning of a declaration, they apply to the `DeclSpec` and should be
  /// attached to that instead.
  ///
  /// Here is an example of an attribute associated with a declaration:
  ///
  ///  [[deprecated]] int x, y;
  ///
  /// This attribute appertains to all of the entities declared in the
  /// declaration, i.e. `x` and `y` in this case.
  Declarator(const DeclSpec &DS, const ParsedAttributesView &DeclarationAttrs,
             DeclaratorContext C)
      : ... {
    assert(llvm::all_of(DeclarationAttrs,
                        [](const ParsedAttr &AL) {
                          return (AL.isStandardAttributeSyntax() ||
                                  AL.isRegularKeywordAttribute());
                        }) &&
           "DeclarationAttrs may only contain [[]] and keyword attributes");
  }
```

Specifically
> /// ... Attributes with other syntax (e.g. GNU)
  /// should not be placed in this attribute list; if they occur at the
  /// beginning of a declaration, they apply to the `DeclSpec` and should be
  /// attached to that instead.

So by doing this
```cpp
  if (!getLangOpts().CPlusPlus)
    for (ParsedAttr &AL : attrs)
      if (AL.isGNUAttribute())
        DS.getAttributes().takeOneFrom(attrs, &AL);
```
I'm effectively applying the GNU attributes to the `DeclSpec` and attaching to 
that instead.
I don't think altering the predicate of `all_of` is the solution here, but what 
I did.

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

Reply via email to