@@ -164,6 +164,8 @@ static bool retPrimValue(InterpState &S, CodePtr OpPC, APValue &Result,
164164 case X: \
165165 return Ret<X>(S, OpPC, Result);
166166 switch (*T) {
167+ RET_CASE (PT_Ptr);
168+ RET_CASE (PT_FnPtr);
167169 RET_CASE (PT_Float);
168170 RET_CASE (PT_Bool);
169171 RET_CASE (PT_Sint8);
@@ -613,15 +615,34 @@ static bool interp__builtin_ffs(InterpState &S, CodePtr OpPC,
613615 return true ;
614616}
615617
618+ static bool interp__builtin_addressof (InterpState &S, CodePtr OpPC,
619+ const InterpFrame *Frame,
620+ const Function *Func,
621+ const CallExpr *Call) {
622+ PrimType PtrT =
623+ S.getContext ().classify (Call->getArg (0 )->getType ()).value_or (PT_Ptr);
624+
625+ if (PtrT == PT_FnPtr) {
626+ const FunctionPointer &Arg = S.Stk .peek <FunctionPointer>();
627+ S.Stk .push <FunctionPointer>(Arg);
628+ } else if (PtrT == PT_Ptr) {
629+ const Pointer &Arg = S.Stk .peek <Pointer>();
630+ S.Stk .push <Pointer>(Arg);
631+ } else {
632+ assert (false && " Unsupported pointer type passed to __builtin_addressof()" );
633+ }
634+ return true ;
635+ }
636+
616637bool InterpretBuiltin (InterpState &S, CodePtr OpPC, const Function *F,
617638 const CallExpr *Call) {
618639 InterpFrame *Frame = S.Current ;
619640 APValue Dummy;
620641
621- QualType ReturnType = Call->getCallReturnType (S. getCtx ());
622- std::optional<PrimType> ReturnT = S. getContext (). classify (ReturnType);
642+ std::optional<PrimType> ReturnT = S. getContext (). classify ( Call->getType ());
643+
623644 // If classify failed, we assume void.
624- assert (ReturnT || ReturnType ->isVoidType ());
645+ assert (ReturnT || Call-> getType () ->isVoidType ());
625646
626647 switch (F->getBuiltinID ()) {
627648 case Builtin::BI__builtin_is_constant_evaluated:
@@ -820,6 +841,12 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F,
820841 if (!interp__builtin_ffs (S, OpPC, Frame, F, Call))
821842 return false ;
822843 break ;
844+ case Builtin::BIaddressof:
845+ case Builtin::BI__addressof:
846+ case Builtin::BI__builtin_addressof:
847+ if (!interp__builtin_addressof (S, OpPC, Frame, F, Call))
848+ return false ;
849+ break ;
823850
824851 default :
825852 return false ;
0 commit comments