It appears that both legacy Pascal compilers I have access to (for the BESM-6) contain a bug: they would happily produce code for
program test(output);(* may have to omit (output) depending on the platform *)
function f: integer; (* entering the function sets R2 as the frame pointer *)
begin f := 7 end; (* assigning 7 to 3(R2) - the value return location *)
begin f := 11 end. (* assigning 11 to 3(R2), where R2 has not been initialized yet *)
Both compilers were derivations from one CDC 6600 version or another, up to the data structures and the order of the subroutines. As the bug is in the machine-independent part, which logic would be transcribed unchanged, I suspect that it would exist in all Pascal implementations derived directly from the same CDC 6600 source by bootstrapping.
Could anyone please verify that on a CDC 6600 emulator, if one exists, or using a Pascal compiler known to be a port of the original?
JFYI:
Newer Pascal compilers written in C using YACC do error out on the test case above.
Free Pascal complains, on line 4, Error: Argument cannot be assigned to
(why "Argument", though?).
UCB Pascal on BSD 2.11 is more lucid, saying function f found where variable required
.
One other I could find online, Turbo Pascal, however, fails with some kind of an internal error: Error: can't cast from 70 to 76 ("11", line 4)
.
func
branch of theselector
routine in the P2 compiler (search for "IMPL. RELAT. ADDR. OF FCT. RESULT
" to find the relevant line) and in the P4 compiler. In the latter there is an error check complaining if a function name is assigned to outside its body. (In adding the check, an oddbegin
-end
pair was left, as noted in Daniels and Pemberton's book about P4).