@@ -222,11 +222,25 @@ static bool interp__builtin_strcmp(InterpState &S, CodePtr OpPC,
222
222
return true ;
223
223
}
224
224
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
+ }
225
235
static bool interp__builtin_strlen (InterpState &S, CodePtr OpPC,
226
236
const InterpFrame *Frame,
227
- const CallExpr *Call) {
237
+ const Function *Func, const CallExpr *Call) {
238
+ unsigned ID = Func->getBuiltinID ();
228
239
const Pointer &StrPtr = getParam<Pointer>(Frame, 0 );
229
240
241
+ if (ID == Builtin::BIstrlen)
242
+ diagnoseNonConstexprBuiltin (S, OpPC, ID);
243
+
230
244
if (!CheckArray (S, OpPC, StrPtr))
231
245
return false ;
232
246
@@ -1781,12 +1795,16 @@ static bool interp__builtin_memcpy(InterpState &S, CodePtr OpPC,
1781
1795
const InterpFrame *Frame,
1782
1796
const Function *Func, const CallExpr *Call) {
1783
1797
assert (Call->getNumArgs () == 3 );
1798
+ unsigned ID = Func->getBuiltinID ();
1784
1799
Pointer DestPtr = getParam<Pointer>(Frame, 0 );
1785
1800
const Pointer &SrcPtr = getParam<Pointer>(Frame, 1 );
1786
1801
const APSInt &Size =
1787
1802
peekToAPSInt (S.Stk , *S.getContext ().classify (Call->getArg (2 )));
1788
1803
assert (!Size.isSigned () && " memcpy and friends take an unsigned size" );
1789
1804
1805
+ if (ID == Builtin::BImemcpy)
1806
+ diagnoseNonConstexprBuiltin (S, OpPC, ID);
1807
+
1790
1808
if (DestPtr.isDummy () || SrcPtr.isDummy ())
1791
1809
return false ;
1792
1810
@@ -1830,7 +1848,8 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F,
1830
1848
return false ;
1831
1849
break ;
1832
1850
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))
1834
1853
return false ;
1835
1854
break ;
1836
1855
case Builtin::BI__builtin_nan:
@@ -2271,6 +2290,7 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F,
2271
2290
break ;
2272
2291
2273
2292
case Builtin::BI__builtin_memcpy:
2293
+ case Builtin::BImemcpy:
2274
2294
if (!interp__builtin_memcpy (S, OpPC, Frame, F, Call))
2275
2295
return false ;
2276
2296
break ;
0 commit comments