DPD200256205 Have -warn unused warn about unused ONLY names

DPD200256205 Have -warn unused warn about unused ONLY names

I recall discussing this in a thread somewhere but I can't seem to find it, Anyway this document

https://software.intel.com/en-us/node/520142

Suggests "DPD200256205 Have -warn unused warn about unused ONLY names"  is in the new release. I took this to mean that:

 

USE FRED, ONLY: bill, alan, peter

would throw a warning if for example alan was not used in the scope of the USE. I was quite looking forward to this feature, did it fall off the list at some point or have I misunderstood?

 

 

 

37 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

I'm looking forward to this feature too and my expectation is also along the lines mentioned by app4619 in the original post.

But I didn't notice such a feature in the 2015 Beta version, so it'll be surprising if it is available in the final release.

This was added late in the Beta cycle, and should be in the final product

Are you guys seeing something different?

           --Lorri

Quote:

Lorri Menard (Intel) wrote:

This was added late in the Beta cycle, and should be in the final product

Are you guys seeing something different?

           --Lorri

I do not seem to be seeing that feature. I was expecting to have quite a number of warnings and when I didn't I deliberately created some lines that should have given a warning. Try a simple test case. 

Hmm.   Our regression test looks like this:

module cq256205mymod

integer a, b, c, x

end module cq256205mymod

program cq256205
use cq256205mymod, only: a,b,c
integer d

a = 1
b = 2
print *, "success"
end program

and does issue two warnings when compiled as:

ifort /warn:unused cq256205.f90

One message for "d"  one message for "c"

What is different about your example?

Yes that example works for me also. The example I tried where in a large application with many modules etc. There are also different build options e.g. I only check the warning on debug builds. I will investigate further and report back.

It does not warn when the "unused only" is within a module procedure it would seem. No warning for "c". As all my routines are usually within modules that appears to be why I get no warnings.

module cq256205mymod
    implicit none
    integer a, b, c, x
end module cq256205mymod
    
module fred
    contains
    subroutine bill
        use cq256205mymod, only: a,b,c
        implicit none
        integer f
        a = 1
        b = 2
        print *, "success"    
    end subroutine bill   
end module fred

program cq256205
    use cq256205mymod, only: a,b  
    use fred
    implicit none
    integer d

    a = 1
    b = 2
    print *, "success"
    call bill()
end program 

1>------ Build started: Project: Console3, Configuration: Debug Win32 ------
1>Compiling with Intel(R) Visual Fortran Compiler XE 15.0.0.108 [IA-32]...
1>Console3.f90
1>C:\Users\Andrew\Documents\Cadfil\cadfil_devt_intel\Console3\Console3.f90(11): remark #7712: This variable has not been used.   [F]
1>C:\Users\Andrew\Documents\Cadfil\cadfil_devt_intel\Console3\Console3.f90(22): remark #7712: This variable has not been used.   [D]

Thank you for the investigation --- I'll send that info over the wall to my colleague.

 

Quote:

app4619 wrote:

.. As all my routines are usually within modules that appears to be why I get no warnings...

Same situation with me; almost all the code is in modules.

 

Quote:

Lorri Menard (Intel) wrote:

Thank you for the investigation --- I'll send that info over the wall to my colleague.

 

Was there any feedback on this issue ?

Regards

Andrew

 

Hi Andrew --

      He acknowledged that it failed, but there's no schedule for the fix yet.

 

I was just informed that the fix for this problem is expected to be in Update 1.

Steve - Intel Developer Support

Quote:

Steve Lionel (Intel) wrote:

I was just informed that the fix for this problem is expected to be in Update 1.

Thanks that will be most welcome :-)

 

And indeed is seems to be working in update 1!

I was pleasantly surprised and the relatively small number of warnings I got when doing a full rebuild of a large project :-)

it is nice to have some spring cleaning in your code even if it is winter.

 

 

Depends where you are ... it's still Spring here until Monday :-)

It's technically not winter here for another few weeks, but we did just have our first snow of the season in southern New Hampshire.

Steve - Intel Developer Support

Sounds like the difference between meteorological and astronomical winter. A-basin opened last month, does that make it winter here?

module cq256205mymod
    implicit none
    integer :: a, b, c, x
end module cq256205mymod
    
module fred
    integer :: y,w
    contains
    subroutine bill
        use cq256205mymod, only: a,b,c !c unused remark #7712
        implicit none
        integer f                      !f unused remark #7712
        a = 1
        b = 2
        print *, "success"    
    end subroutine bill   
end module fred

program cq256205                       ! test for /warn:unused Fortran Compiler XE 15.0.1.148 [IA-32]
    use cq256205mymod, only: a,b  
    use fred, only: y,bill             ! bill is NOT reported as unused
    implicit none
    integer d                          ! d unused remark #7712

    a = 1
    b = 2
    y = 1
    print *, "success"
    !call bill()                       
end program

I think I spoke too soon..... I noticed some issues with this feature yesterday and have updated the test that was at #7. The problem is the line 

use fred, only: y,bill as it seems that unused applies to variablies and not module procedures.  Perhaps that was the intention?

Yes, it'll be nice if /warn:unused applies to module procedures too.

Well, the option's documentation does say: "Determines whether warnings occur for declared variables that are never used." A procedure is not a variable. Nor is a type or an interface. I will enter a feature request that any identifier in a USE list qualify for the warning. Issue ID is DPD200365039.

 

Steve - Intel Developer Support

See recent discussion at comp.lang.fortran: https://groups.google.com/forum/#!topic/comp.lang.fortran/RedeUCqh12c

I think the warning in this case is unwaranted: thoughts?

That's a gfortran warning, not really relevant to this thread. Intel Fortran doesn't give this warning. I'm inclined to agree with those in the thread who say the warning is inappropriate.

Steve - Intel Developer Support

Quote:

Steve Lionel (Intel) wrote:

That's a gfortran warning, not really relevant to this thread. Intel Fortran doesn't give this warning. I'm inclined to agree with those in the thread who say the warning is inappropriate.

I meant this:

module pubprivate 
! Can private stuff be equivalenced to public? 
  implicit none 
  integer,private:: pri = 666 
  integer,public :: pub 
  equivalence (pri,pub) 
end module pubprivate 

program usepubprivate 
  use pubprivate, only: pub 
  implicit none 
  print *,pub 
end program usepubprivate 

It gives

Compiling with Intel(R) Visual Fortran Compiler XE 15.0.1.148 [IA-32]...
p.f90
C:\..\p.f90(2): remark #7712: This variable has not been used.   [PUB]

 

Ah, ok. That is not right and I will let the developers know. (The complaint is about line 10 from your test case, not line 2. You probably compiled the main program separately.) Issue ID DPD200365810.

Steve - Intel Developer Support

The other interesting thing I learned from the #21 link was some comments on bind(c) and private from IanH. I guess this has been discussed and length elsewhere. For interest I made the following test with stand and warn everything, and it build and runs just fine. My personal thought is that bind(c) and private deserves at least a remark from the compiler. It may be standard conforming but it It should really be illegal in a sensible world??

module fredprivate 
    ! does bind(c) override private 
    implicit none 
    private :: fred !the key bit!!!!
    contains
    subroutine FRED() bind(C,name="FRED")
            integer, parameter :: ifred=123
            print *, ifred
    end subroutine fred
end module fredprivate 
program bindcprivate 
  implicit none
  interface
    subroutine FRED()                                 
    end subroutine FRED
  end interface
  call FRED()
end program bindcprivate 

 

As I indicated earlier, I do not believe that any kind of error or diagnostic is appropriate. Richard Maine, in c.l.f., explained the situation well. PRIVATE simply controls module accessibility, it isn't a chastity belt for the entity.

Steve - Intel Developer Support

I just noticed that no warning is displayed if the unused variable is declared as PARAMETER.  I already know :-) that parameters aren't really variables, but a warning if they are not used might still be useful.

Roman

 

The inappropriate unused warning has been fixed for a release later this year.

Steve - Intel Developer Support

Steve, great progress on this front.  Thanks much for your support.

Following up on Roman's comment in #27, will it be possible to catch scenarios involving variables declared with PARAMETER attribute too, such as one in the example below?

module m

   implicit none

   type :: foo
      integer :: i = 1
   end type foo
   type(foo), parameter :: bar = foo()
   
end module m

program p

   use m, only : foo, bar
   
   implicit none
   
   type(foo) :: baz
   
   baz%i = 2
   
   stop

end program p

 

I doubt we'd do that - it's extremely common to declare lots of PARAMETERs you never use.

Steve - Intel Developer Support

And, from what I have seen, unused named constants (PARAMETERs) do not make it into the .OBJ file created by the compiler, so they would not be recognized by the debugger (for example, they would not be present in the Locals window).

Quote:

Steve Lionel (Intel) wrote:

I doubt we'd do that - it's extremely common to declare lots of PARAMETERs you never use.

Are referring to listing them in an only/rename specifier, or them being declared in a scope in general?  I don't think listing the name of a parameter in an only/rename thing and then not using it in the inclusive scope of the use statement would be that common... unless they were putting that stuff in the office water again.

This kind of thing is not unusual in old but still mostly good code from Netlib and other places. Some of those authors used to have a boilerplate block of named constants named 'zero', 'ten', 'pi', 'ft_to_m', etc., that they copied into every subprogram -- into the office water, as you say.

The other common use/replication of unused constants is related to names such as 'sp', 'dp', etc., to refer to kind numbers.

Quote:

Steve Lionel (Intel) wrote:

I doubt we'd do that - it's extremely common to declare lots of PARAMETERs you never use.

Steve,

Sorry I didn't explain the point in detail in Quote #29 assuming it was self-evident from the context of this topic.

I am not hoping to get any compiler warnings with respect to code that declares named constants but which may not get used in that or any other scope.  For example, compilation of module m below obviously needs no warning with respect to bar.

Instead, I'm referring to the USE .., ONLY : statements that list named constants but which are not actually getting used in that code.  So program p, for instance, lists "bar" on the USE statement but you'll notice bar is not getting used in p.  Can the compiler generate warning for p when it is compiled with /warn:unused?

Thanks,

module m

   implicit none

   type :: foo
      integer :: i = 1
   end type foo
   type(foo), parameter :: bar = foo()  !.. This is ok, nothing to be done about this.
   
end module m

program p

   use m, only : foo, bar   !.. bar is not getting used in p; can /warn:unused point this out?
   
   implicit none
   
   type(foo) :: baz
   
   baz%i = 2
   
   stop

end program p

 

It seems reasonable to me to warn about names appearing in ONLY clauses, no matter what they are. But my guess is that this will be harder to implement as PARAMETERs "disappear" very early in the compilation process. I'll enter this as a feature request.

Steve - Intel Developer Support

Quote:

Steve Lionel (Intel) wrote:

It seems reasonable to me to warn about names appearing in ONLY clauses, no matter what they are. But my guess is that this will be harder to implement as PARAMETERs "disappear" very early in the compilation process. I'll enter this as a feature request.

Excellent, thanks.

I think the door is slightly ajar for warning about unused parameters. If a compilation causes a .MOD file to be wcreated, that file will contain information about parameters. Secondly, if the /debug-parameters:used /Zi options are used, the compiler is able to put information into the PDB file (?) about parameters that have been used and one can display their values in the Locals pane of the debugger. Therefore, it should be possible to collect a list of the names of parameters that were not used and output a warning message after compiling the subprogram that declares those parameters (or USEs a module containing those parameters).

Leave a Comment

Please sign in to add a comment. Not a member? Join today