Régis Cridlig | 3 Apr 2008 19:59
Picon

FPC compiler bug: functional parameter invocation

Hello!

This short program compiles without a warning, but crashes at execution. The compiler is FPC 2.2 on the win32 platform.

program Crashes(input,output);

function B(l:integer):boolean;
begin
        B:=true;
end;

procedure Q(j:integer;function A(l:integer):boolean);

        function E(l:integer):boolean;
        begin
                E := false
        end;

  begin
        if A(j) then
            Q(200,E);
  end;

begin
        Q(100,B);
end.

This is the compiler command:
$ gpc --classic-pascal -g -Wall crashes.p

Here are the stack frames from gdb:

Loaded symbols for /cygdrive/c/WINDOWS/system32/ntdll.dll
Loaded symbols for /cygdrive/c/WINDOWS/system32/kernel32.dll
Loaded symbols for /usr/bin/cygwin1.dll
Loaded symbols for /cygdrive/c/WINDOWS/system32/advapi32.dll
Loaded symbols for /cygdrive/c/WINDOWS/system32/rpcrt4.dll
Loaded symbols for /cygdrive/c/WINDOWS/system32/secur32.dll

Program received signal SIGSEGV, Segmentation fault.
0x0022cc20 in ?? ()
(gdb) bt
#0  0x0022cc20 in ?? ()
#1  0x004010a9 in _p__M0_S1_Q (J=200, A= <at> 0x22cc20) at crashes.p:16
#2  0x004010c6 in _p__M0_S1_Q (J=100, A= <at> 0x401050) at crashes.p:16
#3  0x004010e2 in _p__M0_main_program () at crashes.p:20
#4  0x0040115b in main (argc=1, argv=0x6927b0, envp=0x690090)
    at <implicit code>:22

I am pretty sure that this is a compiler bug, because this program used to run on MacPascal with no error.

-- Regis Cridlig
cridlig <at> gmail.com

Picon

Re: FPC compiler bug: functional parameter invocation

On 3 Apr 2008 at 10:59, Régis Cridlig  wrote:

> Hello!
> 
> This short program compiles without a warning, but crashes at execution.
> The compiler is FPC 2.2 on the win32 platform.
> 
> program Crashes(input,output);
> 
> function B(l:integer):boolean;
> begin
>         B:=true;
> end;
> 
> procedure Q(j:integer;function A(l:integer):boolean);
> 
>         function E(l:integer):boolean;
>         begin
>                 E := false
>         end;
> 
>   begin
>         if A(j) then
>             Q(200,E);
>   end;
> 
> begin
>         Q(100,B);
> end.
> 
> This is the compiler command:
> $ gpc --classic-pascal -g -Wall crashes.p

Which GPC version are you using?

Best regards, The Chief
--------
Prof. Abimbola A. Olowofoyeku (The African Chief) 
web:  http://www.greatchief.plus.com/

Picon

Re: FPC compiler bug: functional parameter invocation

On 3 Apr 2008 at 12:14, Régis Cridlig  wrote:

[...]
> > Here is the output of gpc -v
> >
> > $ gpc -v
> > Reading specs from /usr/lib/gcc/i686-pc-cygwin/3.4.4/specs
> > Configured with:
> > /usr/build/package/orig/test.respin/gcc-3.4.4-3/configure --ver bose
> > --prefix=/usr --exec-prefix=/usr --sysconfdir=/etc --libdir=/usr/lib
> > --libe xecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info
> > --enable-langu ages=c,ada,c++,d,f77,pascal,java,objc --enable-nls
> > --without-included-gettext -- enable-version-specific-runtime-libs
> > --without-x --enable-libgcj --disable-java- awt --with-system-zlib
> > --enable-interpreter --disable-libgcj-debug --enable-thre ads=posix
> > --enable-java-gc=boehm --disable-win32-registry --enable-sjlj-exceptio ns
> > --enable-hash-synchronization --enable-libstdcxx-debug Thread model:
> > posix gpc version 20050331, based on gcc-3.4.4 (cygming special, gdc
> > 0.12, using dmd 0 .125)

That is a very old GPC release. I cannot reproduce the problem on gpc-
20060215 for example.

Best regards, The Chief
--------
Prof. Abimbola A. Olowofoyeku (The African Chief) 
web:  http://www.greatchief.plus.com/

Russell Whitaker | 3 Apr 2008 22:01

Re: FPC compiler bug: functional parameter invocation


On Thu, 3 Apr 2008, Prof A Olowofoyeku (The African Chief) wrote:

> On 3 Apr 2008 at 10:59, Régis Cridlig  wrote:
>
>> Hello!
>>
>> This short program compiles without a warning, but crashes at execution.
>> The compiler is FPC 2.2 on the win32 platform.
                    ^^^^^^^
Hmmm, can you run FPC using gpc as the command?
Anyway, program compiles and runs using latest gpc on linux platform.

Hope this helps
     Russ

>> program Crashes(input,output);
>>
>> function B(l:integer):boolean;
>> begin
>>         B:=true;
>> end;
>>
>> procedure Q(j:integer;function A(l:integer):boolean);
>>
>>         function E(l:integer):boolean;
>>         begin
>>                 E := false
>>         end;
>>
>>   begin
>>         if A(j) then
>>             Q(200,E);
>>   end;
>>
>> begin
>>         Q(100,B);
>> end.
>>
>> This is the compiler command:
>> $ gpc --classic-pascal -g -Wall crashes.p

> Which GPC version are you using?
Régis Cridlig | 3 Apr 2008 23:17
Picon

Re: FPC compiler bug: functional parameter invocation

Actually FPC 2.2 does not compile the code:

$ /cygdrive/c/FPC/2.2.0/bin/i386-win32/fpc.exe -Mmacpas crashes.p

Free Pascal Compiler version 2.2.0 [2007/09/09] for i386
Copyright (c) 1993-2007 by Florian Klaempfl
Target OS: Win32 for i386
Compiling crashes.p
crashes.p(17,20) Error: Incompatible type for arg no. 2: Got "local E(SmallInt):
Boolean", expected "<procedure variable type of function(SmallInt):Boolean;Regis
ter>"
crashes.p(24) Fatal: There were 1 errors compiling module, stopping
Fatal: Compilation aborted
Error: c:\FPC\2.2.0\bin\i386-win32\ppc386.exe returned an error exitcode (normal
 if you did not specify a source file to be compiled)


2008/4/3, Russell Whitaker <russ <at> ashlandhome.net>:


On Thu, 3 Apr 2008, Prof A Olowofoyeku (The African Chief) wrote:

On 3 Apr 2008 at 10:59, Régis Cridlig  wrote:

Hello!

This short program compiles without a warning, but crashes at execution.
The compiler is FPC 2.2 on the win32 platform.
                  ^^^^^^^
Hmmm, can you run FPC using gpc as the command?
Anyway, program compiles and runs using latest gpc on linux platform.

Hope this helps
   Russ


program Crashes(input,output);

function B(l:integer):boolean;
begin
       B:=true;
end;

procedure Q(j:integer;function A(l:integer):boolean);

       function E(l:integer):boolean;
       begin
               E := false
       end;

 begin
       if A(j) then
           Q(200,E);
 end;

begin
       Q(100,B);
end.

This is the compiler command:
$ gpc --classic-pascal -g -Wall crashes.p

Which GPC version are you using?

Régis Cridlig | 3 Apr 2008 23:25
Picon

Re: FPC compiler bug: functional parameter invocation

What is the latest stable release of gpc? I am using gcc version 3.4.4

-- Regis

2008/4/3, Russell Whitaker <russ <at> ashlandhome.net>:


On Thu, 3 Apr 2008, Prof A Olowofoyeku (The African Chief) wrote:

On 3 Apr 2008 at 10:59, Régis Cridlig  wrote:

Hello!

This short program compiles without a warning, but crashes at execution.
The compiler is FPC 2.2 on the win32 platform.
                  ^^^^^^^
Hmmm, can you run FPC using gpc as the command?
Anyway, program compiles and runs using latest gpc on linux platform.

Hope this helps
   Russ


program Crashes(input,output);

function B(l:integer):boolean;
begin
       B:=true;
end;

procedure Q(j:integer;function A(l:integer):boolean);

       function E(l:integer):boolean;
       begin
               E := false
       end;

 begin
       if A(j) then
           Q(200,E);
 end;

begin
       Q(100,B);
end.

This is the compiler command:
$ gpc --classic-pascal -g -Wall crashes.p

Which GPC version are you using?

Picon

Re: FPC compiler bug: functional parameter invocation

On 3 Apr 2008 at 14:25, Régis Cridlig  wrote:

> What is the latest stable release of gpc? 

http://www.math.uni.wroc.pl/~hebisch/gpc/gpc-20070904.tar.bz2

Please write only to the GPC list.

Best regards, The Chief
--------
Prof. Abimbola A. Olowofoyeku (The African Chief) 
web:  http://www.greatchief.plus.com/

Picon

Re: FPC compiler bug: functional parameter invocation

> On 3 Apr 2008 at 14:25, Régis Cridlig  wrote:
> 
> > What is the latest stable release of gpc? 
> 
> http://www.math.uni.wroc.pl/~hebisch/gpc/gpc-20070904.tar.bz2

You can get Cygwin binaries here:
http://gnu-pascal.de/contrib/chief/win32/cygwin/

Best regards, The Chief
--------
Prof. Abimbola A. Olowofoyeku (The African Chief) 
web:  http://www.greatchief.plus.com/

Régis Cridlig | 4 Apr 2008 23:10
Picon

Re: GPC compiler bug: functional parameter invocation

Thank you, I succeeded in installing the latest cygwin build:
gpc-20070904.i686-pc-cygwin.tar.gz

This is the compiler version:
$ gpc -v
Reading specs from /usr/lib/gcc/i686-pc-cygwin/3.4.4/specs
Configured with: ../configure --enable-languages=pascal --enable-threads=posix -
-with-system-zlib --enable-nls --without-included-gettext --enable-interpreter -
-disable-sjlj-exceptions --enable-shared --build=i686-pc-cygwin --host=i686-pc-c
ygwin --target=i686-pc-cygwin --enable-haifa --prefix=/usr : (reconfigured) ../c
onfigure --enable-languages=pascal --enable-threads=posix --with-system-zlib --e
nable-nls --without-included-gettext --enable-interpreter --disable-sjlj-excepti
ons --enable-shared --build=i686-pc-cygwin --host=i686-pc-cygwin --target=i686-p
c-cygwin --enable-haifa --prefix=/usr
Thread model: posix
gpc version 20070904, based on gcc-3.4.4

This is the compilation and execution:
$ gpc crashes.p -Wall -g -o crashes.exe

$ gdb crashes.exe
GNU gdb 6.5.50.20060706-cvs (cygwin-special)
Copyright (C) 2006 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i686-pc-cygwin"...
(gdb) run
Starting program: /cygdrive/c/Documents and Settings/regis.cridlig/My
Documents/Info/Pascal/crashes.exe
Loaded symbols for /cygdrive/c/WINDOWS/system32/ntdll.dll
Loaded symbols for /cygdrive/c/WINDOWS/system32/kernel32.dll
Loaded symbols for /usr/bin/cygwin1.dll
Loaded symbols for /cygdrive/c/WINDOWS/system32/advapi32.dll
Loaded symbols for /cygdrive/c/WINDOWS/system32/rpcrt4.dll
Loaded symbols for /cygdrive/c/WINDOWS/system32/secur32.dll

Program received signal SIGSEGV, Segmentation fault.
0x0022cc20 in ?? ()
(gdb) bt
#0  0x0022cc20 in ?? ()
#1  0x004010a9 in _p__M0_S1_Q (J=200, A= <at> 0x22cc20) at crashes.p:16
#2  0x004010c6 in _p__M0_S1_Q (J=100, A= <at> 0x401050) at crashes.p:16
#3  0x004010e2 in _p__M0_main_program () at crashes.p:20
#4  0x0040115b in main (argc=1, argv=0x6927a0, envp=0x690090)
    at <implicit code>:22
(gdb)

The program source:
$ cat crashes.p
program Crashes(input,output);

function B(l:integer):boolean;
begin
        B:=true;
end;

procedure Q(j:integer;function A(l:integer):boolean);

        function E(l:integer):boolean;
        begin
                E := false
        end;

  begin
        if A(j) then
            Q(200,E);
  end;

begin
        Q(100,B);
end.

What is going wrong?

-- Regis

2008/4/4, Prof A Olowofoyeku (The African Chief) <chiefsoft <at> bigfoot.com>:
> > On 3 Apr 2008 at 14:25, Régis Cridlig  wrote:
>  >
>  > > What is the latest stable release of gpc?
>  >
>  > http://www.math.uni.wroc.pl/~hebisch/gpc/gpc-20070904.tar.bz2
>
>
> You can get Cygwin binaries here:
>  http://gnu-pascal.de/contrib/chief/win32/cygwin/
>
>
>  Best regards, The Chief
>  --------
>  Prof. Abimbola A. Olowofoyeku (The African Chief)
>  web:  http://www.greatchief.plus.com/
>
>
>

Picon

Re: GPC compiler bug: functional parameter invocation

On 4 Apr 2008 at 14:10, Régis Cridlig  wrote:

> Thank you, I succeeded in installing the latest cygwin build:
> gpc-20070904.i686-pc-cygwin.tar.gz
[...]

> What is going wrong?

I don't know. It works perfectly fine here:

bash-3.00 /f/gpc> cat crash.pas
program Crashes(input,output);

function B(l:integer):boolean;
begin
        B:=true;
end;

procedure Q(j:integer;function A(l:integer):boolean);

        function E(l:integer):boolean;
        begin
                E := false
        end;

  begin
        if A(j) then
            Q(200,E);
  end;

begin
        Q(100,B);
end.
bash-3.00 /f/gpc> gpc crash.pas -Wall -g -o crash.exe
bash-3.00 /f/gpc> gdb crash.exe
GNU gdb 6.3.50_2004-12-28-cvs (cygwin-special)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you 
are
welcome to change it and/or distribute copies of it under certain 
conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for 
details.
This GDB was configured as "i686-pc-cygwin"...
(gdb) run
Starting program: /f/gpc/crash.exe

Program exited normally.
(gdb)

Best regards, The Chief
--------
Prof. Abimbola A. Olowofoyeku (The African Chief) 
web:  http://www.greatchief.plus.com/


Gmane