View Issue Details

IDProjectCategoryView StatusLast Update
0017283FPCCompilerpublic2011-11-30 21:38
ReporterJasper Neumann Assigned ToJonas Maebe  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Product Version2.5.1 
Target Version2.4.2Fixed in Version2.4.4 
Summary0017283: Typecasted result variable is referenced wrong
DescriptionThe output of the following program compiled in Delphi-mode (-Mdelphi -O2 -Os) should output 5 equal numbers. The one where tr_32(result).words is used however gives a wrong result. With the released version 2.4.0 it appears to be correct.

  program test;

  type
    tr_32=packed record
      case integer of
      1: (words: array [0..1] of word);
      2: (low,high: word);
      end;

  procedure f_ref(var l,h:word);
  begin
    l:=1;
    h:=2;
    end;

  function f_test1:longint;
  begin
    result:=$12345678;
    f_ref(tr_32(result).words[0],tr_32(result).words[1]);
    end;

  function f_test2:longint;
  begin
    result:=$12345678;
    f_ref(tr_32(result).low,tr_32(result).high);
    end;

  var
    q: longint;
  begin
    system.writeln($00020001);

    system.writeln(f_test1);
    system.writeln(f_test2);

    q:=$12345678;
    f_ref(tr_32(q).words[0],tr_32(q).words[1]);
    system.writeln(q);
    q:=$12345678;
    f_ref(tr_32(q).low,tr_32(q).high);
    system.writeln(q);
    end.
TagsNo tags attached.
Fixed in Revision15936
FPCOldBugId0
FPCTarget
Attached Files

Relationships

related to 0016163 closedJonas Maebe IE 200301231 with records 

Activities

Jasper Neumann

2010-08-27 12:31

reporter   ~0040519

Last edited: 2010-08-27 14:06

It appears to apply to local variables (i.e. register vars) and to assignments thereof as well.
You may include these test-procs:

  function f_test3:longint;
  var
    q: longint;
  begin
    q:=$12345678;
    f_ref(tr_32(q).words[0],tr_32(q).words[1]);
    result:=q;
    end;

  function f_test4:longint;
  var
    q: longint;
  begin
    q:=$12345678;
    tr_32(q).words[0]:=1;
    tr_32(q).words[1]:=2;
    result:=q;
    end;

and the corresponding calls:

 system.writeln(f_test3);
 system.writeln(f_test4);

I've tested it with the targets and win64.
It seems that the references/assignments are made to local copies thereof, i.e. it is seen as a type conversion instead of a reinterpret type cast.
Delphi-6 treats it like 2.4.0 as a reinterpret type cast.

Jasper Neumann

2010-08-30 10:02

reporter   ~0040623

Last edited: 2010-08-30 10:04

Unfortunately with svn 15919 f_test4 (assignment to typecasted local var) still produces the wrong result, i.e. a different one compared to 2.4.0 and Delphi-6.

Jonas Maebe

2010-08-30 13:28

manager   ~0040642

I didn't notice it because I made a copy/paste error while adding that test to the test program that caused it not to be executed.

Issue History

Date Modified Username Field Change
2010-08-27 12:26 Jasper Neumann New Issue
2010-08-27 12:31 Jasper Neumann Note Added: 0040519
2010-08-27 12:40 Jasper Neumann Note Edited: 0040519
2010-08-27 12:42 Jasper Neumann Note Edited: 0040519
2010-08-27 12:43 Jasper Neumann Note Edited: 0040519
2010-08-27 12:44 Jasper Neumann Note Edited: 0040519
2010-08-27 12:57 Jasper Neumann Note Edited: 0040519
2010-08-27 14:06 Jasper Neumann Note Edited: 0040519
2010-08-27 15:37 Jonas Maebe Status new => assigned
2010-08-27 15:37 Jonas Maebe Assigned To => Jonas Maebe
2010-08-29 19:20 Jonas Maebe Fixed in Revision => 15918
2010-08-29 19:20 Jonas Maebe Status assigned => resolved
2010-08-29 19:20 Jonas Maebe Fixed in Version => 2.5.1
2010-08-29 19:20 Jonas Maebe Resolution open => fixed
2010-08-29 19:20 Jonas Maebe Target Version => 2.4.2
2010-08-30 10:02 Jasper Neumann Status resolved => feedback
2010-08-30 10:02 Jasper Neumann Resolution fixed => reopened
2010-08-30 10:02 Jasper Neumann Note Added: 0040623
2010-08-30 10:04 Jasper Neumann Note Edited: 0040623
2010-08-30 13:28 Jonas Maebe Fixed in Revision 15918 => 15921
2010-08-30 13:28 Jonas Maebe Status feedback => resolved
2010-08-30 13:28 Jonas Maebe Resolution reopened => fixed
2010-08-30 13:28 Jonas Maebe Note Added: 0040642
2010-08-31 14:33 Jonas Maebe Relationship added related to 0016163
2010-09-01 16:51 Jonas Maebe FPCOldBugId => 0
2010-09-01 16:51 Jonas Maebe Fixed in Revision 15921 => 15936
2010-09-01 16:51 Jonas Maebe Fixed in Version 2.5.1 => 2.4.3
2011-05-01 22:31 Marco van de Voort Status resolved => closed
2011-05-01 22:31 Marco van de Voort Fixed in Version 2.4.3 => 2.4.4
2011-05-02 17:32 Marco van de Voort Status closed => resolved
2011-11-30 21:38 Marco van de Voort Status resolved => closed