[fpc-pascal] nostackframe -- possible to create faulty code?

Bernd prof7bit at googlemail.com
Tue Dec 13 15:42:31 CET 2011


Is it thoretically possible to make an otherwise perfectly working
program crash with access violation only because I used the
nostackframe modifier on a nested procedure?

I have observed this twice now, but I can't reliably reproduce it.

function TBoard.MoveGen(Index: Integer): Integer;
var
  Move: TMove;
  Index: Integer;
  [...] a lot more variables

  procedure AddMove; nostackframe;
  begin
    MoveBuffer[Index] := Move;     // MoveBuffer belongs to TBoard
    Inc(Index);
  end;

  [...] // a lot more lines of complicated code and a few more nested
procedures (but NO inline asm anywhere)

end;

If I declare the nested function inline then I haven't observed any
problems (so far) and also with nostackframe sometimes it works but
sometimes it will crash (depending on seemingly unrelated changes in
other code) (I have not yet debugged where exactly It crashes, I'll do
this the next time it happens).

But whatever it is: shouldn't this AddMove procedure here be perfectly
allowed to be nostackframe because it has no own local variables and
no arguments? Shouldn't it even be impossible to generate faulty code,
by adding nostackframe even if it is not allowed for some reasons and
rather get a compiler error or warning instead? (PS: *if* it works (if
it does not crash) then it works correctly (finds all moves, no
errors), so it seems there are no logical errors in the code and also
activated range check etc. gives no errors).

Bernd



More information about the fpc-pascal mailing list