diff --git a/flang/runtime/tools.cpp b/flang/runtime/tools.cpp --- a/flang/runtime/tools.cpp +++ b/flang/runtime/tools.cpp @@ -98,7 +98,7 @@ if (xExtent != toExtent) { terminator.Crash("Incompatible array arguments to %s: dimension %d of " "%s has extent %" PRId64 " but %s has extent %" PRId64, - funcName, j, toName, toExtent, xName, xExtent); + funcName, j + 1, toName, toExtent, xName, xExtent); } } } diff --git a/flang/unittests/Runtime/RuntimeCrashTest.cpp b/flang/unittests/Runtime/RuntimeCrashTest.cpp --- a/flang/unittests/Runtime/RuntimeCrashTest.cpp +++ b/flang/unittests/Runtime/RuntimeCrashTest.cpp @@ -11,12 +11,15 @@ // //===----------------------------------------------------------------------===// #include "CrashHandlerFixture.h" +#include "tools.h" #include "../../runtime/terminator.h" #include "flang/Runtime/io-api.h" +#include "flang/Runtime/transformational.h" #include using namespace Fortran::runtime; using namespace Fortran::runtime::io; +using Fortran::common::TypeCategory; //------------------------------------------------------------------------------ /// Test crashes through direct calls to terminator methods @@ -155,3 +158,23 @@ ASSERT_DEATH(IONAME(OutputInteger64)(cookie, 0xdeadbeef), "Internal write overran available records"); } + +//------------------------------------------------------------------------------ +/// Test conformity issue reports in transformational intrinsics +//------------------------------------------------------------------------------ +struct TestIntrinsicCrash : CrashHandlerFixture {}; + +TEST(TestIntrinsicCrash, ConformityErrors) { + // ARRAY(2,3) and MASK(2,4) should trigger a runtime error. + auto array{MakeArray( + std::vector{2, 3}, std::vector{1, 2, 3, 4, 5, 6})}; + auto mask{MakeArray(std::vector{2, 4}, + std::vector{ + false, true, true, false, false, true, true, true})}; + StaticDescriptor<1, true> statDesc; + Descriptor &result{statDesc.descriptor()}; + + ASSERT_DEATH(RTNAME(Pack)(result, *array, *mask, nullptr, __FILE__, __LINE__), + "Incompatible array arguments to PACK: dimension 2 of ARRAY= has extent " + "3 but MASK= has extent 4"); +}