It is currently Mon Apr 12, 2021 5:17 am

All times are UTC + 1 hour

Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: PB 5.31 - Wrong ASM generated for sign extension
PostPosted: Sat Dec 13, 2014 12:40 am 
User avatar

Joined: Wed Aug 31, 2005 11:09 pm
Posts: 3705
Location: Italy
Well not always, in this specific case at least, probably in other cases too.

This should really be fixed, it's unnerving every time you mix different data sizes in an expression not knowing if you are about to activate this kind of bug !

I'm reporting this because I was asked to, but probably it would be too hard to fix this (rigid/fragile compiler) and it will stay as it is, like other similar compiler bugs :cry:


; for x86 the bug is present for .b, .w
; for x64 the bug is present for .b, .w, .l

; so when b2 is smaller than the architecture's native data type

Define a = 0
Define b1 = 1
Define b2.w = 2

Procedure MyProcedure (x)
 Debug "x = " + x

MyProcedure (a - (b1 - b2)) ; ok

a = a + (a - MyProcedure (a - (b1 - b2))) ; same params passed to MyProcedure(), yet this time the debug statement shows they are getting destroyed

debug wrote:
[00:32:35] x = 1
[00:32:35] x = 0

; Define a = 0
  MOV    dword [v_a],0
; Define b1 = 1
  MOV    dword [v_b1],1
; Define b2.w = 2
  MOV    word [v_b2],2
; MyProcedure (a - (b1 - b2))
  MOV    ebx,dword [v_a]
  MOV    edi,dword [v_b1]
  MOVSX  eax,word [v_b2]
  SUB    edi,eax
  SUB    ebx,edi
  PUSH   ebx
  CALL  _Procedure0
; a = a + (a - MyProcedure (a - (b1 - b2)))
  MOV    ebx,dword [v_a]
  MOV    edi,dword [v_a]
  MOV    esi,dword [v_a]
  MOV    eax,dword [v_b1]
  MOVSX  eax,word [v_b2] ; <--- extends overwriting b1 (!!)
  SUB    eax,eax ; <--- same register (!!!), this wipes away (zero) the sub expression result (b1 - b2)
  SUB    esi,eax
  PUSH   esi
  CALL  _Procedure0
  SUB    edi,eax
  ADD    ebx,edi
  MOV    dword [v_a],ebx

Original thread -> viewtopic.php?f=7&t=61214

[ My little PureBasic review ]

Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC + 1 hour

Who is online

Users browsing this forum: No registered users and 7 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye