View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0036389 | FPC | Compiler | public | 2019-12-02 09:49 | 2019-12-09 23:01 |
Reporter | Dmitry Belkevich_2 | Assigned To | Florian | ||
Priority | normal | Severity | minor | Reproducibility | always |
Status | resolved | Resolution | fixed | ||
Platform | 64x | OS | Windows | OS Version | 10 |
Product Version | 3.3.1 | Product Build | 62316M | ||
Target Version | Fixed in Version | 3.3.1 | |||
Summary | 0036389: compile code with error "Error: Asm: word value exceeds bounds 65536" | ||||
Description | Try to comile a code and get such error: unit1.pas(46,17) Error: Asm: word value exceeds bounds 65536 In some other builds and Delphi compiled without errors | ||||
Steps To Reproduce | Just compile the code: function Correct(TempInt: integer; Value: word): word; inline; begin if TempInt = 32768 then Result := Value - TempInt else Result := 65536 - Value; end; procedure TForm1.Button1Click(Sender: TObject); var Arr: array of word; begin Arr[0] := Correct(Temp, Arr[0]); end; | ||||
Tags | No tags attached. | ||||
Fixed in Revision | 43670 | ||||
FPCOldBugId | |||||
FPCTarget | - | ||||
Attached Files |
|
|
unable reproduce on x86_64 linux It's not clear what variable "Temp" is. Maybe there is hidden source of error. |
|
Can you change up the project slightly so it's obvious what Temp is? Thanks. |
|
Confirmed on i386-win32 using internal assembler. amd64 is indeed fine. The type of Temp doesn't matter, can be any ordinal type, but not a literal. For example: procedure TForm1.Button1Click(Sender: TObject); var Arr: array of word; Temp: integer; begin Temp:= 42; Arr[0] := Correct(Temp, Arr[0]); end; |
|
confirm on x86_64 linux. Internal assembler and {$r-} {$q-} error on lines: Result := 65536 - Value; Arr[0] := Correct(Temp, Arr[0]); |
|
Can you confirm if this patch fixes the problem? The bug was with the "MovOpMov2MovOp" optimisation. The check to see if the value was in range mixed up bits with bytes (topsize2memsize converts an operand size into a bit length) and so ultimately was never performed.
i36389-fix.patch (1,164 bytes)
Index: compiler/x86/aoptx86.pas =================================================================== --- compiler/x86/aoptx86.pas (revision 43626) +++ compiler/x86/aoptx86.pas (working copy) @@ -2247,8 +2247,8 @@ debug_op2str(taicpu(hp2).opcode)+debug_opsize2str(taicpu(hp2).opsize)+')',p); { limit size of constants as well to avoid assembler errors, but check opsize to avoid overflow when left shifting the 1 } - if (taicpu(p).oper[0]^.typ=top_const) and (topsize2memsize[taicpu(hp2).opsize]<=4) then - taicpu(p).oper[0]^.val:=taicpu(p).oper[0]^.val and ((qword(1) shl (topsize2memsize[taicpu(hp2).opsize]*8))-1); + if (taicpu(p).oper[0]^.typ=top_const) and (topsize2memsize[taicpu(hp2).opsize]<=63) then + taicpu(p).oper[0]^.val:=taicpu(p).oper[0]^.val and ((qword(1) shl topsize2memsize[taicpu(hp2).opsize])-1); taicpu(hp1).changeopsize(taicpu(hp2).opsize); taicpu(p).changeopsize(taicpu(hp2).opsize); if taicpu(p).oper[0]^.typ=top_reg then |
|
yep, patch fixes linux x86_64 |
|
Excellent - just need confirmation on the i386 platforms and I think we're good to merge. |
|
Thanks, applied (tested also on i386-linux). |
Date Modified | Username | Field | Change |
---|---|---|---|
2019-12-02 09:49 | Dmitry Belkevich_2 | New Issue | |
2019-12-02 12:18 | Marģers | Note Added: 0119579 | |
2019-12-02 12:31 | J. Gareth Moreton | Note Added: 0119581 | |
2019-12-02 14:05 | Martok | Note Added: 0119582 | |
2019-12-02 14:58 | Marģers | Note Added: 0119585 | |
2019-12-02 15:00 | Marģers | Note Edited: 0119585 | View Revisions |
2019-12-02 15:28 | J. Gareth Moreton | File Added: i36389-fix.patch | |
2019-12-02 15:28 | J. Gareth Moreton | Note Added: 0119586 | |
2019-12-02 15:29 | J. Gareth Moreton | Status | new => feedback |
2019-12-02 15:29 | J. Gareth Moreton | FPCTarget | => - |
2019-12-02 18:42 | Marģers | Note Added: 0119592 | |
2019-12-02 18:55 | J. Gareth Moreton | Note Added: 0119593 | |
2019-12-02 18:55 | J. Gareth Moreton | Note Edited: 0119593 | View Revisions |
2019-12-09 23:01 | Florian | Assigned To | => Florian |
2019-12-09 23:01 | Florian | Status | feedback => resolved |
2019-12-09 23:01 | Florian | Resolution | open => fixed |
2019-12-09 23:01 | Florian | Fixed in Version | => 3.3.1 |
2019-12-09 23:01 | Florian | Fixed in Revision | => 43670 |
2019-12-09 23:01 | Florian | Note Added: 0119719 |