> Hi! > > clang++ adds __builtin_operator_{new,delete} builtins which as documented > work similarly to ::operator {new,delete}, except that it is an error > if the called ::operator {new,delete} is not a replaceable global operator > and allow optimizations which C++ normally allows just when those are used > from new/delete expressions https://eel.is/c++draft/expr.new#14 > When using these builtins, the same optimizations can be done even when > using those builtins. > > For GCC we note that in the CALL_FROM_NEW_OR_DELETE_P flag on CALL_EXPRs. > The following patch implements it as a C++ FE keyword (because passing > references through ... changes the argument and so BUILT_IN_FRONTEND > builtin can't be used), just attempts to call the ::operator {new,delete} > and if it isn't replaceable, diagnoses it. > > So far lightly tested, ok for trunk if it passes bootstrap/regtest > (note, libstdc++ already uses the builtin)? > Thanks a lot for the patch! I checked the counts of calls to operator delete (by greping disasembly for call.*_Zdl) in clang 20 binary built with -O3 -DNDEBUG and get:
after patch 70576 before patch 70366 So the patch certainly does something. (Based on earlier Martin's counts I hoped for more, but it is a start). Curiously clang 18 built binary has about 50k calls. These counts are not really comparable due to inlining differences but it would be really nice to know why there is such a huge difference. Counting actual runtime calls using ltrace and "grep _Zdl | wc -l" during tramp3d compilation show no significant difference between patched/unpatched gcc and clang 18. Honza