Skip to content

Commit ce479ce

Browse files
authored
[jitcall] Do not require <utility> for std::move. (#916)
This patch uses the underlying implementation of std::move instead.
1 parent b4af14b commit ce479ce

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

lib/CppInterOp/CppInterOp.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2795,14 +2795,16 @@ void make_narg_call(const FunctionDecl* FD, const std::string& return_type,
27952795
// so check for the most common case: the trivial one, but not uniquely
27962796
// available, while there is a move constructor.
27972797

2798-
// include utility header if not already included for std::move
2799-
DeclarationName DMove = &getASTContext().Idents.get("move");
2800-
auto result = getSema().getStdNamespace()->lookup(DMove);
2801-
if (result.empty())
2802-
Cpp::Declare("#include <utility>");
2803-
2804-
// move construction as needed for classes (note that this is implicit)
2805-
callbuf << "std::move(*(" << type_name.c_str() << "*)args[" << i << "])";
2798+
// Move construction as needed for classes (note that this is
2799+
// implicit). Emit `std::move`'s expansion directly rather than the
2800+
// name: a cast to T&& is the definition of std::move for
2801+
// non-reference T ([utility.swap]), and this avoids pulling
2802+
// <utility> into the user's TU just to obtain the name. It also
2803+
// sidesteps the `getSema().getStdNamespace()->lookup(...)` call,
2804+
// which dereferences a nullptr when no `std::` has been parsed
2805+
// yet in this interpreter's TU.
2806+
callbuf << "static_cast<" << type_name.c_str() << "&&>(*("
2807+
<< type_name.c_str() << "*)args[" << i << "])";
28062808
} else {
28072809
// pointer falls back to non-pointer case; the argument preserves
28082810
// the "pointerness" (i.e. doesn't reference the value).

0 commit comments

Comments
 (0)