[Bug c++/112335] missed optimization on reset and assign unique_ptr

2023-11-03 Thread redi at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112335 --- Comment #10 from Jonathan Wakely --- Ah, now I understand what you've been saying about the postcondition. Yes, but the compiler doesn't know the postcondition, it's just words in the standard, so not visible to the optimization passes. It

[Bug c++/112335] missed optimization on reset and assign unique_ptr

2023-11-03 Thread federico at kircheis dot it via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112335 --- Comment #9 from Federico Kircheis --- Great, thank you for the clarifications, your redacted example makes now sense. > https://godbolt.org/z/WGPTesEb3 shows that bar3 is not the same as bar1, > because it runs an additional destructor if

[Bug c++/112335] missed optimization on reset and assign unique_ptr

2023-11-03 Thread redi at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112335 --- Comment #8 from Jonathan Wakely --- (In reply to Federico Kircheis from comment #7) > > Demo: https://godbolt.org/z/PWd96j4fz > > Thank you for the example, but honestly, I think I am still missing > something. > > If you modify the main t

[Bug c++/112335] missed optimization on reset and assign unique_ptr

2023-11-03 Thread federico at kircheis dot it via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112335 --- Comment #7 from Federico Kircheis --- Thank you Jonathan, I've then misunderstood the example of Andrew, I thought he was trying to create a scenario where after reset the pointer is not nullptr. > Demo: https://godbolt.org/z/PWd96j4fz Tha

[Bug c++/112335] missed optimization on reset and assign unique_ptr

2023-11-02 Thread redi at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112335 Jonathan Wakely changed: What|Removed |Added Resolution|--- |INVALID Status|UNCONFIRME

[Bug c++/112335] missed optimization on reset and assign unique_ptr

2023-11-02 Thread federico at kircheis dot it via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112335 --- Comment #5 from Federico Kircheis --- Ok, the described case would be something like std::unique_ptr t; __thread bool tt; inline s::~s() { if (tt) return; tt = true; t.reset(new s); tt = false; } std::unique_ptr t2; bar(t,

[Bug c++/112335] missed optimization on reset and assign unique_ptr

2023-11-02 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112335 --- Comment #4 from Andrew Pinski --- (In reply to Federico Kircheis from comment #2) > > Well s::~s could touch the reference std::unique_ptr (ps1). > > In both cases, s::~s is called only once. > > Also during the move-assignment no user-pro

[Bug c++/112335] missed optimization on reset and assign unique_ptr

2023-11-02 Thread federico at kircheis dot it via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112335 --- Comment #3 from Federico Kircheis --- Or maybe I've misunderstood your comment. Do you have a specific scenario in mind where the two snippets would exhibit different behaviors?

[Bug c++/112335] missed optimization on reset and assign unique_ptr

2023-11-02 Thread federico at kircheis dot it via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112335 --- Comment #2 from Federico Kircheis --- > Well s::~s could touch the reference std::unique_ptr (ps1). In both cases, s::~s is called only once. Also during the move-assignment no user-provided-code is involved (except the destruction of ps1,

[Bug c++/112335] missed optimization on reset and assign unique_ptr

2023-11-01 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112335 --- Comment #1 from Andrew Pinski --- __old_p_6 = MEM[(struct s * &)ps1_2(D)]; MEM[(struct s * &)ps1_2(D)] = 0B; if (__old_p_6 != 0B) goto ; [53.47%] else goto ; [46.53%] [local count: 574129752]: s::~s (__old_p_6); opera