public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-3946] Fortran: diagnostics for actual arguments to pointer dummy arguments [PR94104]
@ 2022-11-13 20:21 Harald Anlauf
0 siblings, 0 replies; only message in thread
From: Harald Anlauf @ 2022-11-13 20:21 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:58e7732a2feddf475e72b232bf16494d84a41acf
commit r13-3946-g58e7732a2feddf475e72b232bf16494d84a41acf
Author: José Rui Faustino de Sousa <jrfsousa@gmail.com>
Date: Wed Nov 9 21:30:25 2022 +0100
Fortran: diagnostics for actual arguments to pointer dummy arguments [PR94104]
Error message improvement. In Fortran 2008 actual procedure arguments
associated with a pointer, intent(in) attribute, dummy argument
can also have the target attribute, not just pointer.
gcc/fortran/ChangeLog:
PR fortran/94104
* interface.cc (gfc_compare_actual_formal): Improve error message
dependent on Fortran standard level.
gcc/testsuite/ChangeLog:
PR fortran/94104
* gfortran.dg/parens_2.f90: Adjust to improved error message.
* gfortran.dg/PR94104a.f90: New test.
* gfortran.dg/PR94104b.f90: New test.
Diff:
---
gcc/fortran/interface.cc | 48 ++++++++++++++++++++++------------
gcc/testsuite/gfortran.dg/PR94104a.f90 | 29 ++++++++++++++++++++
gcc/testsuite/gfortran.dg/PR94104b.f90 | 29 ++++++++++++++++++++
gcc/testsuite/gfortran.dg/parens_2.f90 | 2 +-
4 files changed, 90 insertions(+), 18 deletions(-)
diff --git a/gcc/fortran/interface.cc b/gcc/fortran/interface.cc
index d3e199535b3..49dbd1d886c 100644
--- a/gcc/fortran/interface.cc
+++ b/gcc/fortran/interface.cc
@@ -3477,25 +3477,39 @@ gfc_compare_actual_formal (gfc_actual_arglist **ap, gfc_formal_arglist *formal,
goto match;
}
- if (a->expr->expr_type != EXPR_NULL
- && compare_pointer (f->sym, a->expr) == 0)
+ if (a->expr->expr_type != EXPR_NULL)
{
- if (where)
- gfc_error ("Actual argument for %qs must be a pointer at %L",
- f->sym->name, &a->expr->where);
- ok = false;
- goto match;
- }
+ int cmp = compare_pointer (f->sym, a->expr);
+ bool pre2008 = ((gfc_option.allow_std & GFC_STD_F2008) == 0);
- if (a->expr->expr_type != EXPR_NULL
- && (gfc_option.allow_std & GFC_STD_F2008) == 0
- && compare_pointer (f->sym, a->expr) == 2)
- {
- if (where)
- gfc_error ("Fortran 2008: Non-pointer actual argument at %L to "
- "pointer dummy %qs", &a->expr->where,f->sym->name);
- ok = false;
- goto match;
+ if (pre2008 && cmp == 0)
+ {
+ if (where)
+ gfc_error ("Actual argument for %qs at %L must be a pointer",
+ f->sym->name, &a->expr->where);
+ ok = false;
+ goto match;
+ }
+
+ if (pre2008 && cmp == 2)
+ {
+ if (where)
+ gfc_error ("Fortran 2008: Non-pointer actual argument at %L to "
+ "pointer dummy %qs", &a->expr->where, f->sym->name);
+ ok = false;
+ goto match;
+ }
+
+ if (!pre2008 && cmp == 0)
+ {
+ if (where)
+ gfc_error ("Actual argument for %qs at %L must be a pointer "
+ "or a valid target for the dummy pointer in a "
+ "pointer assignment statement",
+ f->sym->name, &a->expr->where);
+ ok = false;
+ goto match;
+ }
}
diff --git a/gcc/testsuite/gfortran.dg/PR94104a.f90 b/gcc/testsuite/gfortran.dg/PR94104a.f90
new file mode 100644
index 00000000000..a1e578ac9ba
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/PR94104a.f90
@@ -0,0 +1,29 @@
+! { dg-do compile }
+! { dg-options "-std=f2003" }
+!
+! PR fortran/94104
+!
+
+program diag_p
+ implicit none
+
+ integer, parameter :: n = 7
+
+ integer :: a(n)
+ integer, target :: b(n)
+
+ a = 1
+ print *, sumf(a) ! { dg-error "Actual argument for 'a' at .1. must be a pointer" }
+ print *, sumf(b) ! { dg-error "Fortran 2008: Non-pointer actual argument at .1. to pointer dummy 'a'" }
+
+contains
+
+ function sumf(a) result(s)
+ integer, pointer, intent(in) :: a(:)
+
+ integer :: s
+
+ s = sum(a)
+ end function sumf
+
+end program diag_p
diff --git a/gcc/testsuite/gfortran.dg/PR94104b.f90 b/gcc/testsuite/gfortran.dg/PR94104b.f90
new file mode 100644
index 00000000000..ee7d640b926
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/PR94104b.f90
@@ -0,0 +1,29 @@
+! { dg-do compile }
+! { dg-options "-std=f2008" }
+!
+! PR fortran/94104
+!
+
+program diag_p
+ implicit none
+
+ integer, parameter :: n = 7
+
+ integer :: a(n)
+ integer, target :: b(n)
+
+ a = 1
+ print *, sumf(a) ! { dg-error "Actual argument for 'a' at .1. must be a pointer or a valid target" }
+ print *, sumf(b)
+
+contains
+
+ function sumf(a) result(s)
+ integer, pointer, intent(in) :: a(:)
+
+ integer :: s
+
+ s = sum(a)
+ end function sumf
+
+end program diag_p
diff --git a/gcc/testsuite/gfortran.dg/parens_2.f90 b/gcc/testsuite/gfortran.dg/parens_2.f90
index bc2acd8e71d..dc5965de014 100644
--- a/gcc/testsuite/gfortran.dg/parens_2.f90
+++ b/gcc/testsuite/gfortran.dg/parens_2.f90
@@ -2,7 +2,7 @@
! { dg-do compile }
! Originally contributed by Joost VandeVondele
INTEGER, POINTER :: I
-CALL S1((I)) ! { dg-error "Actual argument for .i. must be a pointer" }
+CALL S1((I)) ! { dg-error "Actual argument for .i. at .1. must be a pointer or a valid target" }
CONTAINS
SUBROUTINE S1(I)
INTEGER, POINTER ::I
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-11-13 20:21 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-13 20:21 [gcc r13-3946] Fortran: diagnostics for actual arguments to pointer dummy arguments [PR94104] Harald Anlauf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).