This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Patch, gfortran] Fix host-associated, use-associated common blocks


:ADDPATCH <fortran>:

This patch allows common block symbols that are both host and use associated to find the correct declaration.

At present, gfortran builds a reference to a module variable of the same name as the use_associated common block variable: ie. with the attached test-case

[prt@localhost mytests]# /gcc-4.0/bin/gfortran  host_common.f90
/tmp/cc2DP9BV.o(.text+0x25): In function `foo.468':
: undefined reference to `__global__a'
collect2: ld returned 1 exit status

The patch works by moving the call to gfc_generate_contained_functions, in gfc_generate_function_code, to after the call to gfc_trans_common. This ensures that the host, use-associated common blocks are built and the declarations made before the contained functions are generated.

Bubblestrapped and regtested on FC3/Athlon 1700.

OK for mainline and 4.0?

Paul T


2005-08-19  Paul Thomas  <pault@gcc.gnu.org>

	* trans-decl.c (gfc_generate_function_code): Move the call to
	gfc_generate_contained_functions to after the call to
	gfc_trans_common so the use-associated, use-associated common
	blocks produce the correct references.


2005-08-17  Paul Thomas  <pault@gcc.gnu.org>

	* gfortran.dg/host_common.f90: New.

============================================================

*** gcc/gcc/fortran/trans-decl.c	2005-08-19 12:56:40.197906312 +0200
--- /gcc-4.1/gcc/gcc/fortran/trans-decl.c	2005-08-19 13:00:36.065049056 +0200
*************** gfc_generate_function_code (gfc_namespac
*** 2336,2343 ****
  
    gfc_start_block (&block);
  
-   gfc_generate_contained_functions (ns);
- 
    if (ns->entries && ns->proc_name->ts.type == BT_CHARACTER)
      {
        /* Copy length backend_decls to all entry point result
--- 2336,2341 ----
*************** gfc_generate_function_code (gfc_namespac
*** 2354,2359 ****
--- 2352,2359 ----
    /* Translate COMMON blocks.  */
    gfc_trans_common (ns);
  
+   gfc_generate_contained_functions (ns);
+ 
    generate_local_vars (ns);
  
    current_function_return_label = NULL;

============================================================

! { dg-do run }
! This program tests that host+use associated common blocks work.
!
! provided by Paul Thomas - pault@gcc.gnu.org
!
module global
  common /z/ a
contains
end module global
program test
  use global
  a = 42.0
  call foo ()
contains
  subroutine foo
    common /z/ b
    if (b.ne.a) call abort
    if (b.ne.42.0) call abort
  end subroutine foo
end program test

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]