@@ -243,7 +243,7 @@ static bool interp__builtin_strlen(InterpState &S, CodePtr OpPC,
243243 unsigned ID = Func->getBuiltinID ();
244244 const Pointer &StrPtr = getParam<Pointer>(Frame, 0 );
245245
246- if (ID == Builtin::BIstrlen)
246+ if (ID == Builtin::BIstrlen || ID == Builtin::BIwcslen )
247247 diagnoseNonConstexprBuiltin (S, OpPC, ID);
248248
249249 if (!CheckArray (S, OpPC, StrPtr))
@@ -256,15 +256,28 @@ static bool interp__builtin_strlen(InterpState &S, CodePtr OpPC,
256256 return false ;
257257
258258 assert (StrPtr.getFieldDesc ()->isPrimitiveArray ());
259-
259+ unsigned ElemSize = StrPtr. getFieldDesc ()-> getElemSize ();
260260 size_t Len = 0 ;
261261 for (size_t I = StrPtr.getIndex ();; ++I, ++Len) {
262262 const Pointer &ElemPtr = StrPtr.atIndex (I);
263263
264264 if (!CheckRange (S, OpPC, ElemPtr, AK_Read))
265265 return false ;
266266
267- uint8_t Val = ElemPtr.deref <uint8_t >();
267+ uint32_t Val;
268+ switch (ElemSize) {
269+ case 1 :
270+ Val = ElemPtr.deref <uint8_t >();
271+ break ;
272+ case 2 :
273+ Val = ElemPtr.deref <uint16_t >();
274+ break ;
275+ case 4 :
276+ Val = ElemPtr.deref <uint32_t >();
277+ break ;
278+ default :
279+ llvm_unreachable (" Unsupported char size" );
280+ }
268281 if (Val == 0 )
269282 break ;
270283 }
@@ -1859,6 +1872,8 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F,
18591872 break ;
18601873 case Builtin::BI__builtin_strlen:
18611874 case Builtin::BIstrlen:
1875+ case Builtin::BI__builtin_wcslen:
1876+ case Builtin::BIwcslen:
18621877 if (!interp__builtin_strlen (S, OpPC, Frame, F, Call))
18631878 return false ;
18641879 break ;
0 commit comments