[flang-commits] [flang] [flang] Recognize IARGC and GETARG as aliases for F2003 intrinsics (PR #173973)
via flang-commits
flang-commits at lists.llvm.org
Tue Dec 30 02:22:40 PST 2025
https://github.com/Vinayak-RZ created https://github.com/llvm/llvm-project/pull/173973
This patch fixes a semantic issue where the GNU Fortran compatibility
intrinsics IARGC and GETARG were not recognized under IMPLICIT NONE,
despite being available in the Flang runtime.
The change registers both names as aliases for their Fortran 2003
standard equivalents, restoring compatibility with legacy code
without changing lowering or runtime behavior.
Fixes #158438.
>From cc6136b6de5f2e97652534068cd7ff9cc3bd972e Mon Sep 17 00:00:00 2001
From: Vinayak-RZ <vinayakraizada at gmail.com>
Date: Tue, 30 Dec 2025 15:30:44 +0530
Subject: [PATCH] [flang] Recognize IARGC and GETARG as aliases for F2003
intrinsics
IARGC() and GETARG() are GNU Fortran 77 compatibility intrinsics that
are implemented in the Flang runtime but were not recognized by the
semantic analyzer. As a result, their use with IMPLICIT NONE caused
errors.
This change registers IARGC and GETARG as aliases for their Fortran
2003 standard equivalents:
- IARGC() -> COMMAND_ARGUMENT_COUNT()
- GETARG() -> GET_COMMAND_ARGUMENT()
This restores compatibility with legacy Fortran code without changing
runtime behavior.
Fixes #158438
---
flang/docs/Extensions.md | 3 +++
flang/lib/Evaluate/intrinsics.cpp | 2 ++
.../Semantics/intrinsic-alias-implicit-none.f90 | 17 +++++++++++++++++
3 files changed, 22 insertions(+)
create mode 100644 flang/test/Semantics/intrinsic-alias-implicit-none.f90
diff --git a/flang/docs/Extensions.md b/flang/docs/Extensions.md
index 82822d5a143d2..57c58f567aa56 100644
--- a/flang/docs/Extensions.md
+++ b/flang/docs/Extensions.md
@@ -381,6 +381,9 @@ end
* Legacy names `AND`, `OR`, and `XOR` are accepted as aliases for
the standard intrinsic functions `IAND`, `IOR`, and `IEOR`
respectively.
+* Legacy GNU intrinsics `IARGC` and `GETARG` are accepted as aliases for
+ the standard intrinsics `COMMAND_ARGUMENT_COUNT` and
+ `GET_COMMAND_ARGUMENT`, respectively.
* A digit count of d=0 is accepted in Ew.0, Dw.0, and Gw.0 output
editing if no nonzero scale factor (kP) is in effect.
* The name `IMAG` is accepted as an alias for the generic intrinsic
diff --git a/flang/lib/Evaluate/intrinsics.cpp b/flang/lib/Evaluate/intrinsics.cpp
index 72ac9e2f68758..1a66e7576d61f 100644
--- a/flang/lib/Evaluate/intrinsics.cpp
+++ b/flang/lib/Evaluate/intrinsics.cpp
@@ -1164,6 +1164,7 @@ static const IntrinsicInterface genericIntrinsicFunction[]{
// Aliases for a few generic procedures for legacy compatibility and builtins.
static const std::pair<const char *, const char *> genericAlias[]{
{"and", "iand"},
+ {"getarg", "get_command_argument"},
{"getenv", "get_environment_variable"},
{"fseek64", "fseek"},
{"fseeko64", "fseek"}, // SUN
@@ -1172,6 +1173,7 @@ static const std::pair<const char *, const char *> genericAlias[]{
{"ftello64", "ftell"}, // SUN
{"ftelli8", "ftell"}, // Intel
{"imag", "aimag"},
+ {"iargc", "command_argument_count"},
{"lshift", "shiftl"},
{"or", "ior"},
{"rshift", "shifta"},
diff --git a/flang/test/Semantics/intrinsic-alias-implicit-none.f90 b/flang/test/Semantics/intrinsic-alias-implicit-none.f90
new file mode 100644
index 0000000000000..6b73782028198
--- /dev/null
+++ b/flang/test/Semantics/intrinsic-alias-implicit-none.f90
@@ -0,0 +1,17 @@
+! RUN: %flang_fc1 -fsyntax-only %s
+!
+! Check that GNU Fortran compatibility intrinsics IARGC and GETARG
+! are recognized as intrinsic procedures under IMPLICIT NONE.
+
+program test_intrinsic_aliases
+ implicit none
+
+ integer :: n
+ character(len=100) :: arg
+
+ ! IARGC is an alias for COMMAND_ARGUMENT_COUNT
+ n = iargc()
+
+ ! GETARG is an alias for GET_COMMAND_ARGUMENT
+ call getarg(1, arg)
+end program
More information about the flang-commits
mailing list