[clang] [Clang] Support the GNU copy attribute (PR #229355)

via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 19 09:47:16 PDT 2026


yujincheng08 wrote:

@AaronBallman Hi, I will quickly cover my motivation for this.

Basically, I want to implement a "function wrapper", in which we can insert code snippets before and after the function, e.g., performance instruments. Like the following:

```c++
<typename T>
struct FunctionWrapper;

<typename R, typename ...Args>
struct FunctionWrapper<R(Args...)> {
   R (*inner)(Args...);
   R operator()(Args... &&args) {
       // before snippets
       R ret = inner(std::forward<Args>(args)...);
       // after snippets
       return ret;
   }
};
```

Most of the time, it works. Until I face a function pointer with *calling convention*, e.g.,  `__fastcall___`. In this case, we cannot assign inner = *fastcall function pointer*.

So in this case, one way I think of is:
```
wrapper = +[] static (auto... args) [[gnu::copy(inner)]] { inner(args...); }
```
so that I can use a lambda instead to implement the wrapper and preserve the calling convention. It works on GCC, but I found that Clang does not support copy attribute.

https://github.com/llvm/llvm-project/pull/229355


More information about the cfe-commits mailing list