[PATCH] D123345: Treat `std::move`, `forward`, and `move_if_noexcept` as builtins.

Arthur O'Dwyer via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 11 09:29:05 PDT 2022


On Mon, Apr 11, 2022 at 12:14 PM Aaron Ballman via cfe-commits <
cfe-commits at lists.llvm.org> wrote:

> On Mon, Apr 11, 2022 at 10:50 AM Joerg Sonnenberger via Phabricator <
> reviews at reviews.llvm.org> wrote:
> >
> > joerg added a comment.
> >
> > The patch contains at least one user visible change that would be quite
> surprising: it is no longer possible to intentionally set a break point on
> `std::move`.
>
> Thank you, that is a really good point. It would be a surprise to set
> a breakpoint on the code I can see in debug mode (-O0 -g) and never
> hit the breakpoint.
>

The same is true of `std::strlen`: if it is builtin'ed, then you don't get
a call instruction. This is perfectly expected and natural.
https://godbolt.org/z/jYzTM4a7c
Passing -fno-builtin successfully disables the optimization for
std::strlen. It should also disable the proposed optimization for std::move.

Contra Aaron, I do not see *any difference at all* between what happens
today for std::strlen and what's proposed to happen tomorrow for
std::move.  I don't think std::move is somehow "more advanced" or "more
STL'ish" or "more C++'ish" than std::strlen. They're both part of the
standard library, and the compiler in hosted mode is allowed to assume it
knows what they do — but in freestanding mode (when -fno-builtin is passed)
the compiler should *not* assume it knows what they do.


> Thinking more about it, what about a slightly different implementation
> strategy? Provide a compiler built-in `__builtin_std_move`. If it is
> present, libc++ can alias it into `namespace std` using regular C++.


FWIW, Joerg, I don't understand this suggestion. By what means can libc++
"alias [a compiler builtin] into namespace std"? The only thing I have
imagined so far is something like
    inline auto move(auto&& t) { return __builtin_std_move(t); }
but that would defeat the whole purpose of adding the builtin. The point of
adding the builtin is to eliminate the cost of
instantiating+codegenning+inlining, a whole new function for every call.
In C you could get away with
    #define move(x) __builtin_std_move(x)
but that's a non-starter in C++, because namespaces.

–Arthur
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220411/fe3489ca/attachment.html>


More information about the cfe-commits mailing list