Fortran : ProcPtr function results: 'ppr@' in error message PR39695

Message ID 9b4bfd4c-ba81-98ff-6ed8-16252a5fb57b@codethink.co.uk
State New
Headers show
Series
  • Fortran : ProcPtr function results: 'ppr@' in error message PR39695
Related show

Commit Message

Mark Eggleston May 18, 2020, 7:35 a.m.
Please find attached a patch for PR39695 (this time it is attached).

Commit message:

Fortran  : ProcPtr function results: 'ppr@' in error message PR39695

The value 'ppr@' is set in the name of result symbol, the actual
name of the symbol is in the procedure name symbol pointed
to by the result symbol's namespace (ns). When reporting errors for
symbols that have the proc_pointer attribute check whether the
result attribute is set and set the name accordingly.

2020-05-18  Mark Eggleston <markeggleston@gcc.gnu.org>

gcc/fortran/

     PR fortran/39695
     * resolve.c (resolve_fl_procedure): Set name depending on
     whether the result attribute is set.  For PROCEDURE/RESULT
     conflict use the name in sym->ns->proc_name->name.
     * symbol.c (gfc_add_type): Add check for function and result
     attributes use sym->ns->proc_name->name if both are set.
     Where the symbol cannot have a type use the name in
     sym->ns->proc_name->name.

2020-05-18  Mark Eggleston <markeggleston@gcc.gnu.org>

gcc/testsuite/

     PR fortran/39695
     * gfortran.dg/pr39695_1.f90: New test.
     * gfortran.dg/pr39695_2.f90: New test.
     * gfortran.dg/pr39695_3.f90: New test.
     * gfortran.dg/pr39695_4.f90: New test.

Tested on x86_64 using make check-fortran for master, gcc-8, gcc-9 and 
gcc-10.

OK to to commit and backport?

-- 
https://www.codethink.co.uk/privacy.html

Comments

Manfred Schwarb May 19, 2020, 8:08 a.m. | #1
Am 18.05.20 um 09:35 schrieb Mark Eggleston:
> Please find attached a patch for PR39695 (this time it is attached).

>

> Commit message:

>

> Fortran  : ProcPtr function results: 'ppr@' in error message PR39695

>

> The value 'ppr@' is set in the name of result symbol, the actual

> name of the symbol is in the procedure name symbol pointed

> to by the result symbol's namespace (ns). When reporting errors for

> symbols that have the proc_pointer attribute check whether the

> result attribute is set and set the name accordingly.

>

> 2020-05-18  Mark Eggleston <markeggleston@gcc.gnu.org>

>

> gcc/fortran/

>

>     PR fortran/39695

>     * resolve.c (resolve_fl_procedure): Set name depending on

>     whether the result attribute is set.  For PROCEDURE/RESULT

>     conflict use the name in sym->ns->proc_name->name.

>     * symbol.c (gfc_add_type): Add check for function and result

>     attributes use sym->ns->proc_name->name if both are set.

>     Where the symbol cannot have a type use the name in

>     sym->ns->proc_name->name.

>

> 2020-05-18  Mark Eggleston <markeggleston@gcc.gnu.org>

>

> gcc/testsuite/

>

>     PR fortran/39695

>     * gfortran.dg/pr39695_1.f90: New test.

>     * gfortran.dg/pr39695_2.f90: New test.

>     * gfortran.dg/pr39695_3.f90: New test.

>     * gfortran.dg/pr39695_4.f90: New test.

>

> Tested on x86_64 using make check-fortran for master, gcc-8, gcc-9 and gcc-10.

>

> OK to to commit and backport?

>



--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr39695_1.f90
@@ -0,0 +1,8 @@
+! { dg-compile }
+!
etc. etc.

It should read { dg-do compile }
Mark Eggleston May 19, 2020, 9:13 a.m. | #2
On 19/05/2020 09:08, Manfred Schwarb wrote:
> Am 18.05.20 um 09:35 schrieb Mark Eggleston:

>> Please find attached a patch for PR39695 (this time it is attached).

>>

>> Commit message:

>>

>> Fortran  : ProcPtr function results: 'ppr@' in error message PR39695

>>

>> The value 'ppr@' is set in the name of result symbol, the actual

>> name of the symbol is in the procedure name symbol pointed

>> to by the result symbol's namespace (ns). When reporting errors for

>> symbols that have the proc_pointer attribute check whether the

>> result attribute is set and set the name accordingly.

>>

>> 2020-05-18  Mark Eggleston <markeggleston@gcc.gnu.org>

>>

>> gcc/fortran/

>>

>>      PR fortran/39695

>>      * resolve.c (resolve_fl_procedure): Set name depending on

>>      whether the result attribute is set.  For PROCEDURE/RESULT

>>      conflict use the name in sym->ns->proc_name->name.

>>      * symbol.c (gfc_add_type): Add check for function and result

>>      attributes use sym->ns->proc_name->name if both are set.

>>      Where the symbol cannot have a type use the name in

>>      sym->ns->proc_name->name.

>>

>> 2020-05-18  Mark Eggleston <markeggleston@gcc.gnu.org>

>>

>> gcc/testsuite/

>>

>>      PR fortran/39695

>>      * gfortran.dg/pr39695_1.f90: New test.

>>      * gfortran.dg/pr39695_2.f90: New test.

>>      * gfortran.dg/pr39695_3.f90: New test.

>>      * gfortran.dg/pr39695_4.f90: New test.

>>

>> Tested on x86_64 using make check-fortran for master, gcc-8, gcc-9 and gcc-10.

>>

>> OK to to commit and backport?

>>

>

> --- /dev/null

> +++ b/gcc/testsuite/gfortran.dg/pr39695_1.f90

> @@ -0,0 +1,8 @@

> +! { dg-compile }

> +!

> etc. etc.

>

> It should read { dg-do compile }

Fixed.

-- 
https://www.codethink.co.uk/privacy.html
Tobias Burnus May 19, 2020, 1 p.m. | #3
Hi Mark,

On 5/18/20 9:35 AM, Mark Eggleston wrote:
> Please find attached a patch for PR39695 (this time it is attached).


Looks okay – with the "dg-(do )compile" change as remarked by Manfred.

[I did wonder whether BLOCK could cause problems with ns->proc_name, but
I couldn't come up with a case where one could have both a
function-return value issue and block.]

Thanks,

Tobias

>

> Commit message:

>

> Fortran  : ProcPtr function results: 'ppr@' in error message PR39695

>

> The value 'ppr@' is set in the name of result symbol, the actual

> name of the symbol is in the procedure name symbol pointed

> to by the result symbol's namespace (ns). When reporting errors for

> symbols that have the proc_pointer attribute check whether the

> result attribute is set and set the name accordingly.

>

> 2020-05-18  Mark Eggleston <markeggleston@gcc.gnu.org>

>

> gcc/fortran/

>

>     PR fortran/39695

>     * resolve.c (resolve_fl_procedure): Set name depending on

>     whether the result attribute is set.  For PROCEDURE/RESULT

>     conflict use the name in sym->ns->proc_name->name.

>     * symbol.c (gfc_add_type): Add check for function and result

>     attributes use sym->ns->proc_name->name if both are set.

>     Where the symbol cannot have a type use the name in

>     sym->ns->proc_name->name.

>

> 2020-05-18  Mark Eggleston <markeggleston@gcc.gnu.org>

>

> gcc/testsuite/

>

>     PR fortran/39695

>     * gfortran.dg/pr39695_1.f90: New test.

>     * gfortran.dg/pr39695_2.f90: New test.

>     * gfortran.dg/pr39695_3.f90: New test.

>     * gfortran.dg/pr39695_4.f90: New test.

>

> Tested on x86_64 using make check-fortran for master, gcc-8, gcc-9 and

> gcc-10.

>

> OK to to commit and backport?

>

-----------------
Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / Germany
Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Alexander Walter

Patch

From 8b4e6cb6d72b7c40aa87ca3bbdb1e2bbb7c5a23e Mon Sep 17 00:00:00 2001
From: Mark Eggleston <markeggleston@gcc.gnu.org>
Date: Thu, 7 May 2020 08:02:02 +0100
Subject: [PATCH] Fortran  : ProcPtr function results: 'ppr@' in error message
 PR39695

The value 'ppr@' is set in the name of result symbol, the actual
name of the symbol is in the procedure name symbol pointed
to by the result symbol's namespace (ns). When reporting errors for
symbols that have the proc_pointer attribute check whether the
result attribute is set and set the name accordingly.

2020-05-18  Mark Eggleston  <markeggleston@gcc.gnu.org>

gcc/fortran/

	PR fortran/39695
	* resolve.c (resolve_fl_procedure): Set name depending on
	whether the result attribute is set.  For PROCEDURE/RESULT
	conflict use the name in sym->ns->proc_name->name.
	* symbol.c (gfc_add_type): Add check for function and result
	attributes use sym->ns->proc_name->name if both are set.
	Where the symbol cannot have a type use the name in
	sym->ns->proc_name->name.

2020-05-18  Mark Eggleston  <markeggleston@gcc.gnu.org>

gcc/testsuite/

	PR fortran/39695
	* gfortran.dg/pr39695_1.f90: New test.
	* gfortran.dg/pr39695_2.f90: New test.
	* gfortran.dg/pr39695_3.f90: New test.
	* gfortran.dg/pr39695_4.f90: New test.
---
 gcc/fortran/resolve.c                   |  6 ++++--
 gcc/fortran/symbol.c                    |  7 +++++--
 gcc/testsuite/gfortran.dg/pr39695_1.f90 |  8 ++++++++
 gcc/testsuite/gfortran.dg/pr39695_2.f90 | 12 ++++++++++++
 gcc/testsuite/gfortran.dg/pr39695_3.f90 | 11 +++++++++++
 gcc/testsuite/gfortran.dg/pr39695_4.f90 | 14 ++++++++++++++
 6 files changed, 54 insertions(+), 4 deletions(-)
 create mode 100644 gcc/testsuite/gfortran.dg/pr39695_1.f90
 create mode 100644 gcc/testsuite/gfortran.dg/pr39695_2.f90
 create mode 100644 gcc/testsuite/gfortran.dg/pr39695_3.f90
 create mode 100644 gcc/testsuite/gfortran.dg/pr39695_4.f90

diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c
index fd3b025a84f..bcd89efdc16 100644
--- a/gcc/fortran/resolve.c
+++ b/gcc/fortran/resolve.c
@@ -13123,8 +13123,10 @@  resolve_fl_procedure (gfc_symbol *sym, int mp_flag)
     {
       if (sym->attr.proc_pointer)
 	{
+	  const char* name = (sym->attr.result ? sym->ns->proc_name->name
+					       : sym->name);
 	  gfc_error ("Procedure pointer %qs at %L shall not be elemental",
-		     sym->name, &sym->declared_at);
+		     name, &sym->declared_at);
 	  return false;
 	}
       if (sym->attr.dummy)
@@ -13211,7 +13213,7 @@  resolve_fl_procedure (gfc_symbol *sym, int mp_flag)
       if (sym->attr.subroutine && sym->attr.result)
 	{
 	  gfc_error ("PROCEDURE attribute conflicts with RESULT attribute "
-		     "in %qs at %L", sym->name, &sym->declared_at);
+		     "in %qs at %L", sym->ns->proc_name->name, &sym->declared_at);
 	  return false;
 	}
       if (sym->attr.external && sym->attr.function && !sym->attr.module_procedure
diff --git a/gcc/fortran/symbol.c b/gcc/fortran/symbol.c
index 59f602d80d5..b96706138c9 100644
--- a/gcc/fortran/symbol.c
+++ b/gcc/fortran/symbol.c
@@ -2004,9 +2004,12 @@  gfc_add_type (gfc_symbol *sym, gfc_typespec *ts, locus *where)
 	gfc_error ("Symbol %qs at %L conflicts with symbol from module %qs, "
 		   "use-associated at %L", sym->name, where, sym->module,
 		   &sym->declared_at);
+      else if (sym->attr.function && sym->attr.result)
+	gfc_error ("Symbol %qs at %L already has basic type of %s",
+		   sym->ns->proc_name->name, where, gfc_basic_typename (type));
       else
 	gfc_error ("Symbol %qs at %L already has basic type of %s", sym->name,
-		 where, gfc_basic_typename (type));
+		   where, gfc_basic_typename (type));
       return false;
     }
 
@@ -2024,7 +2027,7 @@  gfc_add_type (gfc_symbol *sym, gfc_typespec *ts, locus *where)
       || (flavor == FL_PROCEDURE && sym->attr.subroutine)
       || flavor == FL_DERIVED || flavor == FL_NAMELIST)
     {
-      gfc_error ("Symbol %qs at %L cannot have a type", sym->name, where);
+      gfc_error ("Symbol %qs at %L cannot have a type", sym->ns->proc_name->name, where);
       return false;
     }
 
diff --git a/gcc/testsuite/gfortran.dg/pr39695_1.f90 b/gcc/testsuite/gfortran.dg/pr39695_1.f90
new file mode 100644
index 00000000000..4dffaa012bd
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr39695_1.f90
@@ -0,0 +1,8 @@ 
+! { dg-compile }
+!
+
+function f()
+  intrinsic :: sin
+  procedure(sin), pointer :: f ! { dg-error "Procedure pointer 'f'" }
+  f => sin
+end function f
diff --git a/gcc/testsuite/gfortran.dg/pr39695_2.f90 b/gcc/testsuite/gfortran.dg/pr39695_2.f90
new file mode 100644
index 00000000000..8c2aba29d3b
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr39695_2.f90
@@ -0,0 +1,12 @@ 
+! { dg-compile }
+!
+
+function g()
+ interface
+    subroutine g()
+    end subroutine g
+  end interface
+  pointer g
+  real g   ! { dg-error "Symbol 'g' at .1. cannot have a type" }
+end function
+
diff --git a/gcc/testsuite/gfortran.dg/pr39695_3.f90 b/gcc/testsuite/gfortran.dg/pr39695_3.f90
new file mode 100644
index 00000000000..69c74878fbc
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr39695_3.f90
@@ -0,0 +1,11 @@ 
+! { dg-compile }
+!
+
+function g()
+ interface
+    subroutine g()   ! { dg-error "RESULT attribute in 'g'" }
+    end subroutine g
+  end interface
+  real g             ! { dg-error "Symbol 'g' at .1. cannot have a type" }
+end function
+
diff --git a/gcc/testsuite/gfortran.dg/pr39695_4.f90 b/gcc/testsuite/gfortran.dg/pr39695_4.f90
new file mode 100644
index 00000000000..93ae85729db
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr39695_4.f90
@@ -0,0 +1,14 @@ 
+! { dg-compile }
+!
+
+function g()
+  implicit none
+  interface
+    function g()
+      integer g
+    end function g
+  end interface
+  pointer g
+  real g   ! { dg-error "Symbol 'g' at .1. already has basic type of INTEGER" }
+end function
+
-- 
2.11.0