[flang-commits] [flang] 2526013 - [flang] Improve error message for move_alloc

David Truby via flang-commits flang-commits at lists.llvm.org
Tue Jan 31 06:59:11 PST 2023


Author: David Truby
Date: 2023-01-31T14:59:02Z
New Revision: 2526013a2266f6eb3ffa743895f84705727aef0d

URL: https://github.com/llvm/llvm-project/commit/2526013a2266f6eb3ffa743895f84705727aef0d
DIFF: https://github.com/llvm/llvm-project/commit/2526013a2266f6eb3ffa743895f84705727aef0d.diff

LOG: [flang] Improve error message for move_alloc

This patch improves the error message when MOVE_ALLOC is passed the same
allocated allocatable as both the to and from arguments.

Differential Revision: https://reviews.llvm.org/D142899

Added: 
    

Modified: 
    flang/include/flang/Runtime/magic-numbers.h
    flang/runtime/allocatable.cpp
    flang/runtime/stat.cpp
    flang/runtime/stat.h
    flang/unittests/Runtime/Allocatable.cpp

Removed: 
    


################################################################################
diff  --git a/flang/include/flang/Runtime/magic-numbers.h b/flang/include/flang/Runtime/magic-numbers.h
index e883637b8c4b8..4ee1fca539bd2 100644
--- a/flang/include/flang/Runtime/magic-numbers.h
+++ b/flang/include/flang/Runtime/magic-numbers.h
@@ -52,4 +52,11 @@ Status codes for GET_ENVIRONMENT_VARIABLE. Values mandated by the standard.
 #endif
 #define FORTRAN_RUNTIME_STAT_MISSING_ENV_VAR 1
 #define FORTRAN_RUNTIME_STAT_ENV_VARS_UNSUPPORTED 2
+
+#if 0
+Processor-defined status code for MOVE_ALLOC where arguments are the
+same allocatable.
+#endif
+#define FORTRAN_RUNTIME_STAT_MOVE_ALLOC_SAME_ALLOCATABLE 109
+
 #endif

diff  --git a/flang/runtime/allocatable.cpp b/flang/runtime/allocatable.cpp
index 2e7e0e9acacf8..3ec9bdaf63beb 100644
--- a/flang/runtime/allocatable.cpp
+++ b/flang/runtime/allocatable.cpp
@@ -51,7 +51,8 @@ std::int32_t RTNAME(MoveAlloc)(Descriptor &to, Descriptor &from, bool hasStat,
   // If to and from are the same allocatable they must not be allocated
   // and nothing should be done.
   if (from.raw().base_addr == to.raw().base_addr && from.IsAllocated()) {
-    return ReturnError(terminator, StatInvalidDescriptor, errMsg, hasStat);
+    return ReturnError(
+        terminator, StatMoveAllocSameAllocatable, errMsg, hasStat);
   }
 
   if (to.IsAllocated()) {

diff  --git a/flang/runtime/stat.cpp b/flang/runtime/stat.cpp
index 3ddcb2ba7c8d3..63284bbea7f23 100644
--- a/flang/runtime/stat.cpp
+++ b/flang/runtime/stat.cpp
@@ -60,6 +60,9 @@ const char *StatErrorString(int stat) {
   case StatMissingEnvVariable:
     return "Missing environment variable";
 
+  case StatMoveAllocSameAllocatable:
+    return "MOVE_ALLOC passed the same address as to and from";
+
   default:
     return nullptr;
   }

diff  --git a/flang/runtime/stat.h b/flang/runtime/stat.h
index a030784090746..e5b49d625912d 100644
--- a/flang/runtime/stat.h
+++ b/flang/runtime/stat.h
@@ -48,6 +48,8 @@ enum Stat {
   StatInvalidArgumentNumber = FORTRAN_RUNTIME_STAT_INVALID_ARG_NUMBER,
   StatMissingArgument = FORTRAN_RUNTIME_STAT_MISSING_ARG,
   StatValueTooShort = FORTRAN_RUNTIME_STAT_VALUE_TOO_SHORT,
+  StatMoveAllocSameAllocatable =
+      FORTRAN_RUNTIME_STAT_MOVE_ALLOC_SAME_ALLOCATABLE,
 };
 
 const char *StatErrorString(int);

diff  --git a/flang/unittests/Runtime/Allocatable.cpp b/flang/unittests/Runtime/Allocatable.cpp
index 919279a245f17..11cb2f2db33e8 100644
--- a/flang/unittests/Runtime/Allocatable.cpp
+++ b/flang/unittests/Runtime/Allocatable.cpp
@@ -64,10 +64,10 @@ TEST(AllocatableTest, MoveAlloc) {
 
   // move_alloc with the same allocated array should fail
   stat = RTNAME(MoveAlloc)(*a, *a, true, errMsg.get(), __FILE__, __LINE__);
-  EXPECT_EQ(stat, 18);
+  EXPECT_EQ(stat, 109);
   std::string_view errStr{errMsg->OffsetElement(), errMsg->ElementBytes()};
   auto trim_pos = errStr.find_last_not_of(' ');
   if (trim_pos != errStr.npos)
     errStr.remove_suffix(errStr.size() - trim_pos - 1);
-  EXPECT_EQ(errStr, "Invalid descriptor");
+  EXPECT_EQ(errStr, "MOVE_ALLOC passed the same address as to and from");
 }


        


More information about the flang-commits mailing list