Index: flang/include/flang/Runtime/character.h =================================================================== --- flang/include/flang/Runtime/character.h +++ flang/include/flang/Runtime/character.h @@ -13,6 +13,7 @@ #define FORTRAN_RUNTIME_CHARACTER_H_ #include "flang/Runtime/entry-names.h" #include +#include namespace Fortran::runtime { @@ -97,7 +98,7 @@ void RTNAME(LenTrim)(Descriptor &result, const Descriptor &, int kind, const char *sourceFile = nullptr, int sourceLine = 0); void RTNAME(Repeat)(Descriptor &result, const Descriptor &string, - std::size_t ncopies, const char *sourceFile = nullptr, int sourceLine = 0); + std::int64_t ncopies, const char *sourceFile = nullptr, int sourceLine = 0); void RTNAME(Trim)(Descriptor &result, const Descriptor &string, const char *sourceFile = nullptr, int sourceLine = 0); Index: flang/runtime/character.cpp =================================================================== --- flang/runtime/character.cpp +++ flang/runtime/character.cpp @@ -953,8 +953,12 @@ } void RTNAME(Repeat)(Descriptor &result, const Descriptor &string, - std::size_t ncopies, const char *sourceFile, int sourceLine) { + std::int64_t ncopies, const char *sourceFile, int sourceLine) { Terminator terminator{sourceFile, sourceLine}; + if (ncopies < 0) { + terminator.Crash( + "REPEAT has negative NCOPIES=%jd", static_cast(ncopies)); + } std::size_t origBytes{string.ElementBytes()}; result.Establish(string.type(), origBytes * ncopies, nullptr, 0, nullptr, CFI_attribute_allocatable);