[clang] [Clang] Add `noalias` to `this` pointer in C++ constructors (PR #136792)

Guy David via cfe-commits cfe-commits at lists.llvm.org
Tue May 13 09:21:37 PDT 2025


guy-david wrote:

> I just got a case:
> 
> ```
> class A {
> public:
>    class B {
>    public:
>          B(A *);
> 
>          // some non static data fields
>    };
> 
>    B b(this);
> };
> ```
> 
> Does this a valid prove that this optimization is not valid ?

This example is fine because `this` is passed directly to `B`'s constructor, so alias analysis can still succesfully track when it might alias other pointers and stop certain optimizations, despite the `noalias`.

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


More information about the cfe-commits mailing list