================
@@ -751,38 +753,56 @@ void Parser::ParseLexedAttribute(LateParsedAttribute &LA,
 
   if (LA.Decls.size() > 0) {
     Decl *D = LA.Decls[0];
-    NamedDecl *ND  = dyn_cast<NamedDecl>(D);
-    RecordDecl *RD = dyn_cast_or_null<RecordDecl>(D->getDeclContext());
 
-    // Allow 'this' within late-parsed attributes.
-    Sema::CXXThisScopeRAII ThisScope(Actions, RD, Qualifiers(),
-                                     ND && ND->isCXXInstanceMember());
+    if (getLangOpts().CPlusPlus) {
+      NamedDecl *ND = dyn_cast<NamedDecl>(D);
+      RecordDecl *RD = dyn_cast_or_null<RecordDecl>(D->getDeclContext());
 
-    if (LA.Decls.size() == 1) {
-      // If the Decl is templatized, add template parameters to scope.
-      ReenterTemplateScopeRAII InDeclScope(*this, D, EnterScope);
+      // Allow 'this' within late-parsed attributes.
+      Sema::CXXThisScopeRAII ThisScope(Actions, RD, Qualifiers(),
+                                       ND && ND->isCXXInstanceMember());
 
-      // If the Decl is on a function, add function parameters to the scope.
+      if (LA.Decls.size() == 1) {
+        // If the Decl is templatized, add template parameters to scope.
+        ReenterTemplateScopeRAII InDeclScope(*this, D, EnterScope);
+
+        // If the Decl is on a function, add function parameters to the scope.
+        bool HasFunScope = EnterScope && D->isFunctionOrFunctionTemplate();
+        if (HasFunScope) {
+          InDeclScope.Scopes.Enter(Scope::FnScope | Scope::DeclScope |
+                                   Scope::CompoundStmtScope);
+          Actions.ActOnReenterFunctionContext(Actions.CurScope, D);
+        }
+
+        ParseGNUAttributeArgs(&LA.AttrName, LA.AttrNameLoc, Attrs, nullptr,
+                              nullptr, SourceLocation(),
+                              ParsedAttr::Form::GNU(), nullptr);
+
+        if (HasFunScope)
+          Actions.ActOnExitFunctionContext();
+      } else {
+        // If there are multiple decls, then the decl cannot be within the
+        // function scope.
+        ParseGNUAttributeArgs(&LA.AttrName, LA.AttrNameLoc, Attrs, nullptr,
+                              nullptr, SourceLocation(),
+                              ParsedAttr::Form::GNU(), nullptr);
+      }
+    } else {
       bool HasFunScope = EnterScope && D->isFunctionOrFunctionTemplate();
----------------
cor3ntin wrote:

You could move that above the if to avoid the duplication

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

Reply via email to