try/except block in inline function causes execution to jump to system finalization
Original Reporter info from Mantis: sethdgrover@gmail.com
-
Reporter name: Seth Grover
Original Reporter info from Mantis: sethdgrover@gmail.com
- Reporter name: Seth Grover
Description:
See "steps to reproduce" to see an example of how to reproduce the problem. If there is an "inline" function with a try/except block, the call to fpc_catches after fpc_popaddrstack causes execution to bypass the rest of the function/program and skip straight to the FinalizeUnits call in system.
I have tested this in 2.4.0 as well as the 2.4.2 release candidate branch on i386 Linux and it reproduces in both environments. Compiling for x86_64 does not seem to reproduce the bug.
I know that having a try/except block in an inlined function kind of defeats the purpose of inlining, but if it can't be done correctly then the function should be automatically not inlined by the compiler and a warning generated during compilation.
Steps to reproduce:
Here are the files for reproducing this bug:
project1.lpr
===============================================================
program project1;
{mode objfpc}{
H+}
uses
Unit1;
function TestInlineExcept : boolean; inline;
begin
try
result := true;
except
result := false;
end;
end;
begin
writeln('before');
if TestInlineExcept then begin
writeln('TestInlineExcept: true');
end else begin
writeln('TestInlineExcept: false');
end;
writeln('after');
end.
===============================================================
unit1.pas
===============================================================
unit Unit1;
{mode objfpc}{
H+}
interface
uses
Classes, SysUtils;
implementation
initialization
writeln('unit 1 init');
finalization
writeln('unit 1 fini');
end.
===============================================================
Compile the project:
$ fpc -Scghi -Pi386 -O2 -oproject1 project1.lpr
Actual output:
$ ./project1
unit 1 init
before
unit 1 fini
Expected output:
$ ./project1
unit 1 init
before
TestInlineExcept: true
after
unit 1 fini
Mantis conversion info:
- Mantis ID: 16874
- OS: Linux
- OS Build: Ubuntu 10.04
- Platform: i386
- Version: 2.4.0
- Fixed in version: 2.6.0
- Fixed in revision: 15535 (#229cbca0)
- Target version: 2.5.1