Skip to content

Commit 5436d89

Browse files
committed
[clang][Interp] Handle std::move etc. builtins
1 parent 7d1a9e8 commit 5436d89

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

clang/lib/AST/Interp/InterpBuiltin.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ static bool retPrimValue(InterpState &S, CodePtr OpPC, APValue &Result,
138138
case X: \
139139
return Ret<X>(S, OpPC, Result);
140140
switch (*T) {
141+
RET_CASE(PT_Ptr);
141142
RET_CASE(PT_Float);
142143
RET_CASE(PT_Bool);
143144
RET_CASE(PT_Sint8);
@@ -533,6 +534,15 @@ static bool interp__builtin_classify_type(InterpState &S, CodePtr OpPC,
533534
return true;
534535
}
535536

537+
static bool interp__builtin_move(InterpState &S, CodePtr OpPC,
538+
const InterpFrame *Frame, const Function *Func,
539+
const CallExpr *Call) {
540+
541+
const Pointer &Arg = S.Stk.peek<Pointer>();
542+
S.Stk.push<Pointer>(Arg);
543+
return Func->getDecl()->isConstexpr();
544+
}
545+
536546
bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F,
537547
const CallExpr *Call) {
538548
InterpFrame *Frame = S.Current;
@@ -702,6 +712,14 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F,
702712
return false;
703713
break;
704714

715+
case Builtin::BIas_const:
716+
case Builtin::BIforward:
717+
case Builtin::BIforward_like:
718+
case Builtin::BImove:
719+
if (!interp__builtin_move(S, OpPC, Frame, F, Call))
720+
return false;
721+
break;
722+
705723
default:
706724
return false;
707725
}

clang/test/AST/Interp/functions.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,3 +378,18 @@ namespace Packs {
378378
static_assert(foo<int, char>() == 2, "");
379379
static_assert(foo<>() == 0, "");
380380
}
381+
382+
namespace std {
383+
template <typename T> struct remove_reference { using type = T; };
384+
template <typename T> struct remove_reference<T &> { using type = T; };
385+
template <typename T> struct remove_reference<T &&> { using type = T; };
386+
template <typename T>
387+
constexpr typename std::remove_reference<T>::type&& move(T &&t) noexcept {
388+
return static_cast<typename std::remove_reference<T>::type &&>(t);
389+
}
390+
}
391+
/// The std::move declaration above gets translated to a builtin function.
392+
namespace Move {
393+
constexpr int A = std::move(5);
394+
static_assert(A == 5, "");
395+
}

0 commit comments

Comments
 (0)