[G5:gpc/testgpc/adriaan] adriaan% cat testsubrange.p
program testsubrange;
type int16 = integer attribute( size = 16); int32 = integer attribute( size = 32); point = record x,y: real end;
var i: int16;
procedure P( size: int32); begin writeln( 'size = ', size) end;
begin i:= 3658; P( i * SizeOf( point)); end.
[G5:gpc/testgpc/adriaan] adriaan% gp testsubrange.p
[G5:gpc/testgpc/adriaan] adriaan% ./testsubrange size = -7008
Any comments ?
Regards,
Adriaan van Os
Running the gpc20060215 Test Suite (based on gcc-3.4.4) under the Red Hat environment, in particular:
Red Hat Enterprise Linux ES release 3 (Taroon Update 6)
as "uname -a" :
Linux tlvqpe 2.4.21-37.ELsmp #1 SMP Sep 7 13:28:55 EDT 2005 i686 i686 i386 GNU/Linux
we got some internal compiler error ...
Test Run By 4grpm on 2006-02-27 11:53:22 Native configuration is i686-pc-linux-gnu (tlvqpe) gpc 20060215, based on gcc-3.4.4, flags: -g -O3 -W -Wall -Wno-unused
=== gpc tests ===
Running target any Running testsuite ...
UNSUPPORTED: aregextest.pas FAIL: fjf932a.pas FAIL: fjf932b.pas
=== gpc Summary ===
# of tests 5057 # of expected passes 5054
TEST fjf932a.pas: p/types.c:1887:find_field: failed assertion `unreachable code' ./fjf932a.pas: In main program: ./fjf932a.pas:73: error: Internal compiler error. Please submit a full bug report to the GPC mailing list gpc@gnu.de. See URL:http://www.gnu-pascal.de/todo.html for details. failed TEST fjf932b.pas: p/types.c:1887:find_field: failed assertion `unreachable code' ./fjf932b.pas: In main program: ./fjf932b.pas:62: error: Internal compiler error. Please submit a full bug report to the GPC mailing list gpc@gnu.de. See URL:http://www.gnu-pascal.de/todo.html for details. ------------------------------------------------------------------------------ Anyway, we tried to build our gpc application: no gpc compilation error found, but we got a segmentation fault when running out application: ------------------------------------------------------------------------------ -bash-2.05b$ ./grfc.exe GRF>cc_gra_sc.smt /out=cc_gra_sc.c Segmentation fault
---------------------------- then trying to use gbd: ----------------------------
-bash-2.05b$ gdb grfc.exe GNU gdb Red Hat Linux (6.3.0.0-1.62rh) 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 "i386-redhat-linux-gnu"...Using host libthread_db library "/lib/tls/libthread_db.so.1".
(gdb) run Starting program: /dktlvqpe1/grfdev/ags/grfpkglnxv12/grfc.exe GRF>cc_gra_sc.smt /out=cc_gra_sc.c Die: DW_TAG_set_type (abbrev = 32, offset = 81793) has children: FALSE attributes: DW_AT_type (DW_FORM_ref4) constant ref: 81665 (adjusted) Dwarf Error: Cannot find type of die [in module /dktlvqpe1/grfdev/ags/grfpkglnxv12/grfc.exe] (gdb) where Die: DW_TAG_set_type (abbrev = 32, offset = 81793) has children: FALSE attributes: DW_AT_type (DW_FORM_ref4) constant ref: 81665 (adjusted) Dwarf Error: Cannot find type of die [in module /dktlvqpe1/grfdev/ags/grfpkglnxv12/grfc.exe] (gdb)
-------------------------------------------------------------------- it seems to me that the our gdb versin (6.3.0.0-1.62rh) isn't compatibel with gpc20060215. Which is the proper gdb version for gpc20060215 based on gcc-3.4.4 ?
Waiting for suggestions.
Thank you very much in advance.
Angelo Fumagalli
Angelo Fumagalli wrote:
Running the gpc20060215 Test Suite (based on gcc-3.4.4) under the Red Hat environment, in particular:
Red Hat Enterprise Linux ES release 3 (Taroon Update 6)
as "uname -a" :
Linux tlvqpe 2.4.21-37.ELsmp #1 SMP Sep 7 13:28:55 EDT 2005 i686 i686 i386 GNU/Linux
we got some internal compiler error ...
Test Run By 4grpm on 2006-02-27 11:53:22 Native configuration is i686-pc-linux-gnu (tlvqpe) gpc 20060215, based on gcc-3.4.4, flags: -g -O3 -W -Wall -Wno-unused
=== gpc tests ===
Running target any Running testsuite ...
UNSUPPORTED: aregextest.pas FAIL: fjf932a.pas FAIL: fjf932b.pas
=== gpc Summary ===
# of tests 5057 # of expected passes 5054
TEST fjf932a.pas: p/types.c:1887:find_field: failed assertion `unreachable code' ./fjf932a.pas: In main program: ./fjf932a.pas:73: error: Internal compiler error. Please submit a full bug report to the GPC mailing list gpc@gnu.de. See URL:http://www.gnu-pascal.de/todo.html for details. failed TEST fjf932b.pas: p/types.c:1887:find_field: failed assertion `unreachable code' ./fjf932b.pas: In main program: ./fjf932b.pas:62: error: Internal compiler error. Please submit a full bug report to the GPC mailing list gpc@gnu.de. See URL:http://www.gnu-pascal.de/todo.html for details.
Thank you for the info. I have too quickly assumed that line 1887 in p/types.c will never be executed. The following should fix the problem:
--- p/types.c 15 Feb 2006 02:03:12 -0000 1.10 +++ p/types.c 27 Feb 2006 21:51:28 -0000 @@ -1884,7 +1884,6 @@ tree field2 = sorted_fields[i], ret; if (DECL_NAME (field2) == component) { - gcc_unreachable (); field = field2; break; }
Anyway, we tried to build our gpc application: no gpc compilation error found, but we got a segmentation fault when running out application:
-bash-2.05b$ ./grfc.exe GRF>cc_gra_sc.smt /out=cc_gra_sc.c Segmentation fault
then trying to use gbd:
-bash-2.05b$ gdb grfc.exe GNU gdb Red Hat Linux (6.3.0.0-1.62rh) 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 "i386-redhat-linux-gnu"...Using host libthread_db library "/lib/tls/libthread_db.so.1".
(gdb) run Starting program: /dktlvqpe1/grfdev/ags/grfpkglnxv12/grfc.exe GRF>cc_gra_sc.smt /out=cc_gra_sc.c Die: DW_TAG_set_type (abbrev = 32, offset = 81793) has children: FALSE attributes: DW_AT_type (DW_FORM_ref4) constant ref: 81665 (adjusted) Dwarf Error: Cannot find type of die [in module /dktlvqpe1/grfdev/ags/grfpkglnxv12/grfc.exe] (gdb) where Die: DW_TAG_set_type (abbrev = 32, offset = 81793) has children: FALSE attributes: DW_AT_type (DW_FORM_ref4) constant ref: 81665 (adjusted) Dwarf Error: Cannot find type of die [in module /dktlvqpe1/grfdev/ags/grfpkglnxv12/grfc.exe] (gdb)
it seems to me that the our gdb versin (6.3.0.0-1.62rh) isn't compatibel with gpc20060215. Which is the proper gdb version for gpc20060215 based on gcc-3.4.4 ?
Waiting for suggestions.
Thank you very much in advance.
Angelo Fumagalli
This in a known problem with gdb -- all released gdb versions have problem with Pascal DWARF-2 debug info. You can try `-gstabs+' to choose stabs debug format. Or you may try patching gdb to get better Pascal DWARF-2 support:
http://www.math.uni.wroc.pl/~hebisch/gpc/gdb-6.3.diff
Waldek Hebisch wrote:
This in a known problem with gdb -- all released gdb versions have problem with Pascal DWARF-2 debug info. You can try `-gstabs+' to choose stabs debug format. Or you may try patching gdb to get better Pascal DWARF-2 support:
Any chance of getting these patches into the gdb tree ?
Regards,
Adriaan van Os
Adriaan van Os wrote:
Waldek Hebisch wrote:
This in a known problem with gdb -- all released gdb versions have problem with Pascal DWARF-2 debug info. You can try `-gstabs+' to choose stabs debug format. Or you may try patching gdb to get better Pascal DWARF-2 support:
Any chance of getting these patches into the gdb tree ?
Things are moving now: gdb maintainers agreed to accept the patch, so now it remains to do paperwork (copyright assignment).
Waldek Hebisch wrote:
Adriaan van Os wrote:
Waldek Hebisch wrote:
This in a known problem with gdb -- all released gdb versions have problem with Pascal DWARF-2 debug info. You can try `-gstabs+' to choose stabs debug format. Or you may try patching gdb to get better Pascal DWARF-2 support:
Any chance of getting these patches into the gdb tree ?
Things are moving now: gdb maintainers agreed to accept the patch, so now it remains to do paperwork (copyright assignment).
Good work !
Regards,
Adriaan van Os
Hi Waldek,
I applied the gdb-6.3.diff to the gdb 6.3 and now the segmentation fault stack is showed correctly. The problem is related to a rewrite operation under trap handler, it seems that the _p_Rewrite procedure received a wrong pointer to file variable.
Pascal source code which generate the segmentation fault: ------------------------------------------------------------------------
procedure tmp_opn_fnm (var p : iop_out_t; var fn: fil_spec_t; var f : text); var fs: string(fil_spec_l); tstr: TString;
procedure TrapRewriteIOErr (Trapped : Boolean); begin if Trapped then begin ioerr := true; tstr := TrappedErrorMessageString; end else begin rewrite (f,fs); end end;
begin fs := fn.body; SetLength(fs,fn.length); TrapExec(TrapRewriteIOErr); {apertura file in output} TrapReset; if (ioerr = true) then begin ios_traperr (tstr); prg_abort; end; p.trnctr := p.trnctr + [iop_opn]; end;
Segmentation Fault Stack frames: -----------------------------------------
(gdb) run Starting program: /dktlvqpe1/grfdev/ags/grfpkglnxv12/grfc.exe GRF> cc_gra_sc.smt /out= cc_gra_sc.c Program received signal SIGSEGV, Segmentation fault. 0x0807ef1a in _p_InternalOpen (f=0x0, FileName=0xbfffe238 '/dktlvqpe1/grfdev/ags/grfpkglnxv12/cc_gra_sc.111', Length=1, BufferSize=1, Mode=Fo_reset) at files.pas:1639 1639 if f^.Status.Untyped then (gdb) where #0 0x0807ef1a in _p_InternalOpen (f=0x0, FileName=0xbfffe238 '/dktlvqpe1/grfdev/ags/grfpkglnxv12/cc_gra_sc.111', Length=1, BufferSize=1, Mode=Fo_reset) at files.pas:1639 #1 0x08084fab in _p_Rewrite (f=0x0, aFileName=@0xbfffe230, FileNameGiven=true, BufferSize=1) at files.pas:3238 #2 0x0804fe9b in Traprewriteioerr.1 () at grfuxtmp.p:85 #3 0x0807311f in Docall.0 () #4 0x080732fb in dosetjmp () #5 0x080731e4 in _p__M4_Trap_S3_Trapexec () #6 0x08050024 in tmp_opn_fnm (p=@0x80a2940, fn=@0xbfffe2f0, f=@0x80a28ec) at grfuxtmp.p:94 #7 0x08051c17 in iniz () at grfcdini.p:169 #8 0x080511ce in mcm_begin () at grfcdpin.p:154 #9 0x0804b100 in main_pre (d_verb='GRF ') at grfdpmai.p:50 #10 0x0804a06c in main program () at grfidt.p:8 #11 0x0804a0e1 in main (argc=1, argv=0xbfffe494, envp=0xbfffe49c) at <implicit code>:14 (gdb) -------------------------------------------------------------------------------------------- it seems that _p_Rewrite function receives a wrong paramenter (0x0) as a reference to a file (f) variable. Does such variable (referenced by TrapExec nesting calls) to be defined with specific attributes?
Thank you very much in advance for your help.
Kind regards.
Angelo Fumagalli _________________________________________________________________
----- Original Message ----- From: "Waldek Hebisch" hebisch@math.uni.wroc.pl To: gpc@gnu.de Sent: Monday, February 27, 2006 10:31 PM Subject: Re: Problem with gpc20060215 under Red Hat Enterprise Linux ES release
Angelo Fumagalli wrote:
Running the gpc20060215 Test Suite (based on gcc-3.4.4) under the Red Hat environment, in particular:
Red Hat Enterprise Linux ES release 3 (Taroon Update 6)
as "uname -a" :
Linux tlvqpe 2.4.21-37.ELsmp #1 SMP Sep 7 13:28:55 EDT 2005 i686 i686 i386 GNU/Linux
we got some internal compiler error ...
Test Run By 4grpm on 2006-02-27 11:53:22 Native configuration is i686-pc-linux-gnu (tlvqpe) gpc 20060215, based on gcc-3.4.4, flags: -g -O3 -W -Wall -Wno-unused
=== gpc tests ===
Running target any Running testsuite ...
UNSUPPORTED: aregextest.pas FAIL: fjf932a.pas FAIL: fjf932b.pas
=== gpc Summary ===
# of tests 5057 # of expected passes 5054
TEST fjf932a.pas: p/types.c:1887:find_field: failed assertion `unreachable code' ./fjf932a.pas: In main program: ./fjf932a.pas:73: error: Internal compiler error. Please submit a full bug report to the GPC mailing list gpc@gnu.de. See URL:http://www.gnu-pascal.de/todo.html for details. failed TEST fjf932b.pas: p/types.c:1887:find_field: failed assertion `unreachable code' ./fjf932b.pas: In main program: ./fjf932b.pas:62: error: Internal compiler error. Please submit a full bug report to the GPC mailing list gpc@gnu.de. See URL:http://www.gnu-pascal.de/todo.html for details.
Thank you for the info. I have too quickly assumed that line 1887 in p/types.c will never be executed. The following should fix the problem:
--- p/types.c 15 Feb 2006 02:03:12 -0000 1.10 +++ p/types.c 27 Feb 2006 21:51:28 -0000 @@ -1884,7 +1884,6 @@ tree field2 = sorted_fields[i], ret; if (DECL_NAME (field2) == component) {
gcc_unreachable (); field = field2; break; }
Anyway, we tried to build our gpc application: no gpc compilation error found, but we got a segmentation fault when running out application:
-bash-2.05b$ ./grfc.exe GRF>cc_gra_sc.smt /out=cc_gra_sc.c Segmentation fault
then trying to use gbd:
-bash-2.05b$ gdb grfc.exe GNU gdb Red Hat Linux (6.3.0.0-1.62rh) 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 "i386-redhat-linux-gnu"...Using host libthread_db library "/lib/tls/libthread_db.so.1".
(gdb) run Starting program: /dktlvqpe1/grfdev/ags/grfpkglnxv12/grfc.exe GRF>cc_gra_sc.smt /out=cc_gra_sc.c Die: DW_TAG_set_type (abbrev = 32, offset = 81793) has children: FALSE attributes: DW_AT_type (DW_FORM_ref4) constant ref: 81665 (adjusted) Dwarf Error: Cannot find type of die [in module /dktlvqpe1/grfdev/ags/grfpkglnxv12/grfc.exe] (gdb) where Die: DW_TAG_set_type (abbrev = 32, offset = 81793) has children: FALSE attributes: DW_AT_type (DW_FORM_ref4) constant ref: 81665 (adjusted) Dwarf Error: Cannot find type of die [in module /dktlvqpe1/grfdev/ags/grfpkglnxv12/grfc.exe] (gdb)
it seems to me that the our gdb versin (6.3.0.0-1.62rh) isn't compatibel with gpc20060215. Which is the proper gdb version for gpc20060215 based on gcc-3.4.4 ?
Waiting for suggestions.
Thank you very much in advance.
Angelo Fumagalli
This in a known problem with gdb -- all released gdb versions have problem with Pascal DWARF-2 debug info. You can try `-gstabs+' to choose stabs debug format. Or you may try patching gdb to get better Pascal DWARF-2 support:
http://www.math.uni.wroc.pl/~hebisch/gpc/gdb-6.3.diff
-- Waldek Hebisch hebisch@math.uni.wroc.pl
Hi Waldek,
I applied the gdb-6.3.diff to the gdb 6.3 and now the segmentation fault stack is showed correctly. The problem is related to a rewrite operation under trap handler, it seems that the _p_Rewrite procedure received a wrong pointer to file variable.
Pascal source code which generate the segmentation fault:
procedure tmp_opn_fnm (var p : iop_out_t; var fn: fil_spec_t; var f : text); var fs: string(fil_spec_l); tstr: TString;
procedure TrapRewriteIOErr (Trapped : Boolean); begin if Trapped then begin ioerr := true; tstr := TrappedErrorMessageString; end else begin rewrite (f,fs); end end;
begin fs := fn.body; SetLength(fs,fn.length); TrapExec(TrapRewriteIOErr); {apertura file in output} TrapReset; if (ioerr = true) then begin ios_traperr (tstr); prg_abort; end; p.trnctr := p.trnctr + [iop_opn]; end;
This source is incomplete
Segmentation Fault Stack frames:
(gdb) run Starting program: /dktlvqpe1/grfdev/ags/grfpkglnxv12/grfc.exe GRF> cc_gra_sc.smt /out= cc_gra_sc.c Program received signal SIGSEGV, Segmentation fault. 0x0807ef1a in _p_InternalOpen (f=0x0, FileName=0xbfffe238 '/dktlvqpe1/grfdev/ags/grfpkglnxv12/cc_gra_sc.111', Length=1, BufferSize=1, Mode=Fo_reset) at files.pas:1639 1639 if f^.Status.Untyped then (gdb) where #0 0x0807ef1a in _p_InternalOpen (f=0x0, FileName=0xbfffe238 '/dktlvqpe1/grfdev/ags/grfpkglnxv12/cc_gra_sc.111', Length=1, BufferSize=1, Mode=Fo_reset) at files.pas:1639 #1 0x08084fab in _p_Rewrite (f=0x0, aFileName=@0xbfffe230, FileNameGiven=true, BufferSize=1) at files.pas:3238 #2 0x0804fe9b in Traprewriteioerr.1 () at grfuxtmp.p:85 #3 0x0807311f in Docall.0 () #4 0x080732fb in dosetjmp () #5 0x080731e4 in _p__M4_Trap_S3_Trapexec () #6 0x08050024 in tmp_opn_fnm (p=@0x80a2940, fn=@0xbfffe2f0, f=@0x80a28ec) at grfuxtmp.p:94 #7 0x08051c17 in iniz () at grfcdini.p:169 #8 0x080511ce in mcm_begin () at grfcdpin.p:154 #9 0x0804b100 in main_pre (d_verb='GRF ') at grfdpmai.p:50 #10 0x0804a06c in main program () at grfidt.p:8 #11 0x0804a0e1 in main (argc=1, argv=0xbfffe494, envp=0xbfffe49c) at <implicit code>:14 (gdb)
it seems that _p_Rewrite function receives a wrong paramenter (0x0) as a reference to a file (f) variable. Does such variable (referenced by TrapExec nesting calls) to be defined with specific attributes?
No, it should just work. Since your source is incomplete I tried to add missing parts to it. However, my completed version works fine. Have you verified that the argument to tmp_opn_fnm is initialized? The backtrace shows non-null value, but the backtrace may be inaccurate, so it is better to print value of your variable.
----- Original Message ----- From: "Waldek Hebisch" hebisch@math.uni.wroc.pl To: gpc@gnu.de Sent: Tuesday, February 28, 2006 10:54 PM Subject: Re: Problem with gpc20060215 under Red Hat Enterprise Linux ES release
Hi Waldek,
I applied the gdb-6.3.diff to the gdb 6.3 and now the segmentation fault stack is showed correctly. The problem is related to a rewrite operation under trap handler, it seems that the _p_Rewrite procedure received a wrong pointer to file variable.
Pascal source code which generate the segmentation fault:
procedure tmp_opn_fnm (var p : iop_out_t; var fn: fil_spec_t; var f : text); var fs: string(fil_spec_l); tstr: TString;
procedure TrapRewriteIOErr (Trapped : Boolean); begin if Trapped then begin ioerr := true; tstr := TrappedErrorMessageString; end else begin rewrite (f,fs); end end;
begin fs := fn.body; SetLength(fs,fn.length); TrapExec(TrapRewriteIOErr); {apertura file in output} TrapReset; if (ioerr = true) then begin ios_traperr (tstr); prg_abort; end; p.trnctr := p.trnctr + [iop_opn]; end;
This source is incomplete
Segmentation Fault Stack frames:
(gdb) run Starting program: /dktlvqpe1/grfdev/ags/grfpkglnxv12/grfc.exe GRF> cc_gra_sc.smt /out= cc_gra_sc.c Program received signal SIGSEGV, Segmentation fault. 0x0807ef1a in _p_InternalOpen (f=0x0, FileName=0xbfffe238 '/dktlvqpe1/grfdev/ags/grfpkglnxv12/cc_gra_sc.111', Length=1, BufferSize=1, Mode=Fo_reset) at files.pas:1639 1639 if f^.Status.Untyped then (gdb) where #0 0x0807ef1a in _p_InternalOpen (f=0x0, FileName=0xbfffe238 '/dktlvqpe1/grfdev/ags/grfpkglnxv12/cc_gra_sc.111', Length=1, BufferSize=1, Mode=Fo_reset) at files.pas:1639 #1 0x08084fab in _p_Rewrite (f=0x0, aFileName=@0xbfffe230, FileNameGiven=true, BufferSize=1) at files.pas:3238 #2 0x0804fe9b in Traprewriteioerr.1 () at grfuxtmp.p:85 #3 0x0807311f in Docall.0 () #4 0x080732fb in dosetjmp () #5 0x080731e4 in _p__M4_Trap_S3_Trapexec () #6 0x08050024 in tmp_opn_fnm (p=@0x80a2940, fn=@0xbfffe2f0, f=@0x80a28ec) at grfuxtmp.p:94 #7 0x08051c17 in iniz () at grfcdini.p:169 #8 0x080511ce in mcm_begin () at grfcdpin.p:154 #9 0x0804b100 in main_pre (d_verb='GRF ') at grfdpmai.p:50 #10 0x0804a06c in main program () at grfidt.p:8 #11 0x0804a0e1 in main (argc=1, argv=0xbfffe494, envp=0xbfffe49c) at <implicit code>:14 (gdb)
it seems that _p_Rewrite function receives a wrong paramenter (0x0) as a reference to a file (f) variable. Does such variable (referenced by TrapExec nesting calls) to be defined with specific attributes?
No, it should just work. Since your source is incomplete I tried to add missing parts to it. However, my completed version works fine. Have you verified that the argument to tmp_opn_fnm is initialized? The backtrace shows non-null value, but the backtrace may be inaccurate, so it is better to print value of your variable.
-- Waldek Hebisch hebisch@math.uni.wroc.pl
Hi Waldek,
The file vriable and the procedure invocation are declared in other units, as:
unit grfeveis; interface const ..... var tmpf : text; tmpf2: text; sym: text; ..... end.
unit grfcdini; interface uses ...,grfeveis; procedure iniz; attribute(n ame='Iniz'); implementation procedure iniz; var fn: file_spec_t; begin ... get_fnmtmp(fn,'.111'); tmp_opn_fnm(tmp2_pkt,fn,tmpf); ... end ... unit grfuxtmp; interface uses GPC,Trap,...,grfeveis; procedure tmp_opn_fnm (var p : iop_out_t; var fn: fil_spec_t; var f : text); attribute(name='Tmp_opn_fnm'); implementation procedure tmp_opn_fnm (var p : iop_out_t; var fn: fil_spec_t; var f : text); var fs: string(fil_spec_l); tstr: TString;
procedure TrapRewriteIOErr (Trapped : Boolean); begin if Trapped then begin ioerr := true; tstr := TrappedErrorMessageString; end else begin rewrite (f,fs); end end;
begin fs := fn.body; SetLength(fs,fn.length); TrapExec(TrapRewriteIOErr); {apertura file in output} TrapReset; if (ioerr = true) then begin ios_traperr (tstr); prg_abort; end; p.trnctr := p.trnctr + [iop_opn]; end; _______________________________________________________________________ The problem is related to the fact that file variable tmpf isn't initialized automatically, I set a beakpoint at the beginning of the program (main_pre) and I saw that some file variables (inp, ou) declared in unother pascal unit (prenv) were properly initialized, but which (tmpf, tmpf2, sym) declared into the grfeveis unit are not initialized. In fact the gdb report is:
(gdb) break main_pre Breakpoint 1 at 0x804b0a7: file grfdpmai.p, line 44. (gdb) run Starting program: /dktlvqpe1/grfdev/ags/grfpkglnxv12/grfc.exe
Breakpoint 1, main_pre (d_verb='GRF ') at grfdpmai.p:44 44 if not(prg_host in [1,3]) then cli_setraw; (gdb) where #0 main_pre (d_verb='GRF ') at grfdpmai.p:44 #1 0x0804a06c in main program () at grfidt.p:8 #2 0x0804a0e1 in main (argc=1, argv=0xbfffb4d4, envp=0xbfffb4dc) at <implicit code>:14 (gdb) print _p__M5_Prenv_S7_Inp $1 = {_p_File_ = 0x9f83080} (gdb) print _p__M5_Prenv_S9_Ou $2 = {_p_File_ = 0x9f7f000} (gdb) print _p__M8_Grfeveis_S2_Tmpf2 $3 = {_p_File_ = 0x0} (gdb) print _p__M8_Grfeveis_S3_Tmpf $4 = {_p_File_ = 0x0} (gdb) print _p__M8_Grfeveis_S4_Sym $6 = {_p_File_ = 0x0} (gdb) __________________________________________
The question is: Why such file variables aren't initialized automatically at the program start? I need to call some internal gpc function to force the proper initialization?
Thank you very much in advance for your help.
Kind regards.
Angelo Fumagalli
Angelo Fumagalli wrote:
The file vriable and the procedure invocation are declared in other units, as:
unit grfeveis; interface const ..... var tmpf : text; tmpf2: text; sym: text; ..... end.
<Incomplete source skipped>
The problem is related to the fact that file variable tmpf isn't initialized automatically, I set a beakpoint at the beginning of the program (main_pre) and I saw that some file variables (inp, ou) declared in unother pascal unit (prenv) were properly initialized, but which (tmpf, tmpf2, sym) declared into the grfeveis unit are not initialized. In fact the gdb report is:
(gdb) break main_pre Breakpoint 1 at 0x804b0a7: file grfdpmai.p, line 44. (gdb) run Starting program: /dktlvqpe1/grfdev/ags/grfpkglnxv12/grfc.exe
Breakpoint 1, main_pre (d_verb='GRF ') at grfdpmai.p:44 44 if not(prg_host in [1,3]) then cli_setraw; (gdb) where #0 main_pre (d_verb='GRF ') at grfdpmai.p:44 #1 0x0804a06c in main program () at grfidt.p:8 #2 0x0804a0e1 in main (argc=1, argv=0xbfffb4d4, envp=0xbfffb4dc) at <implicit code>:14 (gdb) print _p__M5_Prenv_S7_Inp $1 = {_p_File_ = 0x9f83080} (gdb) print _p__M5_Prenv_S9_Ou $2 = {_p_File_ = 0x9f7f000} (gdb) print _p__M8_Grfeveis_S2_Tmpf2 $3 = {_p_File_ = 0x0} (gdb) print _p__M8_Grfeveis_S3_Tmpf $4 = {_p_File_ = 0x0} (gdb) print _p__M8_Grfeveis_S4_Sym $6 = {_p_File_ = 0x0} (gdb) __________________________________________
The question is: Why such file variables aren't initialized automatically at the program start? I need to call some internal gpc function to force the proper initialization?
Thank you very much in advance for your help.
The variable should be initialized automatically. The rules are: 1) You have to give explict import or uses clause. It does not matter if import is direct or indirect, but if you want to use something from `grfeveis' then there must be a dependency chain from main program to `grfeveis'. 2) Variables in a single module are initialized sequentially. 3) You should not depend on the order in which modules are initialized. It is not arbitrary, but may change in the future.
Typical reason for uninitialized variables are missing dependencies (uses clauses). Sources that you posted are incomplete, so I can not tell more.
OK Waldek, thanks,
I added the grfeveis unit to uses directive into the main program and the problew has been soved, in fact, now, file variables defined into grfeveis are initialized correctly.
Ciao,
Angelo Fumagalli _______________________
----- Original Message ----- From: "Waldek Hebisch" hebisch@math.uni.wroc.pl To: gpc@gnu.de Sent: Wednesday, March 01, 2006 10:10 PM Subject: Re: Problem with gpc20060215 under Red Hat Enterprise Linux ES release
Angelo Fumagalli wrote:
The file vriable and the procedure invocation are declared in other units, as:
unit grfeveis; interface const ..... var tmpf : text; tmpf2: text; sym: text; ..... end.
<Incomplete source skipped>
The problem is related to the fact that file variable tmpf isn't initialized automatically, I set a beakpoint at the beginning of the program (main_pre) and I saw that some file variables (inp, ou) declared in unother pascal unit (prenv) were properly initialized, but which (tmpf, tmpf2, sym) declared into the grfeveis unit are not initialized. In fact the gdb report is:
(gdb) break main_pre Breakpoint 1 at 0x804b0a7: file grfdpmai.p, line 44. (gdb) run Starting program: /dktlvqpe1/grfdev/ags/grfpkglnxv12/grfc.exe
Breakpoint 1, main_pre (d_verb='GRF ') at grfdpmai.p:44 44 if not(prg_host in [1,3]) then cli_setraw; (gdb) where #0 main_pre (d_verb='GRF ') at grfdpmai.p:44 #1 0x0804a06c in main program () at grfidt.p:8 #2 0x0804a0e1 in main (argc=1, argv=0xbfffb4d4, envp=0xbfffb4dc) at <implicit code>:14 (gdb) print _p__M5_Prenv_S7_Inp $1 = {_p_File_ = 0x9f83080} (gdb) print _p__M5_Prenv_S9_Ou $2 = {_p_File_ = 0x9f7f000} (gdb) print _p__M8_Grfeveis_S2_Tmpf2 $3 = {_p_File_ = 0x0} (gdb) print _p__M8_Grfeveis_S3_Tmpf $4 = {_p_File_ = 0x0} (gdb) print _p__M8_Grfeveis_S4_Sym $6 = {_p_File_ = 0x0} (gdb) __________________________________________
The question is: Why such file variables aren't initialized automatically at the program start? I need to call some internal gpc function to force the proper initialization?
Thank you very much in advance for your help.
The variable should be initialized automatically. The rules are:
- You have to give explict import or uses clause. It does not matter if
import is direct or indirect, but if you want to use something from `grfeveis' then there must be a dependency chain from main program to `grfeveis'. 2) Variables in a single module are initialized sequentially. 3) You should not depend on the order in which modules are initialized. It is not arbitrary, but may change in the future.
Typical reason for uninitialized variables are missing dependencies (uses clauses). Sources that you posted are incomplete, so I can not tell more.
-- Waldek Hebisch hebisch@math.uni.wroc.pl
On Mon, 27 Feb 2006, Adriaan van Os wrote:
[G5:gpc/testgpc/adriaan] adriaan% cat testsubrange.p
program testsubrange;
type int16 = integer attribute( size = 16); int32 = integer attribute( size = 32); point = record x,y: real end;
var i: int16;
procedure P( size: int32); begin writeln( 'size = ', size) end;
begin i:= 3658; P( i * SizeOf( point)); end.
[G5:gpc/testgpc/adriaan] adriaan% gp testsubrange.p
[G5:gpc/testgpc/adriaan] adriaan% ./testsubrange size = -7008
Any comments ? Regards,
Adriaan van Os
Simplifying your program I observe the same problem:
PROGRAM testsubrange; var i: ShortInt; {signed 16 bit integer} j: SizeType; {unsigned 32 bit word} point : record x,y: real end; {takes 16 bytes} begin i:= 3658; j:= 16; writeln ('result1 = ', i*j); {58528, OK} writeln ('result2 = ', i*SizeOf(point)); {-7008, wrong} end.
My suspicion is that for calculating the second expression the compiler uses wrong operand size (16? bit) instead of 32 (function SizeOf returns a value of SizeType). BTW: -7008+2^16 = 58528
Hope that may help.
Ernst-Ludwig
Ernst-Ludwig Bohne wrote:
On Mon, 27 Feb 2006, Adriaan van Os wrote:
[G5:gpc/testgpc/adriaan] adriaan% cat testsubrange.p
program testsubrange;
type int16 = integer attribute( size = 16); int32 = integer attribute( size = 32); point = record x,y: real end;
var i: int16;
procedure P( size: int32); begin writeln( 'size = ', size) end;
begin i:= 3658; P( i * SizeOf( point)); end.
[G5:gpc/testgpc/adriaan] adriaan% gp testsubrange.p
[G5:gpc/testgpc/adriaan] adriaan% ./testsubrange size = -7008
Any comments ? Regards,
Adriaan van Os
Simplifying your program I observe the same problem:
PROGRAM testsubrange; var i: ShortInt; {signed 16 bit integer} j: SizeType; {unsigned 32 bit word} point : record x,y: real end; {takes 16 bytes} begin i:= 3658; j:= 16; writeln ('result1 = ', i*j); {58528, OK} writeln ('result2 = ', i*SizeOf(point)); {-7008, wrong} end.
My suspicion is that for calculating the second expression the compiler uses wrong operand size (16? bit) instead of 32 (function SizeOf returns a value of SizeType). BTW: -7008+2^16 = 58528
Basically speaking gpc performs operations up to precision of more precise argument. When computing `i*j' gpc notes that `j' is more precise (usually `SizeType' has 32-bit or better precision) and uses its precision to perform multiplication. In the second case (`i*SizeOf(point)') gpc notes that `SizeOf(point)' is a constant and that this constant fits into 16-bits, and uses only 16-bit precision for multiplication.
Also, ATM gpc has no runtime overflow checking, so one silently gets incorrect result.
You may ask gpc is "correct". That is samewhat tricky question. Namely, gpc applies rules, and AFAICS it applies exactly the rules which were intended by programers coding them (I think Frank changed rules to the current ones). So the real question is if the rules are good ("correct"). Now, it would be nice to have rules which always give mathematically correct result (in other words, use precision big enough to avoid any possibility of overflow). But this is impossible in currect gpc: we have maximal precision and we can not go beyond that. Another possibility is to give correct results if possible and use maximal precision otherwise. However, the maximal precision is really a "double precision". Namely, gpc can perform arithmetic at twice of normal machine precision. Which is nice, but expensive: such operation may be significantly slower then normal operations. ATM gpc is rather dumb when predicting needed precision, so even if arguments are small gpc may think that maximal precision is needed. Also, even maximal precision may still give you wrong results.
So, there is rather nasty compromise between correctness and speed. I usuallt go for correctness. However, here speed penalty may be very significant (about 3 times when done right, but may be as high as 20 if maximal precision is slow). So, having optional overflow checking looks more attractive: one can test with overflow checking on and then release with checking off.
One could also try to invent some compromise rules, for example trying to use "most precise fast arithmetic", but doint it right is tricky. Also, there are issues of compatibility (spurious overflows in bitwise operations...).
BTW: I do not plan work on this in near future. Still, if some consesus appears we may implement it when time comes.
Waldek Hebisch wrote:
Ernst-Ludwig Bohne wrote:
Simplifying your program I observe the same problem:
PROGRAM testsubrange; var i: ShortInt; {signed 16 bit integer} j: SizeType; {unsigned 32 bit word} point : record x,y: real end; {takes 16 bytes} begin i:= 3658; j:= 16; writeln ('result1 = ', i*j); {58528, OK} writeln ('result2 = ', i*SizeOf(point)); {-7008, wrong} end.
My suspicion is that for calculating the second expression the compiler uses wrong operand size (16? bit) instead of 32 (function SizeOf returns a value of SizeType). BTW: -7008+2^16 = 58528
Basically speaking gpc performs operations up to precision of more precise argument. When computing `i*j' gpc notes that `j' is more precise (usually `SizeType' has 32-bit or better precision) and uses its precision to perform multiplication. In the second case (`i*SizeOf(point)') gpc notes that `SizeOf(point)' is a constant and that this constant fits into 16-bits, and uses only 16-bit precision for multiplication.
Also, ATM gpc has no runtime overflow checking, so one silently gets incorrect result.
You may ask gpc is "correct". That is samewhat tricky question. Namely, gpc applies rules, and AFAICS it applies exactly the rules which were intended by programers coding them (I think Frank changed rules to the current ones). So the real question is if the rules are good ("correct"). Now, it would be nice to have rules which always give mathematically correct result (in other words, use precision big enough to avoid any possibility of overflow). But this is impossible in currect gpc: we have maximal precision and we can not go beyond that. Another possibility is to give correct results if possible and use maximal precision otherwise. However, the maximal precision is really a "double precision". Namely, gpc can perform arithmetic at twice of normal machine precision. Which is nice, but expensive: such operation may be significantly slower then normal operations. ATM gpc is rather dumb when predicting needed precision, so even if arguments are small gpc may think that maximal precision is needed. Also, even maximal precision may still give you wrong results.
So, there is rather nasty compromise between correctness and speed. I usuallt go for correctness. However, here speed penalty may be very significant (about 3 times when done right, but may be as high as 20 if maximal precision is slow). So, having optional overflow checking looks more attractive: one can test with overflow checking on and then release with checking off.
Yes, that's my reasoning too. I've always had overflow checking in mind (even though I also cannot work on it in the near future). And, of course, there should always be a way to force evaluation in higher precision if needed. In GPC/BP modes, type-casting one operand is a common way (also common in BP code). In ISO mode, we don't have such a way, AFAICS. OTOH, ISO doesn't support types larger than `Integer' anyway.
One could also try to invent some compromise rules, for example trying to use "most precise fast arithmetic", but doint it right is tricky.
And it makes testing for several targets tricky, because they can differ about which types are fast -- not only relating to size, but also to Pascal types, e.g. MedInt may be fast or not.
However, I do see a GPC problem here. According to ISO Pascal, operations should not be done on smaller than Integer types. GPC followed this rule for `+' and `-', but not for other operations. The attached patch fixes this. It doesn't cause any regressions in the test suite on IA32 (but I haven't tested on other systems yet, and type size changes are always somewhat critical -- that's why I included 3 versions of these test programs, even if rather similar). Whether SizeOf gives a result of type SizeType or another type is quite irrelevant as GPC mostly ignores types of integer constants.
Frank
Frank Heckenbach wrote:
However, I do see a GPC problem here. According to ISO Pascal, operations should not be done on smaller than Integer types. GPC followed this rule for `+' and `-', but not for other operations. The attached patch fixes this. It doesn't cause any regressions in the test suite on IA32 (but I haven't tested on other systems yet, and type size changes are always somewhat critical -- that's why I included 3 versions of these test programs, even if rather similar). Whether SizeOf gives a result of type SizeType or another type is quite irrelevant as GPC mostly ignores types of integer constants.
Works without regressions on AMD-64.
Frank Heckenbach wrote:
One could also try to invent some compromise rules, for example trying to use "most precise fast arithmetic", but doint it right is tricky.
And it makes testing for several targets tricky, because they can differ about which types are fast -- not only relating to size, but also to Pascal types, e.g. MedInt may be fast or not.
However, I do see a GPC problem here. According to ISO Pascal, operations should not be done on smaller than Integer types. GPC followed this rule for `+' and `-', but not for other operations. The attached patch fixes this. It doesn't cause any regressions in the test suite on IA32 (but I haven't tested on other systems yet, and type size changes are always somewhat critical -- that's why I included 3 versions of these test programs, even if rather similar).
Thanks for the patch ! It fixes the problem and doesn't cause any regressions on powerpc-apple-darwin7.
Whether SizeOf gives a result of type SizeType or another type is quite irrelevant as GPC mostly ignores types of integer constants.
But it also ignores explicit typecasts on integer constants (see below).
Basically speaking gpc performs operations up to precision of more precise argument. When computing `i*j' gpc notes that `j' is more precise (usually `SizeType' has 32-bit or better precision) and uses its precision to perform multiplication. In the second case (`i*SizeOf(point)') gpc notes that `SizeOf(point)' is a constant and that this constant fits into 16-bits, and uses only 16-bit precision for multiplication.
Also, ATM gpc has no runtime overflow checking, so one silently gets incorrect result.
You may ask gpc is "correct". That is samewhat tricky question. Namely, gpc applies rules, and AFAICS it applies exactly the rules which were intended by programers coding them (I think Frank changed rules to the current ones). So the real question is if the rules are good ("correct"). Now, it would be nice to have rules which always give mathematically correct result (in other words, use precision big enough to avoid any possibility of overflow). But this is impossible in currect gpc: we have maximal precision and we can not go beyond that. Another possibility is to give correct results if possible and use maximal precision otherwise. However, the maximal precision is really a "double precision". Namely, gpc can perform arithmetic at twice of normal machine precision. Which is nice, but expensive: such operation may be significantly slower then normal operations. ATM gpc is rather dumb when predicting needed precision, so even if arguments are small gpc may think that maximal precision is needed. Also, even maximal precision may still give you wrong results.
So, there is rather nasty compromise between correctness and speed. I usuallt go for correctness. However, here speed penalty may be very significant (about 3 times when done right, but may be as high as 20 if maximal precision is slow). So, having optional overflow checking looks more attractive: one can test with overflow checking on and then release with checking off.
Yes, that's my reasoning too. I've always had overflow checking in mind (even though I also cannot work on it in the near future).
Then, I kindly ask to put the following program (with overflow checking) in p/test/todo (to be implemented at some point in the future).
program testsubrange;
type int32 = integer attribute( size = 32); int64 = integer attribute( size = 64); millionbytes = array[ 1..1000000] of byte;
var i: int32;
procedure P( size: int64); begin WriteLn ('size = ', size) end;
begin i:= 3658; P( i * SizeOf( millionbytes)); end.
And, of course, there should always be a way to force evaluation in higher precision if needed. In GPC/BP modes, type-casting one operand is a common way (also common in BP code). In ISO mode, we don't have such a way, AFAICS. OTOH, ISO doesn't support types larger than `Integer' anyway.
But typecasting the SizeOf operand doesn't work, e.g.
program testsubrange;
type int32 = integer attribute( size = 32); int64 = integer attribute( size = 64); millionbytes = array[ 1..1000000] of byte;
var i: int32;
procedure P( size: int64); begin if size = 3658000000 then WriteLn ('OK') else WriteLn ('failed: ', 'size = ', size) end;
begin i:= 3658; P( i * int64( SizeOf( millionbytes))); end.
Typecasting the variable operand (i) does work.
Regards,
Adriaan van Os
Whether SizeOf gives a result of type SizeType or another type is quite irrelevant as GPC mostly ignores types of integer constants.
But it also ignores explicit typecasts on integer constants (see below).
Another idea. If value type-casts are ignored by the compiler for integer constants, then maybe a warning can be issued by the compiler "Ignored constant value type-cast".
Regards,
Adriaan van Os