User account creation filtered due to spam.

Bug 51056 - [4.7 Regression][OOP] Bogus "Unused module variable '__vtab_domain_Domain_container'"
Summary: [4.7 Regression][OOP] Bogus "Unused module variable '__vtab_domain_Domain_con...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.7.0
: P4 normal
Target Milestone: 4.7.0
Assignee: janus
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2011-11-09 12:41 UTC by Tobias Burnus
Modified: 2012-01-20 08:07 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work: 4.6.3
Known to fail: 4.7.0
Last reconfirmed: 2011-11-09 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2011-11-09 12:41:30 UTC
As reported by xarthisius at #gfortran,

the following program gives a bogus warning with -Wall. For one of my local trees, I get:

Warning: Unused module variable '__vtab_domain_Domain_container' which has been explicitly imported at (1)

for my other 4.7 tree, I get:

Warning: Unused module variable '__def_init_domain_Domain_container' which has been explicitly imported at (1)




module domain
   implicit none
   private
   public :: domain_container, dom

   type :: domain_container
      integer :: D_x             !< set to 1 when x-direction exists, 0 otherwise
    contains
      procedure :: init => init_domain_container
   end type domain_container

   type(domain_container) :: dom

   contains
      subroutine init_domain_container(this)
         implicit none
         class(domain_container), intent(inout) :: this
         this%D_x = 0
      end subroutine init_domain_container
end module domain

program ala
   use domain, only: dom
   implicit none
   call dom%init
end program ala
Comment 1 janus 2011-11-09 15:02:02 UTC
(In reply to comment #0)
> for my other 4.7 tree, I get:
> 
> Warning: Unused module variable '__def_init_domain_Domain_container' which has
> been explicitly imported at (1)

That's what I get here with:

gcc version 4.7.0 20111109 (experimental) [trunk revision 181203] (GCC)



Reduced test case:

module domain
  implicit none
  type :: domain_container
  contains
    procedure, nopass :: init
  end type
  type(domain_container) :: dom
contains
  subroutine init
  end subroutine
end module

program ala
  use domain, only: dom
  implicit none
  call dom%init
end program ala
Comment 2 Dominique d'Humieres 2011-11-09 15:33:05 UTC
Revision 177649 is OK.
Revision 178509 gives the warning.
Comment 3 janus 2011-11-09 17:45:58 UTC
(In reply to comment #2)
> Revision 177649 is OK.
> Revision 178509 gives the warning.

Well, the culprit is surely this one:

http://gcc.gnu.org/viewcvs?view=revision&revision=177833
Comment 4 janus 2011-11-09 18:32:51 UTC
Possible fix:

Index: module.c
===================================================================
--- module.c    (revision 181207)
+++ module.c    (working copy)
@@ -4213,7 +4213,7 @@ load_needed (pointer_info *p)
 
   mio_symbol (sym);
   sym->attr.use_assoc = 1;
-  if (only_flag)
+  if (only_flag && (strncmp (sym->name, "__", 2) != 0))
     sym->attr.use_only = 1;
   if (p->u.rsym.renamed)
     sym->attr.use_rename = 1;
Comment 5 janus 2011-11-15 15:22:10 UTC
Taking this. The patch in comment #4 is not particularly pretty, but at least it's simple, it works and shows no testsuite regressions. I should probably include a small comment, though.
Comment 6 Tobias Burnus 2012-01-17 09:28:24 UTC
(In reply to comment #5)
> Taking this. The patch in comment #4 is not particularly pretty, but at least
> it's simple, it works and shows no testsuite regressions. I should probably
> include a small comment, though.

I think a comment would be useful and I'd prefer a

  if (only_flag && sym->name[0] == '_' && sym->name[1] == '_')

I think it affects __vtab, __def_init, __copy - and, in future, __free. (It might also affect __vtype_ and __class; I don't know whether they can occur in a .mod file.)
Comment 7 Tobias Burnus 2012-01-20 08:07:06 UTC
Author: burnus
Date: Fri Jan 20 08:06:53 2012
New Revision: 183326

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

        PR fortran/51056
        * module.c (load_needed, read_module): Don't mark __vtab etc.
        as use_only.

2012-01-20  Tobias Burnus  <burnus@net-b.de>
            Janus Weil  <janus@gcc.gnu.org>

        PR fortran/51056
        * gfortran.dg/use_21.f90: New.


Added:
    trunk/gcc/testsuite/gfortran.dg/use_21.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/module.c
    trunk/gcc/testsuite/ChangeLog
Comment 8 Tobias Burnus 2012-01-20 08:07:47 UTC
FIXED on the trunk (4.7).