4bsd-f77@utah-cs.UUCP (09/20/84)
From: Donn Seeley <donn@utah-cs.arpa> Subject: F77 does the wrong thing when given both '-O' and '-g' Index: usr.bin/f77/src/f77/f77.c 4.2BSD Description: F77 can't produce objects that are optimized yet are proper to give to the 'dbx' debugger; but it will accept both the optimization and debugger flags without any complaint, leading to core dumps from the peephole optimizer and perhaps other unfortunate symptoms. This problem was brought to my attention by Raleigh Romine at the Center for Seismic Studies. Repeat-By: Try to compile the following program with both the '-O' and '-g' flags (program from Raleigh Romine): ---------------------------------------------------------------- program foo integer a, b a = 1 b = 2 b = b / (a-1) stop end ---------------------------------------------------------------- When you compile the program it will say something like this: ---------------------------------------------------------------- foo.f: MAIN foo: Termination code 132 ---------------------------------------------------------------- You will be left with a core dump of the peephole optimizer. Fix: To fix this problem, I added code to the f77 driver program to detect these conflicting options and choose to use only one of them (the first one it sees, in fact). It could be argued that the proper behavior is to complain and not do a compile at all, but I think there are advantages to doing it this way. Anyone who doesn't like this method can fix f77 to their own taste. The changes are in the main() routine of f77.c: ---------------------------------------------------------------- *** /tmp/,RCSt1029623 Mon Aug 20 21:37:19 1984 --- f77.c Wed Aug 15 18:57:58 1984 *************** *** 185,190 break; case 'O': optimflag = YES; #if TARGET == INTERDATA *loadp++ = "-r"; --- 190,200 ----- break; case 'O': + if(sdbflag) + { + fprintf(diagfile, "-O and -g are incompatible; -O ignored\n"); + break; + } optimflag = YES; #if TARGET == INTERDATA *loadp++ = "-r"; *************** *** 240,245 break; case 'g': strcat(cflags," -g"); sdbflag = YES; goto copyfflag; --- 250,260 ----- break; case 'g': + if(optimflag) + { + fprintf(diagfile, "-g and -O are incompatible; -g ignored\n"); + break; + } strcat(cflags," -g"); sdbflag = YES; goto copyfflag; ---------------------------------------------------------------- When you execute the command 'f77 -O -g foo.f' you now get: ---------------------------------------------------------------- -g and -O are incompatible; -g ignored foo.f: MAIN foo: ---------------------------------------------------------------- Donn Seeley University of Utah CS Dept donn@utah-cs.arpa 40 46' 6"N 111 50' 34"W (801) 581-5668 decvax!utah-cs!donn