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

2025-05-22 Thread John McCall via cfe-commits
rjmccall wrote: Okay, it sounds like this is where we've left off: - The standard is using an odd formulation in [[class.cdtor]p2](https://eel.is/c++draft/class.cdtor) that we're not sure how to interpret. It's possible that it's formally slightly weaker than `restrict` might be, which would m

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

2025-05-15 Thread Florian Hahn via cfe-commits
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

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

2025-05-13 Thread Guy David via cfe-commits
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 `

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

2025-05-13 Thread Chuanqi Xu via cfe-commits
ChuanqiXu9 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 ? https://github.com/llvm/llvm-project/pull/136792 __

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

2025-05-13 Thread Richard Smith via cfe-commits
zygoloid wrote: > @zygoloid Can you explain in your example why `a.n == 2` must be true, when > your interpretation (which I understood in the same manner) of the standard's > wording does indicate that the object's state is unspecified? My reading is that the standard says that the value of `

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

2025-05-13 Thread Guy David via cfe-commits
guy-david wrote: > > @zygoloid Can you explain in your example why `a.n == 2` must be true, when > > your interpretation (which I understood in the same manner) of the > > standard's wording does indicate that the object's state is unspecified? > > My reading is that the standard says that the

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

2025-05-12 Thread Eli Friedman via cfe-commits
efriedma-quic wrote: These days, there's very high demand for "secure" C/C++. From this perspective, this optimization is a security threat: if you write code that does an undefined write to "this", you have a lurking security vulnerability could be exposed with any change to optimization heu

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

2025-05-09 Thread Guy David via cfe-commits
guy-david wrote: @efriedma-quic ping :) https://github.com/llvm/llvm-project/pull/136792 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

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

2025-05-06 Thread Guy David via cfe-commits
https://github.com/guy-david edited https://github.com/llvm/llvm-project/pull/136792 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

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

2025-05-04 Thread Guy David via cfe-commits
https://github.com/guy-david ready_for_review https://github.com/llvm/llvm-project/pull/136792 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

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

2025-05-04 Thread via cfe-commits
llvmbot wrote: @llvm/pr-subscribers-hlsl Author: Guy David (guy-david) Changes Note: the patch is probably amending the wrong piece of code, I've tried to add it to `buildThisParam` but hit an assertion because of a missing translation unit context. Clang does not transform the followin

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

2025-05-04 Thread Guy David via cfe-commits
guy-david wrote: Comparison between latest Clang and GCC's output for a snippet out of a benchmark that could use this optimization: https://godbolt.org/z/35EEvcsPr. I've ran llvm-test-suite ten times for the before and after, it executed correctly and expectedly saw no performance gains: ```

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

2025-04-23 Thread Richard Smith via cfe-commits
zygoloid wrote: > * I'm not sure this matches the requirements for C++ semantics; noalias is > very aggressive, so we might end up with undefined behavior in unintended > cases. I'd like someone familiar with the relevant standard bits to comment > on the requirements here. CC @zygoloid The

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

2025-04-23 Thread Eli Friedman via cfe-commits
efriedma-quic wrote: That said, in terms of whether we actually care about what the committee says... both the C and C++ committees have a terrible track record on the fine details of stuff related to memory. I'd be okay with being slightly more aggressive than the standard technically allows

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

2025-04-23 Thread Eli Friedman via cfe-commits
efriedma-quic wrote: We don't really specify what, exactly, the consequences are for violating noalias in LangRef. But... we do say elsewhere "If memory accesses alias even though they are noalias according to !tbaa metadata, the behavior is undefined." Probably the same has to apply to noal

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

2025-04-23 Thread Guy David via cfe-commits
guy-david wrote: Yeah, I realize it's misplaced, I am not familiar with that part of the project, see the first paragraph in the PR description. I don't really agree with your second point about breaking people's existing assumptions on UB :) I am willing to run correctness suites to further v

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

2025-04-23 Thread Eli Friedman via cfe-commits
efriedma-quic wrote: This isn't really the right place to add this code; we should be doing it alongside all the other attributes on function definitions... That said: - I'm not sure this matches the requirements for C++ semantics; noalias is very aggressive, so we might end up with undefined

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

2025-04-22 Thread Guy David via cfe-commits
https://github.com/guy-david edited https://github.com/llvm/llvm-project/pull/136792 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

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

2025-04-22 Thread via cfe-commits
github-actions[bot] wrote: :warning: C/C++ code formatter, clang-format found issues in your code. :warning: You can test this locally with the following command: ``bash git-clang-format --diff HEAD~1 HEAD --extensions cpp -- clang/lib/CodeGen/CodeGenFunction.cpp ``

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

2025-04-22 Thread Guy David via cfe-commits
https://github.com/guy-david edited https://github.com/llvm/llvm-project/pull/136792 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

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

2025-04-22 Thread Guy David via cfe-commits
https://github.com/guy-david edited https://github.com/llvm/llvm-project/pull/136792 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

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

2025-04-22 Thread Guy David via cfe-commits
https://github.com/guy-david edited https://github.com/llvm/llvm-project/pull/136792 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

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

2025-04-22 Thread Guy David via cfe-commits
https://github.com/guy-david created https://github.com/llvm/llvm-project/pull/136792 Note: the patch is probably amending the wrong piece of code, I've tried to add it to `buildThisParam` but hit an assertion because of a missing translation unit context. Clang, unlike GCC, does not transfor