[flang] use 1-based dim in transformational runtime error msg

Flang transformational runtime was previously reporting conformity
issues in a zero based fashion to describe which dimension is non
conformant. This may confuse Fortran user, especially when the message
is about a dimension other than the first one.

Differential Revision: https://reviews.llvm.org/D124941
This commit is contained in:
Jean Perier 2022-05-05 10:32:40 +02:00
parent cc344d262a
commit b910cf986a
2 changed files with 24 additions and 1 deletions

View File

@ -98,7 +98,7 @@ void CheckConformability(const Descriptor &to, const Descriptor &x,
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);
}
}
}

View File

@ -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 <gtest/gtest.h>
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 @@ TEST(TestIOCrash, OverwriteBufferIntegerTest) {
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<TypeCategory::Integer, 4>(
std::vector<int>{2, 3}, std::vector<std::int32_t>{1, 2, 3, 4, 5, 6})};
auto mask{MakeArray<TypeCategory::Logical, 1>(std::vector<int>{2, 4},
std::vector<std::uint8_t>{
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");
}