Bug 52909 - [F03] Procedure pointers not private to modules
Summary: [F03] Procedure pointers not private to modules
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.8.0
: P3 normal
Target Milestone: ---
Assignee: janus
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-04-08 23:12 UTC by Andrew Benson
Modified: 2012-12-10 23:21 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2012-04-08 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Benson 2012-04-08 23:12:17 UTC
The following code won't compile with the latest gfortran (or with 4.6 and 4.7). The two procedure pointers should be private to their respective modules so there should be no symbol conflict.

module Module1
  implicit none
  private
  procedure(), pointer :: procPtr => null()
end module Module1

module Module2
  implicit none
  private
  procedure(), pointer :: procPtr => null()
end module Module2

program Test
  use Module1
  use Module2
  implicit none
end program Test


$ gfortran -v
Using built-in specs.
COLLECT_GCC=/home/abenson/gcc4.7/bin/gfortran
COLLECT_LTO_WRAPPER=/home/abenson/gcc4.7/libexec/gcc/x86_64-unknown-linux-
gnu/4.8.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../gcc4.7/configure --prefix=/home/abenson/gcc4.7 --enable-
languages=c,c++,fortran --disable-multilib --with-gmp=/home/abenson/gcc4.7 --
with-mpc=/home/abenson/gcc4.7 --with-mpfr=/home/abenson/gcc4.7
Thread model: posix
gcc version 4.8.0 20120407 (experimental) (GCC) 

$ gfortran test.F90
/tmp/ccuQNbu2.s: Assembler messages:
/tmp/ccuQNbu2.s:13: Error: symbol `procptr' is already defined
Comment 1 janus 2012-04-08 23:36:20 UTC
Confirmed.

The problem is: We currently fail to apply the proper name mangling to procedure pointers!
Comment 2 janus 2012-04-09 14:40:12 UTC
Preliminary patch, which makes the test case work:


Index: gcc/fortran/trans-decl.c
===================================================================
--- gcc/fortran/trans-decl.c	(revision 186243)
+++ gcc/fortran/trans-decl.c	(working copy)
@@ -1536,6 +1536,14 @@ get_proc_pointer_decl (gfc_symbol *sym)
 		     VAR_DECL, get_identifier (sym->name),
 		     build_pointer_type (gfc_get_function_type (sym)));
 
+  if (sym->module)
+    {
+      /* Do name mangling.  */
+      gfc_set_decl_assembler_name (decl, gfc_sym_mangled_identifier (sym));
+      if (sym->attr.use_assoc)
+	DECL_IGNORED_P (decl) = 1;
+    }
+  
   if ((sym->ns->proc_name
       && sym->ns->proc_name->backend_decl == current_function_decl)
       || sym->attr.contained)
Comment 3 janus 2012-12-10 23:17:51 UTC
Author: janus
Date: Mon Dec 10 23:17:43 2012
New Revision: 194375

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=194375
Log:
2012-12-10  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/52909
	* trans-decl.c (get_proc_pointer_decl): Apply name mangling.


2012-12-10  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/52909
	* gfortran.dg/proc_ptr_39.f90: New test case.

Added:
    trunk/gcc/testsuite/gfortran.dg/proc_ptr_39.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/trans-decl.c
    trunk/gcc/testsuite/ChangeLog
Comment 4 janus 2012-12-10 23:21:30 UTC
Fixed with r194375. Closing.

Thanks for the report!