The -Xlist options provide a valuable way to analyze a source program for inconsistencies and possible runtime problems. The analysis performed by the compiler is global, across subprograms.
–Xlist reports errors in alignment, agreement in number and type for subprogram arguments, common block, parameter, and various other kinds of errors.
–Xlist also can be used to make detailed source code listings and cross-reference tables.
Programs compiled with -Xlist options have their analysis data built into the binary files automatically. This enables global program checking over programs in libraries.
Global program checking (GPC), invoked by the -Xlistx option, does the following:
Enforces type-checking rules of Fortran more stringently than usual, especially between separately compiled routines
Enforces some portability restrictions needed to move programs between different machines or operating systems
Detects legal constructions that nevertheless might be suboptimal or error-prone
Reveals other potential bugs and obscurities
In particular, global checking reports problems such as:
Possible conflicts due to data type mismatches in common blocks between different subprograms
Usage problems
The -Xlist option on the command line invokes the compiler’s global program analyzer. There are a number of suboptions, as described in the sections that follow.
Example: Compile three files for basic global program checking:
demo% f95 -Xlist any1.f any2.f any3.f |
In the preceding example, the compiler:
Produces output listings in the file any1.lst
Compiles and links the program if there are no errors
Normally, output listings produced by -Xlistx are written to a file. To display directly to the screen, use -Xlisto to write the output file to /dev/tty.
Example: Display to terminal:
demo% f95 -Xlisto /dev/tty any1.f |
The –Xlist option provides a combination of features available for output. With no other -Xlist options, you get the following by default:
The listing file name is taken from the first input source or object file that appears, with the extension replaced by .lst
Error messages (embedded in listing) for inconsistencies across routines
Cross-reference table of the identifiers
Pagination at 66 lines per page and 79 columns per line
No call graph
No expansion of include files
The checking process recognizes all the files in the compiler command line that end in .f, .f90, .f95, .for, .F, .F95, or .o. The .o files supply the process with information regarding only global names, such as subroutine and function names.
Here is a listing of the Repeat.f source code used in the following examples:
demo% cat Repeat.f PROGRAM repeat pn1 = 27.005 CALL subr1 ( pn1 ) CALL newf ( pn1 ) PRINT *, pn1 END SUBROUTINE subr1 ( x ) IF ( x .GT. 1.0 ) THEN CALL subr2 ( x * 0.5 ) END IF END SUBROUTINE newf( ix ) INTEGER PRNOK IF (ix .eq. 0) THEN ix = -1 ENDIF PRINT *, prnok ( ix ) END INTEGER FUNCTION prnok ( x ) prnok = INT ( x ) + .05 END SUBROUTINE unreach_sub() CALL sleep(1) END SUBROUTINE subr2 (x) CALL subr1(x+x) END |
Example: Use -XlistX to show errors, warnings, and cross-reference
demo% f95 -XlistX Repeat.f demo% cat Repeat.lst Repeat.f Mon Mar 18 18:08:27 2002 page 1 FILE "Repeat.f" program repeat 4 CALL newf ( pn1 ) ^ **** ERR #418: argument "pn1" is real, but dummy argument is integer See: "Repeat.f" line #14 5 PRINT *, pn1 ^ **** ERR #570: variable "pn1" referenced as real but set as integer in line #4 subroutine newf 19 PRINT *, prnok ( ix ) ^ **** ERR #418: argument "ix" is integer, but dummy argument is real See: "Repeat.f" line #22 function prnok 23 prnok = INT ( x ) + .05 ^ **** WAR #1024: suspicious assignment a value of type "real*4" to a variable of type "integer*4" subroutine unreach_sub 26 SUBROUTINE unreach_sub() ^ **** WAR #338: subroutine "unreach_sub" never called from program subroutine subr2 31 CALL subr1(x+x) ^ **** WAR #348: recursive call for "subr1". See dynamic calls: "Repeat.f" line #10 "Repeat.f" line #3 Cross Reference Mon Mar 18 18:08:27 2002 page 2 C R O S S R E F E R E N C E T A B L E Source file: Repeat.f Legend: D Definition/Declaration U Simple use M Modified occurrence A Actual argument C Subroutine/Function call I Initialization: DATA or extended declaration E Occurrence in EQUIVALENCE N Occurrence in NAMELIST L Use Module Cross Reference Mon Mar 18 15:40:57 2002 page 3 P R O G R A M F O R M Program ------- repeat <repeat> D 1:D Cross Reference Mon Mar 18 15:40:57 2002 page 4 Functions and Subroutines ------------------------- INT intrinsic <prnok> C 23:C newf <repeat> C 4:C <newf> D 14:D prnok int*4 <newf> DC 15:D 19:C <prnok> DM 22:D 23:M sleep <unreach_sub> C 27:C subr1 <repeat> C 3:C <subr1> D 8:D <subr2> C 31:C subr2 <subr1> C 10:C <subr2> D 30:D unreach_sub <unreach_sub> D 26:D Cross Reference Mon Mar 18 15:40:57 2002 page 5 Variables and Arrays -------------------- ix int*4 dummy <newf> DUMA 14:D 16:U 17:M 19:A pn1 real*4 <repeat> UMA 2:M 3:A 4:A 5:U x real*4 dummy <subr1> DU 8:D 9:U 10:U <subr2> DU 30:D 31:U 31:U <prnok> DA 22:D 23:A ------------------------------------------------------------------ STATISTIC Mon Mar 18 15:40:57 2002 page 6 Date: Mon Mar 18 15:40:57 2002 Options: -XlistX Files: 2 (Sources: 1; libraries: 1) Lines: 33 (Sources: 33; Library subprograms:1) Routines: 6 (MAIN: 1; Subroutines: 4; Functions: 1) Messages: 6 (Errors: 3; Warnings: 3) |
The basic global cross-checking option is -Xlist with no suboption. It is a combination of suboptions, each of which could have been specified separately.
The following sections describe options for producing the listing, errors, and cross-reference table. Multiple suboptions may appear on the command line.
Add suboptions according to the following rules:
Append the suboption to -Xlist.
Put no space between the -Xlist and the suboption.
Use only one suboption per -Xlist.
Combine suboptions according to the following rules:
The most general option is -Xlist (listing, errors, cross-reference table).
Specific features can be combined using -Xlistc, -XlistE, -XlistL, or -XlistX.
Other suboptions specify further details.
Example: Each of these two command lines performs the same task:
demo% f95 -Xlistc -Xlist any.f |
demo% f95 - Xlistc any.f |
The following table shows the reports generated by these basic -Xlist suboptions alone:
Table 5–1 Basic Xlist Suboptions
Generated Report |
Option |
---|---|
Errors, listing, cross-reference |
–Xlist |
Errors only |
–XlistE |
Errors and source listing only |
–XlistL |
–XlistX |
|
–Xlistc |
The following table shows all -Xlist suboptions.
Table 5–2 Complete List of -Xlist Suboptions