Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28914 Discussions

How to cleanup unused use-only statements?

Jarek_T
Novice
953 Views

I am working with a large Fortran code that is changing a lot. I am using Intel Fortran through Visual Studio on Windows. Occasionally I would like to do some code cleanup like for example finding all the places where I use use-only statement to declare that I will be calling a function which I am no longer calling. Is there a way to detect those?

 

I would also like to detect functions missing "implicit none" statements. I wonder if those can be done through a compiler, Visual Studio or some (free) 3rd party tools. I realize that I can write my own code to analyze my source-code but I would preferer to avoid it.

Labels (1)
0 Kudos
1 Solution
Ron_Green
Moderator
871 Views

extend -warn unused to include unused module procedures listed in USE ONLY is Feature Request CMPLRLLVM-61734

View solution in original post

5 Replies
andrew_4619
Honored Contributor III
944 Views

The "use-only" thing is a question I raised a few years back. It would be nice "Warn-unused" applied but  it doesn't work or only works a 'little bit'.  Yes I think it would be a good feature if it worked and I will reiterate my feature request to Intel of long ago!

Sometimes I comment out the use-only and compare the errors list to the things I commented out but that is a bit tedious. 

As to "implicit none" missing I also  once upon a time made a simple utility to find however since that time I have changed my opinion and don't use the 'belt and braces' approach. All my routines are in modules or sub-modules so I make do with the "implicit none(type, external)" in the module header only.

0 Kudos
Ron_Green
Moderator
885 Views

The first question, dead 'use only' statements - that's a good question.  And I can see the need for that.  I posed this question to the team and will check for an existing Feature Request.  The DPD200256205 may help me find that.  Yes, found , it's new number CMPLRIL0-8879.   Doctor Fortran opened that request in 2014.  It was closed due to inactivity.  I'll reopen it for our IFX compiler.   One of our super smart Front-end developers has an interest in this feature and had this feedback:

"For #1, we already warn for things like unused variables, or uninitialized result values. So we theoretically have the ability to warn for unused “use-only” objects. In fact, it looks like nagfor already does it:

 

$ cat foo.f90

module m

contains

    subroutine sub()

        print *, "hi"

    end subroutine

end module

program p

    use m, only: sub

end program

 

$ nagfor foo.f90

NAG Fortran Compiler Release 7.2(Shin-Urayasu) Build 7203

Warning: foo.f90, line 11: SUB explicitly imported into P but not used

[NAG Fortran Compiler normal termination, 1 warning]

 

So if the customer has nagfor, they could use that. But it would be nice if we could do that too." 
Then she asked me to open a new Feature Request for that.  I'll revive this feature request.

 

For the second ask - she suggested we open a Feature Request for a new option like "-warn implicit_typing". When set, all scopes which have implicit typing will get a warning for it.  I'll get that opened also. She thinks this is doable and not too complicated to implement. 

 

Thanks for the suggestions.  These could be great additions to ifx! 

0 Kudos
Ron_Green
Moderator
872 Views

extend -warn unused to include unused module procedures listed in USE ONLY is Feature Request CMPLRLLVM-61734

Ron_Green
Moderator
867 Views

and 
add new feature and option so that all scopes which have implicit typing will get a warning Feature ID CMPLRLLVM-61735

Reply