[flang-commits] [flang] 9c87746 - [flang] emit warning when encountering a non-variable actual argument when its corresponding dummy argument expects a VOLATILE variable

via flang-commits flang-commits at lists.llvm.org
Tue Dec 13 12:28:30 PST 2022


Author: Cabrera, Anthony
Date: 2022-12-13T15:28:15-05:00
New Revision: 9c87746de7cdbb2b60a3fc274831aee43ddd9b7c

URL: https://github.com/llvm/llvm-project/commit/9c87746de7cdbb2b60a3fc274831aee43ddd9b7c
DIFF: https://github.com/llvm/llvm-project/commit/9c87746de7cdbb2b60a3fc274831aee43ddd9b7c.diff

LOG: [flang] emit warning when encountering a non-variable actual argument when its corresponding dummy argument expects a VOLATILE variable

This patch implements @klausler's suggestion in `llvm-project` [issue #58973](https://github.com/llvm/llvm-project/issues/58973); encountering the `VOLATILE` attribute should produce a __warning__, not a __fatal error__.

When tested on the following Fortran program `snem0601_012_.f90`:
```fortran
  module mod
    contains
    subroutine sub(m6,error)
    integer,intent(inout) :: error

    integer,volatile :: m6

    if (any ((/m6/).ne.(/6/))) &
   & then
       error = 1
    end if
    end subroutine
  end module

  program fe1nvol12

    use mod
    integer :: error = 0

    call sub(6,error)

    if (error .ne. 0) then
      print *,'NG: snem0601_012'
    end if

    print *,'pass: snem0601_012'

  end program fe1nvol12
```

the following output is produced:

```bash
$ flang-new -fc1 snem0601_012_.f90
/noback/93u/Sandbox/issue_58973_volatile_dummy_arg/snem0601_012_.f90:21:12: warning: actual argument associated with VOLATILE dummy argument 'm6=' is not a variable
    call sub(6,error)
             ^
```

Reviewed By: clementval, klausler

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

Added: 
    flang/test/Semantics/call30.f90

Modified: 
    flang/lib/Semantics/check-call.cpp

Removed: 
    


################################################################################
diff  --git a/flang/lib/Semantics/check-call.cpp b/flang/lib/Semantics/check-call.cpp
index f151dfaa7477e..76cb96ced3f4a 100644
--- a/flang/lib/Semantics/check-call.cpp
+++ b/flang/lib/Semantics/check-call.cpp
@@ -417,6 +417,15 @@ static void CheckExplicitDataArg(const characteristics::DummyDataObject &dummy,
     }
   }
 
+  // technically legal but worth emitting a warning
+  // llvm-project issue #58973: constant actual argument passed in where dummy
+  // argument is marked volatile
+  if (dummyIsVolatile && !IsVariable(actual)) {
+    messages.Say(
+        "actual argument associated with VOLATILE %s is not a variable"_warn_en_US,
+        dummyName);
+  }
+
   // Cases when temporaries might be needed but must not be permitted.
   bool actualIsContiguous{IsSimplyContiguous(actual, context)};
   bool dummyIsAssumedShape{dummy.type.attrs().test(

diff  --git a/flang/test/Semantics/call30.f90 b/flang/test/Semantics/call30.f90
new file mode 100644
index 0000000000000..f6725cdafcd1a
--- /dev/null
+++ b/flang/test/Semantics/call30.f90
@@ -0,0 +1,60 @@
+! RUN: %python %S/test_errors.py %s %flang_fc1 -Werror
+! This test is responsible for checking the fix for passing non-variables as 
+! actual arguments to subroutines/functions whose corresponding dummy argument
+! expects a VOLATILE variable
+! c.f. llvm-project GitHub issue #58973
+
+module m
+  contains
+  subroutine vol_dum_int(my_int)
+    integer, volatile :: my_int
+  end subroutine vol_dum_int
+
+  subroutine vol_dum_real(my_real)
+    real, volatile :: my_real
+  end subroutine vol_dum_real
+
+  subroutine vol_dum_complex(my_complex)
+    complex, volatile :: my_complex
+  end subroutine vol_dum_complex
+
+  subroutine vol_dum_int_arr(my_int_arr)
+    integer, dimension(2,2), volatile :: my_int_arr
+  end subroutine vol_dum_int_arr
+
+  subroutine test_all_subprograms()
+    !WARNING: actual argument associated with VOLATILE dummy argument 'my_int=' is not a variable
+    call vol_dum_int(6)
+		!WARNING: actual argument associated with VOLATILE dummy argument 'my_int=' is not a variable
+    call vol_dum_int(6+12)
+		!WARNING: actual argument associated with VOLATILE dummy argument 'my_int=' is not a variable
+    call vol_dum_int(6*12)
+		!WARNING: actual argument associated with VOLATILE dummy argument 'my_int=' is not a variable
+    call vol_dum_int(-6/2)
+
+		!WARNING: actual argument associated with VOLATILE dummy argument 'my_real=' is not a variable
+    call vol_dum_real(3.141592653)
+		!WARNING: actual argument associated with VOLATILE dummy argument 'my_real=' is not a variable
+    call vol_dum_real(3.141592653 + -10.6e-11)
+		!WARNING: actual argument associated with VOLATILE dummy argument 'my_real=' is not a variable
+    call vol_dum_real(3.141592653 * 10.6e-11)
+		!WARNING: actual argument associated with VOLATILE dummy argument 'my_real=' is not a variable
+    call vol_dum_real(3.141592653 / -10.6e-11)
+
+		!WARNING: actual argument associated with VOLATILE dummy argument 'my_complex=' is not a variable
+    call vol_dum_complex((1., 3.2))
+		!WARNING: actual argument associated with VOLATILE dummy argument 'my_complex=' is not a variable
+    call vol_dum_complex((1., 3.2) + (-2., 3.14))
+		!WARNING: actual argument associated with VOLATILE dummy argument 'my_complex=' is not a variable
+    call vol_dum_complex((1., 3.2) * (-2., 3.14))
+		!WARNING: actual argument associated with VOLATILE dummy argument 'my_complex=' is not a variable
+    call vol_dum_complex((1., 3.2) / (-2., 3.14))
+
+		!WARNING: actual argument associated with VOLATILE dummy argument 'my_int_arr=' is not a variable
+    call vol_dum_int_arr((/ 1, 2, 3, 4 /))
+		!WARNING: actual argument associated with VOLATILE dummy argument 'my_int_arr=' is not a variable
+    call vol_dum_int_arr(reshape((/ 1, 2, 3, 4 /), (/ 2, 2/)))
+		!WARNING: actual argument associated with VOLATILE dummy argument 'my_int_arr=' is not a variable
+  	call vol_dum_int_arr((/ 1, 2, 3, 4 /))
+  end subroutine test_all_subprograms
+end module m


        


More information about the flang-commits mailing list