4bsd-f77@utah-cs.UUCP (4.2 BSD f77 bug reports) (09/02/84)
From: Donn Seeley <donn@utah-cs.arpa> Subject: Parentheses aren't allowed in certain declarations in f77 Index: usr.bin/f77/src/f77pass1/gram.expr 4.2BSD Description: The f77 standard permits the length specification of a CHARACTER variable in a declaration to be a constant expression, not just a constant, but the compiler doesn't allow it when the optimizer is on. Jerry Berkman found and fixed this bug. Repeat-By: Try to compile the following program with the optimizer on (program from Jerry Berkman): ---------------------------------------------------------------- c get syntax error: "length must be a positive integer constant" character str*( 5 ) str = 'hi there' print *, str end ---------------------------------------------------------------- The compiler complains and dies: ---------------------------------------------------------------- chdec.f: MAIN: Error on line 2 of chdec.f: Declaration error length must be a positive integer constant Error. No assembly. ---------------------------------------------------------------- Fix: The problem is the useless OPPAREN operator which gets generated for parenthesized expressions when the optimizer is on. I still haven't figured out why it is there, but it is clearly pointless in declarations so the following simple change to gram.expr turns it off: ---------------------------------------------------------------- *** /tmp/,RCSt1028940 Mon Aug 20 18:01:03 1984 --- gram.expr Sat Aug 4 21:28:00 1984 *************** *** 12,18 expr: uexpr | SLPAR expr SRPAR ! { if (optimflag) $$ = mkexpr(OPPAREN, $2, ENULL); else $$ = $2; } --- 26,32 ----- expr: uexpr | SLPAR expr SRPAR ! { if (optimflag && parstate != INDCL) $$ = mkexpr(OPPAREN, $2, ENULL); else $$ = $2; } ---------------------------------------------------------------- If you are annoyed by the lack of punctuation in f77's error message (as Jerry was), there is a fix for that, too. Make the following changes to dclerr() and execerr() in error.c: ---------------------------------------------------------------- *** /tmp/,RCSt1028948 Mon Aug 20 18:03:12 1984 --- error.c Mon Aug 20 17:57:43 1984 *************** *** 105,111 err(buff); } else ! errstr("Declaration error %s", s); } --- 117,123 ----- err(buff); } else ! errstr("Declaration error: %s", s); } *************** *** 115,121 { char buf1[100], buf2[100]; ! sprintf(buf1, "Execution error %s", s); sprintf(buf2, buf1, n); err(buf2); } --- 127,133 ----- { char buf1[100], buf2[100]; ! sprintf(buf1, "Execution error: %s", s); sprintf(buf2, buf1, n); err(buf2); } ---------------------------------------------------------------- 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