fpt and WinFPT Reference Manual - Command-line Commands

| SimCon Home | Ref Manual Home |

CHECK AMBIGUOUS FLOW and RESOLVE AMBIGUOUS FLOW

Syntax:

[DO NOT] CHECK AMBIGUOUS FLOW [DO NOT] SHOW AMBIGUOUS FLOW [DO NOT] RESOLVE AMBIGUOUS FLOW

Function:

FPT checks for statements in which the program flow is ambiguous. If RESOLVE AMBIGUOUS FLOW is specified, the code is rewritten to resolve the ambiguity and to force a unique order of execution.

The Fortran standard explicitly states that the order of evaluation of terms within an expression is undefined. If an expression contains two or more function invocations at the same level of function nesting, the functions may therefore be invoked in any order. Different compilers choose different orders. As a result:

Where to use these commands:

Operating system command line Yes
Configuration file, config.fsp Yes
Specification (fsp) files, *.fsp Yes
Interactively, to FPT> prompt Yes
Interactive command files Yes
Embedded in the Fortran code Yes

Default

No check or change to the code is made by default (Note that defaults may be changed in the configuration file).

Examples:

In the following example the IF statement has ambiguous flow:

PROGRAM t_ambiguous_flow INTEGER*4,EXTERNAL :: f1,f2 ! Functions IF ((f1(1) > 0) .OR. (f2(2) < 0)) THEN WRITE(*,'("Test succeeded")') ENDIF END PROGRAM t_ambiguous_flow INTEGER*4 FUNCTION f1(n) INTEGER*4 n WRITE(*,'("Call to f1")') f1 = n END FUNCTION f1 INTEGER*4 FUNCTION f2(n) INTEGER*4 n WRITE(*,'("Call to f2")') f2 = n END FUNCTION f2

The code is built and run with default optimisation under two Linux compilers, and the program flow follows different paths:

$ gfortran -o t_gfortran.exe t_ambiguous_flow.f90 $ t_gfortran.exe Call to f1 Test succeeded $ $ ifort -o t_ifort.exe t_ambiguous_flow.f90 $ t_ifort.exe Call to f1 Call to f2 Test succeeded $

You may wish to cut-and-paste this example to your own system to see what your compilers will do.

The code is analysed interactively by fpt to show the ambiguous flow:

FPT> show ambiguous flow Statements With Ambiguous Program Flow ====================================== Line: 7, File: ... man\code_examples\ambiguous_flow\t_ambiguous_flow.f90 ! IF ((F1(1)>0) .OR. & !--------------^--------------------------------------------------------------- !!! fpt - 3665 Program flow is ambiguous. Functions may be invoked in any order !------------------------------------------------------------------------------ (F2(2)<0)) THEN !--------------^--------------------------------------------------------------- !!! fpt - 3665 Program flow is ambiguous. Functions may be invoked in any order !------------------------------------------------------------------------------ ------------------------------------------------------------------------------- Number of statements with ambiguous flow: 1

The code is processed by fpt to resolve the ambiguous flow:

$ fpt t_ambiguous_flow.f90 "%resolve ambiguous flow"

The main program is re-written:

PROGRAM t_ambiguous_flow ! INTEGER*4 f2_return INTEGER*4,EXTERNAL::f1,f2 ! Functions ! f2_return=f2(2) IF ((f1(1)>0) .OR. (f2_return<0)) THEN !------------------------------------^----------------------------------------- !!! fpt - 3669 Ambiguous program flow has been resolved !------------------------------------------------------------------------------ WRITE (*,'("Test succeeded")') ENDIF ! END PROGRAM t_ambiguous_flow

Copyright ©1995 to 2024 Software Validation Ltd. All rights reserved.