Path: utzoo!utgpu!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!rutgers!cmcl2!lanl!dph From: dph@lanl.gov (David Huelsbeck) Newsgroups: comp.lang.fortran Subject: Re: Dubious Fortran Construct Message-ID: <7319@lanl.gov> Date: 19 Dec 88 21:51:46 GMT References: <22994@sgi.SGI.COM> Organization: Los Alamos National Laboratory Lines: 67 From article <22994@sgi.SGI.COM>, by bron@bronze.SGI.COM (Bron Campbell Nelson): > A random question for you all: How does your Fortran compiler > handle branches to a DO loop termination statement? In particular, > in the following program, statement "10" terminates both DO loops, and > is branched to by a statement in the outer DO loop: > > subroutine foo(a, b, n) > real a(n), b(n,n) > do 10 i = 1,n > if (a(i) .eq. 0) goto 10 > do 10 j = 1,n > b(i,j) = 1/a(i) > 10 continue > > return > end > [...How various compilers treat it...Is it really leagal?...] > > -- > Bron Campbell Nelson bron@sgi.com > The opinions expressed are not necessarily those of the author's employer, > are not necessarily those of the author's friends, are not necessarily even > those of the author, and are probably not necessary. This caught my attention because I'm right in the middle of evaluating a number of different static analysis tools for FORTRAN that are supposed to catch this sort of thing. What follows are the results of using one such package on the code you provided. I'm giving only the Toolpack/1 results as it's the only non-comercial package we're looking at right now. -results-of-running-the-original-code-through-the-pfort-portablility-analyzer- ISTLA - Toolpack Static Analyser, Version 1.2 Error: Branch into DO with label - 10 at statement 5 in FOO detected at N@ (token number 51) Error: Invalid forward reference to - 10 at statement 7 in FOO detected at @10 (token number 66) [ISTLA Terminated, 2 parse errors] Tool Termination Status: ERROR Errors detected. Invoke script "getlst" to obtain a listing showing statement and token numbers. ----------------------------------------------------------------------------- The Toolpack/1 source code structurer rufuses to even try to figure out what the programmer intended. This is interesting as we recently found a very similar bug deep down in a large mathematical library that was almost the exact same situation. It was however caused by a typo in the statement labels not by programmer intent. And just to fill out your list of compiler results: SunOS 3.5 f77 says nothing about it. Cray CFT gives a warning Cray CFT77 also gives a warning. David Huelsbeck dph@lanl.gov