[comp.lang.fortran] fortran compiler for unix machines

mab@ukc.ac.uk (M.A.Broom) (02/22/91)

   Does anybody know of a good Fortran compiler for a 

   Unix Operating system ?

    We would like it to be able to check the following:

      a) extensions to the Fortran 77 standard;

      b) check array bounds are within defined range;

      c) check the types of arguments passed between program

         units  are the same and the number of arguments 

         passed is correct;

      d) undefined variables are left as undefined and not set to

         zero or any other predefined initial state;

      e) check varaibles have been declared before used.


    At the moment we have a DEC 8800 system running VMS and we 

    are using the University of Waterloo WATFOR-77 compiler which

    does all the above.

   

       If anybody knows of a good fortran compiler for a unix opearting

    system that does at least items  (c) and (d) above could they mail me.


     Thanks in advance. 



   Martin Broom        mab@ukc.uk.ac
   Computing Lab
   University of Kent
   Canterbury
   Kent
   England

khb@chiba.Eng.Sun.COM (Keith Bierman fpgroup) (02/23/91)

In article <6939@harrier.ukc.ac.uk> mab@ukc.ac.uk (M.A.Broom) writes:


      Does anybody know of a good Fortran compiler for a 

      Unix Operating system ?

       We would like it to be able to check the following:

	 a) extensions to the Fortran 77 standard;

many claim this, few do it really well (vms fortran goofs in some
places, and it is very good at this sort of thing). IBM's xlf is very
strict. In general, I strongly advise the use of a static analysis
tool (a review of one in particular "attached"). 

	 b) check array bounds are within defined range;

	-C is supported by most unix f77 compilers. it provides
	runtime checks

	 c) check the types of arguments passed between program
	    units  are the same and the number of arguments 
	    passed is correct;

xlf does this. static analyzers do it.	

	 d) undefined variables are left as undefined and not set to
	    zero or any other predefined initial state;

static analyzers do this.


	 e) check varaibles have been declared before used.

ditto

Subject: fortran-lint (fortran tool(s)) 
--text follows this line--
				Intro
			  -----------------
From time to time folks ask:

1)  Can I get numbered listings (sure awk "{i=i+1; print i":" $0}" etc.)
2)  Can I get Cross references  (sure use source browser)
3)  Why is my code broken       (hours later, ah is this a O or an 0?)
4)  Why doesn't cxflow work for f77 ?

There are a variety of tools, public domain, site specific and
commerical which address these needs. One of the groups which sells
such a product was kind enough to send it to me to review. 

			       Top Line
			     -----------

	The product solves far more problems than it creates.
	Certainly handy to have around. Has a few rough edges, but
	very, very useful.
				   
			       Details
			   ---------------

	The vendor is IPT 1096 East Meadow Circle, Palo Alto, CA 94303
			     415-494-7500

	*** legalism:
	    PRL of the UK claims "flint" is a name trademarked by them.
	    In the text of this review I use "flint" as the invocation
	    name of the IPT product (because it is). I have no reason
	    to doubt PRL's claim so this is acknowledgement that PRL
	    claims trademark protection of the name. If possible, I
	    will review their flint at a later date.  
	*** end aside

The most obvious thing for a "lint" program to do, is to catch real and
likely coding errors (such as mismatched argument lists, variables
used before defined, violations of standards, etc.). IPT fortran-lint does a
crediable job of this. 

Several different levels of checking are available. A simple

	flint foo.f

will catch things like

USAGE WARNING- local variables set but never referenced:  NUMSIT (Line 2199)
USAGE ERROR- local variables referenced but never set:  NFLVPR (Line 306)

clearly the first is just bad juju (old code not maintained well, or a
possible typo) the latter is a sure sign that the code may fail with
the optimizer is turned up, or the code moved to another machine, or
recursion is enabled, or ...

SYNTAX WARNING- branch to label 29 from outside do loop.

I would have made this more than a warning.... as the code really
looks like

            go to 29
            do 30 im=1,nm                                               
 29            continue
               hs(nslice+im)=0.0
 30            continue

which is not standard complying ... (so I'd call it an error,
especially with the -a switch see below). But the key thing, is that
it is identified ... which makes it likely to be caught.

There is the added

      flint -a foo.f

>      common                                                            
>     *     cstop , dcycst, dmpint, dmplst, dmptime, dradlos, dtld  ,    
>                                                    ^
flux.f:FLUX line 113:
ANSI EXTENSION- symbol name longer than 6 characters.

Which, as can easily be seen, adds strict ANSI checking. 

There are a variety of flags, and tons of messages. Far more than I am
willing to clutter up a review with. We will only hit _some_ of the
highlights. 

	    flint -g foo.f | *.f | `cat mylistoffiles`

enables checking of interfaces. Checking is done for correct type
(real, double, logical*n, etc.) and size (real foo(100) vs real foo)
for storing into a constant. Consider the following silly codelet

      program bork
      real*8 x,y

      call foo(x,1.0d0)
      print*,x
      end
      subroutine foo(x,y)
      real*8 x(100)
      real y

      do i = 1, n
         y = x(i)**2+y
      enddo
      return
      end

flint -g silly.f produces

FORTRAN-lint    Rev 2.61                    7-Mar-90  22:54:11 
Options: -g 


Directory (current)

bork2.f  


*******************************************************************************
      Program BORK                      File bork2.f              Line 1

>      call foo(x,1.0d0)
>               ^
bork2.f:BORK line 4:
INTERFACE ERROR- R*8 variable passed to dummy arg which is a R*8
array.

<there is a way to set things up so this can get past sans nattering
... as many large codes do this on purpose>

>      call foo(x,1.0d0)
>                 ^
bork2.f:BORK line 4:
INTERFACE ERROR- R*8 actual arg passed to a R*4 dummy arg.

<<this is likely to be OK on DEC, wrong everywhere else>>

>      call foo(x,1.0d0)
>                 ^
bork2.f:BORK line 4:
INTERFACE ERROR- constant is changed by subprogram.

<<this is likely to be very confusing>>

USAGE ERROR- local variables referenced but never set:  X (Line 4)


*******************************************************************************
   Subroutine FOO                       File bork2.f              Line 7

USAGE ERROR- local variables referenced but never set:  N (Line 11)

*******************************************************************************



Global checking:

--- No additional global inconsistencies found ---


This functionality would be enough to warrent having this puppy handy.
But like a late night commerical (which I should be home watching ;>)
there's more!

There is a relatively comprehensive xref. The layout is a bit space
wasteful, here is a sample:

FORTRAN-lint    (symbol table)                                                                  5-Mar-90  16:03:32 
******** SYMBOL TABLE ********

*** Program:

SPICE : defined at line 2 of file spice.f
                    Calls- cputim.f:CPUTIM, elapse.f:ELAPSE,
		    getcje.f:GETCJE, tsec.f:TSEC, setmem.f:SETMEM,
		    zero8.f:ZERO8, readin.f:READIN, errchk.f:ERRCHK,
		    setup.f:SETUP, alter.f:ALTER, tmpupd.f:TMPUPD,
		    dctran.f:DCTRAN, ovtpvt.f:OVTPVT, dcop.f:DCOP,
		    acan.f:ACAN, title.f:TITLE 

*** Subroutines:

ACAN : defined at line 14 of file acan.f
                    Args- none
                    Calls- tsec.f:TSEC, getm8.f:GETM8,
		    getm16.f:GETM16, dinit.f:DINIT, crunch.f:CRUNCH,
		    getcje.f:GETCJE, acload.f:ACLOAD, acdcmp.f:ACDCMP,
		    acsol.f:ACSOL, extmem.f:EXTMEM, copy16.f:COPY16,
		    noise.f:NOISE, disto.f:DISTO, clrmem.f:CLRMEM
                    Called by- spice.f:SPICE

...

CMEYER : defined at line 1 of file cmeyer.f
                    Args- (R*8 R, R*8 R, R*8 R, R*8 R, R*8 R, R*8 R,
		    R*8 R, R*8 R, R*8 R, R*8 R, R*8 R, R*8 S, R*8 S,
		    R*8 S, R*8 S, R*8 S, R*8 S)
                    Called by- mosfet.f:MOSFET

.... note that R*8 R means dp, referenced, S means Set.
....
*** Vars/Arrays:

A (adj) : R*8 : local
                    in (shlsrt.f:SHLSRT) is Ref, Set, Dummy argument
A (1) : CHAR*1 : local
                    in (move.f:MOVE) is Set, Dummy argument
A : R*8 : local
                    in (moseq2.f:MOSEQ2) is Ref, Set
                    in (scale.f:SCALE) is Ref, Set
                    in (xxor.f:XXOR) is Ref, Dummy argument

....

this provides handy information. Source browser is more fun, and
almost certainly the better tool. But there are times where this sort
of report is exactly what management ordered....

There are summary statistics

FORTRAN-lint    (statistics)                                                                    5-Mar-90  16:03:32 
>>> Statistics:

 Number of source files:   130

 Source files:    18556 lines,    561873 bytes    ( 14% comments, 86% code )
 Include files:       0 lines,         0 bytes
 Total parsed:    18556 lines,    561873 bytes    ( 14% comments, 86% code )

 Total subprograms:    130
   Subroutines:        121
   Functions:            8
   Program:              1
   Block Data:           0

 Total messages: 652

                 Errors  Warnings   FYIs  
                -------- -------- --------
    Syntax:           0        0      102 
    Interface:      426        1        4 
    Data usage:      17       58       44 

    Implicit typing:       <supp> 
    Portability issues:         0 
    ANSI extensions:       <supp> 


supp means suppressed. It seems strange to note interface errors but
no portability issues. The defintion of portability issue is possibly
debatable. 

----
Call graph tree, with options to minimze output. {means missing}

FORTRAN-lint    (call tree)                                     
                5-Mar-90  16:03:32 
Call tree:

This is a primary tree starting at the program 'SPICE'

SPICE-+-CPUTIM (1)--{ETIME} 
      +-ELAPSE--{TIME} 
      +-GETCJE (2)--TSEC (3)--CPUTIM see 1
      +-TSEC see 3
      +-SETMEM-+-LOCF
      |        +-NXTEVN
      |        +-NXTMEM
      |        +-ERRMEM (4)--DMPMEM (5)--LOCF
      |        +-MEMORY
      +-ZERO8
      +-READIN-+-TSEC see 3
      |        +-ZERO4
      |        +-GETLIN (6)--COPY8 (7)--LOCF
      |        +-COPY8 see 7
      |        +-GETM4 (8)--GETMX (9)-+-MEMPTR (10)--LOCF
      |        |                      +-ERRMEM see 4
      |        |                      +-NXTEVN
      |        |                      +-COMPRS (11)-+-NXTEVN
      |        |                      |             +-COPY4 (12)--LOCF
      |        |                      +-NXTMEM
      |        |                      +-MEMORY
      |        |                      +-COPY4 see 12
      |        |                      +-LOCF
      |        |                      +-MEMADJ (13)-+-NXTMEM
      |        |                                    +-COMPRS see 11
      |        |                                    +-COPY4 see 12
      |        |                                    +-MEMORY
.....
This is a detached tree starting at the subprogram 'ZERO16'

ZERO16
.....

The detached tree means code left in, which is called from nowhere.
Probably best to remove, though there are times when someone does this
on purpose....

I have found a fair number of false positives, and there are a couple
of modest bugs. I will be doing more testing, and reporting bugs to
the authors.

The documentation does not do the product justice, and it could use
some manpages or other online reference facility.

I don't know pricing. There is a copy protection scheme (hostid
based at the moment, but a floating server is being implemented
RealSoonNow). There seem to be quantity discounts.

...sun internal remarks deleted... enhancement-wise, this fortran-lint
from IPT (or equivalents from elsewhere) will be a great boon to those
who wrestle with Fortran codes, and sometimes lose.

There are other vendors with similar (and perhaps even superior) tools, but
I haven't reviewed them personally .... so for the nonce this is my
new answer to questions (1)-(4) from the intro. 

Cheers all.

Keith H. Bierman    |*My thoughts are my own. !! kbierman@Eng.Sun.COM
It's Not My Fault   | MTS --Only my work belongs to Sun* kbierman%eng@sun.com
I Voted for Bill &  | Advanced Languages/Floating Point Group            
Opus                | "When the going gets Weird .. the Weird turn PRO"

"There is NO defense against the attack of the KILLER MICROS!"
			Eugene Brooks


Postscript: 

Some competing products:

FORWARN Quibus Enterprises: Seems similar, from a promo blurb reading.
			    Probably has slightly uglier reporting
			    (one assumes the promo is as good as it
			    gets). 217 356 8876. Primary focus is the
			    PC market, but say unix versions are
			    available. $1200 would appear to be the
			    price, no discount structure info
			    available. Also avaliable from them are
			    "Fortran development tools" reformatter,
			    simple spagetti to if-then-else. 

Flint(tm) Programming Research ltd:

			    Seems like a much more powerful tool (from
			    the promo lit) includes complexity
			    metrics, X11 interface and all sorts of
			    advisories about what constitutes good
			    portable code (beyond standard(s)
			    conformance). FAX (44) 01 336 1151 voice
                            (44) 1 942 9242

	also

            		         8701 Bedford Euless Rd.
 		                 Suite 520
                                 Hurst TX 76053 USA
		                 ph: 817-589-0949, fax: 817-595-4611


FORCHECK Leiden University Box 9604
2300 RC Leiden
The Netherlands
31-71-276804		    Claims similar to IPT's product.
			    Is said to be available on Suns and many
			    other platforms. I have no personal
			    experience with it.

FLOPPY/FLOW		    From CERN. FLOPPY was posted to
			    comp.sources.misc. Sun employees can get
			    it via the usual internal anon ftp site.
			    FLOW was not posted (and is the 'good
			    part'). 

Related tools of interest:

FOR_STRUCT    Cobolt-Blue 2940 Union Ave Suite C San Jose CA 95124
	      408 723 0474. This is a "reverse engineering tool" to
	      use the COBOL lingo, viz. makes old code more readable
	      and maintainable. I have not used it myself.

SPAG	      I have reviewed SPAG, short overview is that SPAG is
	      quite handy ... alas not very unixlike (fixable with
	      some shell programming). (Sun employees note: Full
	      review is in the file called SPAG in the same directory
	      as this review). I like the results, and recommend this
	      tool with the caveat about non-unix interface...

	      US distributor: OTG
			      voice 717 222 9100
			      fax   717 229 9103

              Authors:
	                 Polyhedron Software Ltd
			 Magdalen House
			 98 Abingdon Road
			 Standlake
			 Witney
			 Oxon OX8 7RN
			 Tel 0865 300 579
	       
--
----------------------------------------------------------------
Keith H. Bierman    kbierman@Eng.Sun.COM | khb@chiba.Eng.Sun.COM
SMI 2550 Garcia 12-33			 | (415 336 2648)   
    Mountain View, CA 94043