Ok I reproduced it. (compiled with -gh -gt -O1 => but I am not sure it matters

Question: Is it some wrong doing of me? or shall i report it as bug?

In Foo, "s" is supposed to be a copy of "x" => the string should have a ref count of 2, and the modification of x, should make a copy of the string.
afaik the output should be "a" => but it is "X"

You can also set x:='' => which will be random in output

program Project1;

{$mode objfpc}{$H+}

var
  x: String;

procedure Foo(const s: String);
begin
  x[1]:='X';  //  x:='';
  writeln(s);
end;

procedure Bar;
begin
  SetLength(x,1);
  x[1]:= 'a';
end;

{$R *.res}

begin
  Bar;
  Foo(x);
  readln;
end.


On 22/07/2010 03:10, Martin wrote:
I have an odd case (bug ?)
But I am unable to reproduce on a simple example.

Debugger output, and assembler both suggests it's in the compilation.
fpc from trunk a few weeks ago. using -OpPENTIUMM   -O1

one procedure is declared as
    procedure SetFoldState(const AValue: String);

another one calls this as follows
    if FPendingFoldState <> '' then
      SetFoldState(FPendingFoldState);

FPendingFoldState is a variable (String) of the object (both methods belong to the same object too)

Now in SetFoldstate is a line:
  FPendingFoldState:='';

and after this AValue becomes corrupt

The assembler of the calling code (from -al)
# [6541] if FPendingFoldState <> '' then
    movl    -4(%ebp),%eax
    movl    1352(%eax),%eax
    testl    %eax,%eax
    je    .Lj12594
.Ll3371:
# [6542] SetFoldState(FPendingFoldState);
    movl    -4(%ebp),%eax
    movl    1352(%eax),%edx
    movl    -4(%ebp),%eax
    call    SYNEDIT_TCUSTOMSYNEDIT_$__SETFOLDSTATE$ANSISTRING
.Lj12594:

There is no ansistring inc ref (both methods are in the same file, and yes {$H+}

Trying to reproduce in a smaller example did not bring results....

Anyone any idea, if there s any code that could cause such an "optimization" ?

Martin


_______________________________________________
fpc-devel maillist  -  [email protected]
http://lists.freepascal.org/mailman/listinfo/fpc-devel

_______________________________________________
fpc-devel maillist  -  [email protected]
http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply via email to