Hi Troops,
I've been using Adriaan's recent gpc (gpc436u1) on MacOSX 10.7.2 with Xcode 4.2 and I think I have found a bug. I've attached a rather odd but simple code that can produce a segmentation fault.
This is what I get when running the code through gdb
Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0xc0000140
0x917a4a89 in longcopy ()
(gdb) where
#0 0x917a4a89 in longcopy ()
#1 0x9178ec98 in memmove$VARIANT$sse3x ()
#2 0x000018c0 in Jack (l1=1, u1=4, x_beg=@0xbfffed10, l2=1, u2=4, x_end=@0xbfffecf0) at foo.p:25
#3 0x00001a05 in Jill () at foo.p:48
#4 0x00001a34 in main program () at foo.p:57
#5 0x00001aab in main (argc=1, argv=0xbfffeda0, envp=0xbfffeda8) at foo.p:1
(gdb) quit
It seems that the crash occurs when starting up the procedure Mary. It looks like something to do with a copy of the two arrays x_beg and x_end. If I change the formal declarations to var arrays then the problem does not occur. So I have a workaround but it is not ideal. And almost any other change to the code seems to also remove the seg fault (e.g. use just one case in the case statement, set my_choice=1, make x_beg, x_end array[1..3], add a written anywhere etc.)
Any thoughts or suggestions?
Cheers
Leo Brewin
School of Mathematical Sciences
Monash University
// -----------------------------------------------------------------------------------
// compile this with gpc346u1 leads to a segmentation fault
// gpc -o foo foo.p
program Fred(input,output);
var
my_choice : integer;
// the segmentation fault does not ocurr if the the following two arrayas are passed as var ...
procedure Mary(x_beg : array[l1..u1:integer] of double;
x_end : array[l2..u2:integer] of double);
begin
end;
procedure Jack(var x_beg : array[l1..u1:integer] of double;
var x_end : array[l2..u2:integer] of double);
begin
case my_choice of
1: Mary(x_beg,x_end);
2: Mary(x_beg,x_end);
otherwise ;
end;
end;
procedure Jill;
var
x_0 : array[1..4] of double;
x_1 : array[1..4] of double;
begin
x_0[1]:=0.0e0;
x_0[2]:=0.0e0;
x_0[3]:=0.0e0;
x_0[4]:=0.0e0;
x_1[1]:=0.1e0;
x_1[2]:=0.0e0;
x_1[3]:=0.0e0;
x_1[4]:=0.0e0;
Jack(x_0,x_1);
end;
begin
my_choice:=1; // no problem using this
my_choice:=2; // will cause a seg fault
Jill;
end.