Inlining of methods produces wrong assembly code (x86)
Original Reporter info from Mantis: Julian Puhl @jpuhl
-
Reporter name:
Original Reporter info from Mantis: Julian Puhl @jpuhl
- Reporter name:
Description:
The example program passes a variable to a method and it gets modified despite it is not declared as var. Also there are weird asm instructions like (in this case duplicated):
# [34] TestObj.SetKey(i + 1);
movl $2,%eax
movl $2,%eax
Steps to reproduce:
Compile the following program:
program project1;
{$mode objfpc}
{$Inline On} // inline must be turned on for both methods
type
TTest = object // both methods must be inside of object
procedure ModifyValue(Value: Int32); inline;
procedure SetKey(const Value: Int32); inline;
end;
procedure TTest.ModifyValue(Value: Int32);
begin
Value := 1;
end;
procedure TTest.SetKey(const Value: Int32);
var
OriginalValue: Int32;
begin
OriginalValue := Value;
ModifyValue(Value);
WriteLn('Current Value: ', Value); //Outputs 1
WriteLn('Original Value: ', OriginalValue); //Outputs 2
end;
var
TestObj: TTest;
i: Int32;
begin
i := 1;
TestObj.SetKey(i + 1);
ReadLn;
end.
Mantis conversion info:
- Mantis ID: 30015
- Platform: x86
- Version: 3.1.1
- Fixed in version: 3.1.1
- Fixed in revision: 34288 (#70b1b327)