View Issue Details

IDProjectCategoryView StatusLast Update
0024815FPCCompilerpublic2013-08-02 02:19
ReporterMaxim GanetskyAssigned ToJonas Maebe 
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionno change required 
PlatformWin32OSWindowsOS VersionXP SP3
Product Version2.6.2Product Build 
Target VersionFixed in Version 
Summary0024815: SHR (and probably SHL) behavior inconsistense
DescriptionThe following program

program shrshl;
var
  i: integer;
begin
  i := 55;
  WriteLn(55 shr 32);
  WriteLn(i shr 32);
end.

gives the following output:

0
55

I would expect consistent result in this case.
Additional InformationFPC 2.6.2 win32.
TagsNo tags attached.
Fixed in Revision
FPCOldBugId
FPCTarget
Attached Files
  • shrshl.pas (105 bytes)
    program shrshl;
    var
      i: integer;
    begin
      i := 55;
      WriteLn(55 shr 32);
      WriteLn(i shr 32);
    end.
    shrshl.pas (105 bytes)

Activities

Maxim Ganetsky

2013-08-01 22:42

reporter  

shrshl.pas (105 bytes)
program shrshl;
var
  i: integer;
begin
  i := 55;
  WriteLn(55 shr 32);
  WriteLn(i shr 32);
end.
shrshl.pas (105 bytes)

Jonas Maebe

2013-08-01 22:59

manager   ~0069207

This is for Delphi/TP and x86-nonsensical-behaviour compatibility.

Maxim Ganetsky

2013-08-01 23:52

reporter   ~0069208

But Delphi 7 outputs:

55
55

which is consistent.

Shouldn't this behavior be implemented at least in Delphi mode?

Jonas Maebe

2013-08-02 00:22

manager   ~0069209

FPC evaluates constant expressions always using 64 bit arithmetic in all modes, and has done so since the moment it supported 64 bit arithmetic. If you use WriteLn(int64(i) shr 32);, you'll also get 0 in the second case. Changing that would break backwards FPC compatibility. It also wouldn't surprise me if Delphi XE3 would give the same output as FPC.

Maxim Ganetsky

2013-08-02 02:19

reporter   ~0069210

Got it, thanks.

Issue History

Date Modified Username Field Change
2013-08-01 22:42 Maxim Ganetsky New Issue
2013-08-01 22:42 Maxim Ganetsky File Added: shrshl.pas
2013-08-01 22:59 Jonas Maebe Note Added: 0069207
2013-08-01 22:59 Jonas Maebe Status new => resolved
2013-08-01 22:59 Jonas Maebe Resolution open => no change required
2013-08-01 22:59 Jonas Maebe Assigned To => Jonas Maebe
2013-08-01 23:47 Maxim Ganetsky Status resolved => closed
2013-08-01 23:52 Maxim Ganetsky Note Added: 0069208
2013-08-01 23:52 Maxim Ganetsky Status closed => feedback
2013-08-01 23:52 Maxim Ganetsky Resolution no change required => reopened
2013-08-02 00:22 Jonas Maebe Note Added: 0069209
2013-08-02 00:22 Jonas Maebe Status feedback => resolved
2013-08-02 00:22 Jonas Maebe Resolution reopened => no change required
2013-08-02 02:19 Maxim Ganetsky Note Added: 0069210
2013-08-02 02:19 Maxim Ganetsky Status resolved => closed