Skip to content

Commit b910cf9

Browse files
committed
[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
1 parent cc344d2 commit b910cf9

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

flang/runtime/tools.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ void CheckConformability(const Descriptor &to, const Descriptor &x,
9898
if (xExtent != toExtent) {
9999
terminator.Crash("Incompatible array arguments to %s: dimension %d of "
100100
"%s has extent %" PRId64 " but %s has extent %" PRId64,
101-
funcName, j, toName, toExtent, xName, xExtent);
101+
funcName, j + 1, toName, toExtent, xName, xExtent);
102102
}
103103
}
104104
}

flang/unittests/Runtime/RuntimeCrashTest.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,15 @@
1111
//
1212
//===----------------------------------------------------------------------===//
1313
#include "CrashHandlerFixture.h"
14+
#include "tools.h"
1415
#include "../../runtime/terminator.h"
1516
#include "flang/Runtime/io-api.h"
17+
#include "flang/Runtime/transformational.h"
1618
#include <gtest/gtest.h>
1719

1820
using namespace Fortran::runtime;
1921
using namespace Fortran::runtime::io;
22+
using Fortran::common::TypeCategory;
2023

2124
//------------------------------------------------------------------------------
2225
/// Test crashes through direct calls to terminator methods
@@ -155,3 +158,23 @@ TEST(TestIOCrash, OverwriteBufferIntegerTest) {
155158
ASSERT_DEATH(IONAME(OutputInteger64)(cookie, 0xdeadbeef),
156159
"Internal write overran available records");
157160
}
161+
162+
//------------------------------------------------------------------------------
163+
/// Test conformity issue reports in transformational intrinsics
164+
//------------------------------------------------------------------------------
165+
struct TestIntrinsicCrash : CrashHandlerFixture {};
166+
167+
TEST(TestIntrinsicCrash, ConformityErrors) {
168+
// ARRAY(2,3) and MASK(2,4) should trigger a runtime error.
169+
auto array{MakeArray<TypeCategory::Integer, 4>(
170+
std::vector<int>{2, 3}, std::vector<std::int32_t>{1, 2, 3, 4, 5, 6})};
171+
auto mask{MakeArray<TypeCategory::Logical, 1>(std::vector<int>{2, 4},
172+
std::vector<std::uint8_t>{
173+
false, true, true, false, false, true, true, true})};
174+
StaticDescriptor<1, true> statDesc;
175+
Descriptor &result{statDesc.descriptor()};
176+
177+
ASSERT_DEATH(RTNAME(Pack)(result, *array, *mask, nullptr, __FILE__, __LINE__),
178+
"Incompatible array arguments to PACK: dimension 2 of ARRAY= has extent "
179+
"3 but MASK= has extent 4");
180+
}

0 commit comments

Comments
 (0)