================
@@ -366,6 +389,101 @@ getFunctionSourceCode(const FunctionDecl *FD, const 
DeclContext *TargetContext,
       DelKeyword(tok::kw_explicit, {FD->getBeginLoc(), FD->getLocation()});
   }
 
+  // Drop attributes that the out-of-line definition inherits from the
+  // declaration. Ones we can't safely locate are left alone.
+  // FIXME: Attributes coing from macros and attributes unknown to clang (which
+  // are not part of the AST) are not dropped.
+  for (Attr *A : FD->attrs()) {
+    if (A->isImplicit() || A->isInherited())
+      continue;
+
+    // Get the delimiter for the attribute type
+    llvm::SmallVector<tok::TokenKind> LeftDelimiter, RightDelimiter;
+    switch (A->getSyntax()) {
+    case AttributeCommonInfo::AS_GNU:
+      // Delimited by __attribute__(( and ))
+      LeftDelimiter.assign({tok::kw___attribute, tok::l_paren, tok::l_paren});
+      RightDelimiter.assign({tok::r_paren, tok::r_paren});
+      break;
+    case AttributeCommonInfo::AS_CXX11:
+    case AttributeCommonInfo::AS_C23:
+      // Delimited by [[ and ]]
+      LeftDelimiter.assign({tok::l_square, tok::l_square});
+      RightDelimiter.assign({tok::r_square, tok::r_square});
+      break;
+    case AttributeCommonInfo::AS_Declspec:
+      // Delimited by __declspec( and )
+      LeftDelimiter.assign({tok::kw___declspec, tok::l_paren});
+      RightDelimiter.assign({tok::r_paren});
+      break;
+    default:
+      // All other syntaxes are not relevant here
+      break;
+    }
+
+    if (LeftDelimiter.empty() || RightDelimiter.empty())
+      continue;
+
+    auto FDTokens = TokBuf.spelledForExpanded(TokBuf.expandedTokens(
----------------
ckandeler wrote:

**[LLM-generated]** `FDTokens` doesn't depend on `A`, so it could be computed 
once before the loop rather than once per attribute.

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

Reply via email to