[clang] [Clang] Add `noalias` to `this` pointer in C++ constructors (PR #136792)
Florian Hahn via cfe-commits
cfe-commits at lists.llvm.org
Thu May 15 02:58:40 PDT 2025
https://github.com/fhahn commented:
> > I just got a case:
> > ```
> > class A {
> > public:
> > class B {
> > public:
> > B(A *);
> >
> > // some non static data fields
> > };
> > 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`.
I might be missing something here and it would be good to see how it would like in LLVM IR, but if we have `noalias` on a pointer, then alias analysis can use this to determine no-alias even if it can also prove that 2 involved pointers are equal through other means (this case would be UB).
https://github.com/llvm/llvm-project/pull/136792
More information about the cfe-commits
mailing list