[flang-commits] [flang] [flang] Add support for the IARGC and GETARG legacy intrinsics (PR #196425)

via flang-commits flang-commits at lists.llvm.org
Sun May 10 15:58:17 PDT 2026


================
@@ -0,0 +1,43 @@
+! RUN: %python %S/test_errors.py %s %flang_fc1
+subroutine iargc_test
+  implicit none
+  integer :: n
+  integer(4) :: i4
+  character(32) :: value
+  !OK:
+  i4 = iargc()
+  !ERROR: Cannot call function 'iargc' like a subroutine
+  call iargc()
+end subroutine iargc_test
+
+subroutine getarg_test_1
+  implicit none
+  integer :: n
+  character(32) :: value
+  !OK:
+  call getarg(n, value)
+  !ERROR: Cannot call subroutine 'getarg' like a function
+  n = getarg(1, value)
+end subroutine getarg_test_1
+
+subroutine getarg_test_2
+  implicit none
+  integer :: n
+  character(32) :: value
+  !ERROR: No explicit type declared for 'getarg'
----------------
Tuhil926 wrote:

I see two different  errors in gfortran as well:

* For the first one, where there's a proper call to the subroutine before erroneously calling it as a function, gfortran gives the error:
```
test-iargc-getarg.f90:20:13:

   20 |   n = getarg(1, value)
      |             1
Error: Unexpected use of subroutine name ‘getarg’ at (1)
```

* For the second one, with just the erroneous call as a function, gfortran gives:
```
test-iargc-getarg.f90:28:6:

   28 |   n = getarg(1, value)
      |      1
Error: Function ‘getarg’ at (1) has no IMPLICIT type
```

Both of these seem to be similar to the errors given by flang.

The reason for the difference seems to be that if there is a prior successful subroutine call, flang correctly identifies the erroneous call as a misuse of the subroutine, but if this was the first time it encountered this symbol, it checks if it was explicitly declared as a function, and not finding one, it gives that error. 

https://github.com/llvm/llvm-project/pull/196425


More information about the flang-commits mailing list