diff --git a/flang/include/flang/Runtime/character.h b/flang/include/flang/Runtime/character.h index 441faf2c36333..24f26920bdd2c 100644 --- a/flang/include/flang/Runtime/character.h +++ b/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 @@ std::size_t RTNAME(LenTrim4)(const char32_t *, std::size_t); 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); diff --git a/flang/runtime/character.cpp b/flang/runtime/character.cpp index 2264fe6b8f62c..16f39332cc60c 100644 --- a/flang/runtime/character.cpp +++ b/flang/runtime/character.cpp @@ -953,8 +953,12 @@ void RTNAME(Scan)(Descriptor &result, const Descriptor &string, } 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);