Skip to content

Commit fbed3f9

Browse files
zygoloidPavel V Chupin
authored andcommitted
Treat std::move, forward, etc. as builtins.
This is extended to all `std::` functions that take a reference to a value and return a reference (or pointer) to that same value: `move`, `forward`, `move_if_noexcept`, `as_const`, `addressof`, and the libstdc++-specific function `__addressof`. We still require these functions to be declared before they can be used, but don't instantiate their definitions unless their addresses are taken. Instead, code generation, constant evaluation, and static analysis are given direct knowledge of their effect. This change aims to reduce various costs associated with these functions -- per-instantiation memory costs, compile time and memory costs due to creating out-of-line copies and inlining them, code size at -O0, and so on -- so that they are not substantially more expensive than a cast. Most of these improvements are very small, but I measured a 3% decrease in -O0 object file size for a simple C++ source file using the standard library after this change. We now automatically infer the `const` and `nothrow` attributes on these now-builtin functions, in particular meaning that we get a warning for an unused call to one of these functions. In C++20 onwards, we disallow taking the addresses of these functions, per the C++20 "addressable function" rule. In earlier language modes, a compatibility warning is produced but the address can still be taken. The same infrastructure is extended to the existing MSVC builtin `__GetExceptionInfo`, which is now only recognized in namespace `std` like it always should have been. This is a re-commit of fc30901, a571f82, 64c045e, and de6ddae, and reverts aa643f4. This change also includes a workaround for users using libc++ 3.1 and earlier (!!), as apparently happens on AIX, where std::move sometimes returns by value. Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D123345 Revert "Fixup D123950 to address revert of D123345" This reverts commit aa643f4.
1 parent f709ece commit fbed3f9

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

clang/lib/CodeGen/CGExpr.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,6 +1176,8 @@ Address CodeGenFunction::EmitPointerWithAlignment(const Expr *E,
11761176
switch (Call->getBuiltinCallee()) {
11771177
default:
11781178
break;
1179+
case Builtin::BIaddressof:
1180+
case Builtin::BI__addressof:
11791181
case Builtin::BI__builtin_addressof: {
11801182
LValue LV = EmitLValue(Call->getArg(0));
11811183
if (BaseInfo) *BaseInfo = LV.getBaseInfo();

0 commit comments

Comments
 (0)