As found/reported by Thomas, the redefinition of dummy arguments with the
VALUE attribute was erroneously rejected for pure procedures. A related
purity check did not take VALUE into account and was therefore adjusted.
Regtested on x86_64-pc-linux-gnu.
OK for master?
Thanks,
Harald
PR fortran/97491 - Wrong restriction for VALUE arguments of pure procedures
A dummy argument with the VALUE attribute may be redefined in a PURE or
ELEMENTAL procedure. Adjust the associated purity check.
gcc/fortran/ChangeLog:
* resolve.c (gfc_impure_variable): A dummy argument with the VALUE
attribute may be redefined without making a procedure impure.
gcc/testsuite/ChangeLog:
* gfortran.dg/value_8.f90: New test.
diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c
index a210f9aad43..096108f4317 100644
--- a/gcc/fortran/resolve.c
+++ b/gcc/fortran/resolve.c
@@ -16476,6 +16507,7 @@ gfc_impure_variable (gfc_symbol *sym)
proc = sym->ns->proc_name;
if (sym->attr.dummy
+ && !sym->attr.value
&& ((proc->attr.subroutine && sym->attr.intent == INTENT_IN)
|| proc->attr.function))
return 1;
diff --git a/gcc/testsuite/gfortran.dg/value_8.f90 b/gcc/testsuite/gfortran.dg/value_8.f90
new file mode 100644
index 00000000000..8273fe88b60
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/value_8.f90
@@ -0,0 +1,16 @@
+! { dg-do compile }
+! PR97491 - Wrong restriction for VALUE arguments of pure procedures
+
+pure function foo (x) result (ret)
+ integer :: ret
+ integer, value :: x
+ x = x / 2
+ ret = x
+end function foo
+
+elemental function foo1 (x)
+ integer :: foo1
+ integer, value :: x
+ x = x / 2
+ foo1 = x
+end function foo1