Bug 51913 - [4.6/4.7 Regression][OOP] bug when submitting a class pointer to a subroutine
Summary: [4.6/4.7 Regression][OOP] bug when submitting a class pointer to a subroutine
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.7.0
: P4 major
Target Milestone: 4.6.3
Assignee: Not yet assigned to anyone
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2012-01-20 09:35 UTC by alexander tismer
Modified: 2012-01-21 16:12 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2012-01-20 00:00:00


Attachments
buggy program (334 bytes, text/x-fortran)
2012-01-20 09:35 UTC, alexander tismer
Details

Note You need to log in before you can comment on or make changes to this bug.
Description alexander tismer 2012-01-20 09:35:44 UTC
Created attachment 26390 [details]
buggy program

When I declare a pointer in main routine:
>> CLASS(sparseMatrix_t), pointer :: sparseMatrix

Then I pass this pointer to a subroutine
>> call test(sparseMatrix)

I get a compiler error message:
>> Error: Actual argument to 'matrix' at (1) must have the same declared type

Please find attached a small program that does not work and fails compiling with this error. I find this fault in gfortran-4.6.1 and gfortran-4.7.0 20111210.
I compiled with 'gfortran main.f90'.
Comment 1 Tobias Burnus 2012-01-20 14:27:04 UTC
Conformed. Works with NAG f95 and ifort. And works with GCC 4.5. (Probably because the valid but not correctly working check was not yet implemented.)


The failing check (in interface.c's compare_parameter; cf. PR46161, Rev. 166018) is:

  /* F2003, 12.5.2.5.  */
  if (formal->ts.type == BT_CLASS
      && (CLASS_DATA (formal)->attr.class_pointer
          || CLASS_DATA (formal)->attr.allocatable))
    {
...
      if (CLASS_DATA (actual)->ts.u.derived
          != CLASS_DATA (formal)->ts.u.derived)
            gfc_error ("Actual argument to '%s' at %L must have the same "
                       "declared type", formal->name, &actual->where);


Thus, the question is why 
  CLASS_DATA (actual)->ts.u.derived ! = CLASS_DATA (formal)->ts.u.derived
or in other words why do we have two different symbols in the symtree? We have:

(gdb) p formal->ts.u.derived->name
$4 = 0x2aaaacf45000 "__class_m_sparsematrix_Sparsematrix_t_p"
(gdb) p actual->ts.u.derived->name
$5 = 0x2aaaacf45000 "__class_m_sparsematrix_Sparsematrix_t_p"


What I find a bit odd is:
(gdb) p formal->ts.u.derived->module
$9 = 0x2aaaace25fc0 ""  ! <<< pointer to empty string
(gdb) p actual->ts.u.derived->module
$8 = 0x0  ! <<< NULL pointer

Otherwise, the two belong (unsurprisingly) to different namespaces:
(gdb) p actual->ts.u.derived->ns->proc_name->name
$13 = 0x2aaaace25fa8 "main"
(gdb) p formal->ts.u.derived->ns->proc_name->name
$14 = 0x2aaaace25fb0 "test"

Thus, having a different symbol - and hence a different pointer address - is not too surprising.
Comment 2 Tobias Burnus 2012-01-20 14:40:44 UTC
(In reply to comment #0)
> Created attachment 26390 [details]
> buggy program

Work around: Swap the USE statements in the main program.


(In reply to comment #1)
>   /* F2003, 12.5.2.5.  */
The reference is wrong, it should be F2008.
Comment 3 Tobias Burnus 2012-01-21 15:12:39 UTC
Author: burnus
Date: Sat Jan 21 15:12:31 2012
New Revision: 183368

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=183368
Log:
2012-01-21  Tobias Burnus  <burnus@net-b.de>

        PR fortran/51913
        * interface.c (compare_parameter): Fix CLASS comparison.

2012-01-21  Tobias Burnus  <burnus@net-b.de>

        PR fortran/51913
        * gfortran.dg/class_47.f90: New.


Added:
    trunk/gcc/testsuite/gfortran.dg/class_47.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/interface.c
    trunk/gcc/testsuite/ChangeLog
Comment 4 Tobias Burnus 2012-01-21 16:11:55 UTC
Author: burnus
Date: Sat Jan 21 16:11:47 2012
New Revision: 183369

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=183369
Log:
2012-01-21  Tobias Burnus  <burnus@net-b.de>

        PR fortran/51913
        * interface.c (compare_parameter): Fix CLASS comparison.

2012-01-21  Tobias Burnus  <burnus@net-b.de>

        PR fortran/51913
        * gfortran.dg/class_47.f90: New.


Added:
    branches/gcc-4_6-branch/gcc/testsuite/gfortran.dg/class_47.f90
Modified:
    branches/gcc-4_6-branch/gcc/fortran/ChangeLog
    branches/gcc-4_6-branch/gcc/fortran/interface.c
    branches/gcc-4_6-branch/gcc/testsuite/ChangeLog
Comment 5 Tobias Burnus 2012-01-21 16:12:40 UTC
FIXED on the trunk (4.7) and on the 4.6 branch.

Thanks for reporting the bug!