@@ -222,11 +222,25 @@ static bool interp__builtin_strcmp(InterpState &S, CodePtr OpPC,
222222 return true ;
223223}
224224
225+ static void diagnoseNonConstexprBuiltin (InterpState &S, CodePtr OpPC,
226+ unsigned ID) {
227+ auto Loc = S.Current ->getSource (OpPC);
228+ if (S.getLangOpts ().CPlusPlus11 )
229+ S.CCEDiag (Loc, diag::note_constexpr_invalid_function)
230+ << /* isConstexpr=*/ 0 << /* isConstructor=*/ 0
231+ << (" '" + S.getASTContext ().BuiltinInfo .getName (ID) + " '" ).str ();
232+ else
233+ S.CCEDiag (Loc, diag::note_invalid_subexpr_in_const_expr);
234+ }
225235static bool interp__builtin_strlen (InterpState &S, CodePtr OpPC,
226236 const InterpFrame *Frame,
227- const CallExpr *Call) {
237+ const Function *Func, const CallExpr *Call) {
238+ unsigned ID = Func->getBuiltinID ();
228239 const Pointer &StrPtr = getParam<Pointer>(Frame, 0 );
229240
241+ if (ID == Builtin::BIstrlen)
242+ diagnoseNonConstexprBuiltin (S, OpPC, ID);
243+
230244 if (!CheckArray (S, OpPC, StrPtr))
231245 return false ;
232246
@@ -1781,12 +1795,16 @@ static bool interp__builtin_memcpy(InterpState &S, CodePtr OpPC,
17811795 const InterpFrame *Frame,
17821796 const Function *Func, const CallExpr *Call) {
17831797 assert (Call->getNumArgs () == 3 );
1798+ unsigned ID = Func->getBuiltinID ();
17841799 Pointer DestPtr = getParam<Pointer>(Frame, 0 );
17851800 const Pointer &SrcPtr = getParam<Pointer>(Frame, 1 );
17861801 const APSInt &Size =
17871802 peekToAPSInt (S.Stk , *S.getContext ().classify (Call->getArg (2 )));
17881803 assert (!Size.isSigned () && " memcpy and friends take an unsigned size" );
17891804
1805+ if (ID == Builtin::BImemcpy)
1806+ diagnoseNonConstexprBuiltin (S, OpPC, ID);
1807+
17901808 if (DestPtr.isDummy () || SrcPtr.isDummy ())
17911809 return false ;
17921810
@@ -1830,7 +1848,8 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F,
18301848 return false ;
18311849 break ;
18321850 case Builtin::BI__builtin_strlen:
1833- if (!interp__builtin_strlen (S, OpPC, Frame, Call))
1851+ case Builtin::BIstrlen:
1852+ if (!interp__builtin_strlen (S, OpPC, Frame, F, Call))
18341853 return false ;
18351854 break ;
18361855 case Builtin::BI__builtin_nan:
@@ -2271,6 +2290,7 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F,
22712290 break ;
22722291
22732292 case Builtin::BI__builtin_memcpy:
2293+ case Builtin::BImemcpy:
22742294 if (!interp__builtin_memcpy (S, OpPC, Frame, F, Call))
22752295 return false ;
22762296 break ;
0 commit comments