Do an explicit conversion when converting from signed to unsigned byte values. This is needed because the value is held in a 16-bit register, sign-extended. The high 8 bits need to be cleared to convert to an unsigned byte.

This fixes the compca06.c test case.

Note that this generates inefficient code in the case of loading a signed byte value and then immediately casting it to unsigned (it first sign-extends the value, then masks off the high bits). This should be optimized, but at least the generated code is correct now.
This commit is contained in:
Stephen Heumann 2015-12-21 23:01:53 -06:00
parent 6bd0bef8c5
commit c28e48a54f
2 changed files with 3 additions and 2 deletions

View File

@ -854,7 +854,7 @@ if codeGeneration then begin
else if (baseTypeEnum(fp1) in [cgUByte,cgWord,cgUWord]) else if (baseTypeEnum(fp1) in [cgUByte,cgWord,cgUWord])
and (baseTypeEnum(fp2) in [cgWord,cgUWord]) then and (baseTypeEnum(fp2) in [cgWord,cgUWord]) then
goto 1 goto 1
else if (baseTypeEnum(fp1) in [cgByte,cgUByte]) else if (baseTypeEnum(fp1) in [cgUByte])
and (baseTypeEnum(fp2) in [cgByte,cgUByte]) then and (baseTypeEnum(fp2) in [cgByte,cgUByte]) then
goto 1 goto 1
else else

View File

@ -1131,6 +1131,7 @@ const {note: these constants list all legal }
cExtended = $09; cExtended = $09;
cVoid = $0B; cVoid = $0B;
byteToUByte = $01;
byteToWord = $02; byteToWord = $02;
byteToUword = $03; byteToUword = $03;
byteToLong = $04; byteToLong = $04;
@ -1249,7 +1250,7 @@ else if op^.q in [ubyteToLong,ubyteToUlong,uwordToLong,uwordToUlong] then
GenImplied(m_pha); GenImplied(m_pha);
end; {else} end; {else}
end {else if} end {else if}
else if op^.q in [wordToByte,wordToUbyte,uwordToByte,uwordToUbyte] then else if op^.q in [byteToUByte,wordToByte,wordToUbyte,uwordToByte,uwordToUbyte] then
GenNative(m_and_imm, immediate, $00FF, nil, 0) GenNative(m_and_imm, immediate, $00FF, nil, 0)
else if op^.q in [byteToReal,uByteToReal,wordToReal] then else if op^.q in [byteToReal,uByteToReal,wordToReal] then
GenCall(11) GenCall(11)