[flang-commits] [PATCH] D130380: [flang] Better error message for NULL() actual argument for dummy allocatable

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Mon Jul 25 10:10:12 PDT 2022


This revision was automatically updated to reflect the committed changes.
Closed by commit rG85a40ce6ddf6: [flang] Better error message for NULL() actual argument for dummy allocatable (authored by klausler).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130380/new/

https://reviews.llvm.org/D130380

Files:
  flang/docs/Extensions.md
  flang/lib/Semantics/check-call.cpp
  flang/test/Semantics/call27.f90


Index: flang/test/Semantics/call27.f90
===================================================================
--- /dev/null
+++ flang/test/Semantics/call27.f90
@@ -0,0 +1,19 @@
+! RUN: %python %S/test_errors.py %s %flang_fc1
+! Catch NULL() actual argement association with allocatable dummy argument
+program test
+  !ERROR: Null actual argument 'NULL()' may not be associated with allocatable dummy argument 'a='
+  call foo1(null())
+  !ERROR: Null actual argument 'NULL()' may not be associated with allocatable dummy argument 'a='
+  call foo2(null()) ! perhaps permissible later on user request
+  call foo3(null()) ! ok
+ contains
+  subroutine foo1(a)
+    real, allocatable :: a
+  end subroutine
+  subroutine foo2(a)
+    real, allocatable, intent(in) :: a
+  end subroutine
+  subroutine foo3(a)
+    real, allocatable, optional :: a
+  end subroutine
+end
Index: flang/lib/Semantics/check-call.cpp
===================================================================
--- flang/lib/Semantics/check-call.cpp
+++ flang/lib/Semantics/check-call.cpp
@@ -740,6 +740,15 @@
                                        DummyDataObject::Attr::Optional)) &&
                     evaluate::IsNullPointer(*expr)) {
                   // ok, FOO(NULL())
+                } else if (object.attrs.test(characteristics::DummyDataObject::
+                                   Attr::Allocatable) &&
+                    evaluate::IsNullPointer(*expr)) {
+                  // Unsupported extension that more or less naturally falls
+                  // out of other Fortran implementations that pass separate
+                  // base address and descriptor address physical arguments
+                  messages.Say(
+                      "Null actual argument '%s' may not be associated with allocatable %s"_err_en_US,
+                      expr->AsFortran(), dummyName);
                 } else {
                   messages.Say(
                       "Actual argument '%s' associated with %s is not a variable or typed expression"_err_en_US,
Index: flang/docs/Extensions.md
===================================================================
--- flang/docs/Extensions.md
+++ flang/docs/Extensions.md
@@ -308,6 +308,7 @@
   PGI converts the arguments while Intel and XLF replace the specific by the related generic.
 * VMS listing control directives (`%LIST`, `%NOLIST`, `%EJECT`)
 * Continuation lines on `INCLUDE` lines
+* `NULL()` actual argument corresponding to an `ALLOCATABLE` dummy data object
 
 ## Preprocessing behavior
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D130380.447394.patch
Type: text/x-patch
Size: 2526 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20220725/e6f08875/attachment-0001.bin>


More information about the flang-commits mailing list