================
@@ -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()) {
----------------
max-winkler wrote:

Thanks for raising this point.  There is no general rule for which attributes 
can be dropped, so the tweak now leaves all attributes untouched if the function

- is multiversioned (due to attributes target, cpu_specific), this can be 
checked by the FunctionDecl,
- has an explicit non-inheritable attribute (e.g. abi_tag), this can be 
retrieved from the Attribute class,
- has an attribute from a denylist (currently enable_if, overloadable).

The denylist is probably not exhaustive. I went through 
`Sema::mergeDeclAttributes` and the attribute diagnostics in Sema and covered 
the cases I found. Missing attributes can be added easily.

Tests are added for all three cases.

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