C KAP and Incorrect Programs

KAP users should be aware that KAP assumes that the Fortran code that it processes conforms to the Fortran rules. Programs that violate these rules may behave differently after KAP transforms it.

As an example, the following is a program in which the loop control variable is modified during execution of the loop:

DIMENSION A(200)
COMMON I
J = 10
K = 100
L = 10

DO I=J,K,L
A(I) = I
CALL SETI
ENDDO

WRITE (6,*) I,A(I)
END

SUBROUTINE SETI
COMMON I
I = 20
END

The output of this program is as follows:

30  30.00000

When the Digital Fortran compiler does not know the value of the "increment" parameter of a DO loop, it always computes a loop iteration count, even if the value is subsequently determined by value propagation. Thus, if the program illegally modifies the loop control variable I , the loop will still complete in the correct number of iterations. In this case, no compilation time or run-time error message is given, even though the program violates the Fortran 77 standard and language rules.

KAP produces the following when this program is processed:

DIMENSION A(200)
COMMON I

DO   I=10,100,10
A(I) = I
CALL SETI
END DO

WRITE (6, *) I, A(I)
END

SUBROUTINE SETI
COMMON I
I = 20
END

This program incurs an access violation at run time. Since the Digital Fortran compiler sees that the increment value is a constant, it uses I directly to test for loop termination. Since I is modified in the loop just before the test, the loop does not terminate, but at the top of the loop I is given a new value appropriate for the iteration number the loop has reached. Eventually I exceeds 200 and the assignment statement accesses past A(200) , resulting in the access violation.

A wide variety of incorrect behaviors can result from KAP transformations with "illegal" programs. This possibility (and others of like nature) will need to be considered when evaluating programs whose run-time behavior changes when KAP is used.


Previous Page | Next Page | Contents | Index |
Command-Line Qualifiers