From fc6be612fd13e36e8a3d810d679b2ee88dced8c2 Mon Sep 17 00:00:00 2001 From: Jonas Maebe Date: Fri, 16 Mar 2012 20:57:22 +0000 Subject: [PATCH] * also insert an explicit conversion from byte/char/bytebool/... to smallint on Dalvik, because those values are obtained via an "and 255" operation which again turns them into longint values as var as the Dalvik type system is concerned git-svn-id: branches/jvmbackend@20527 - --- compiler/jvm/hlcgcpu.pas | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/compiler/jvm/hlcgcpu.pas b/compiler/jvm/hlcgcpu.pas index c9963553ce..81d8212303 100644 --- a/compiler/jvm/hlcgcpu.pas +++ b/compiler/jvm/hlcgcpu.pas @@ -1993,10 +1993,19 @@ implementation above. We still may have to truncare or sign extend in case the destination type is smaller that the source type, or has a different sign. In case the destination is a widechar and the source is not, we - also have to insert a conversion to widechar } + also have to insert a conversion to widechar. + + In case of Dalvik, we also have to insert conversions for e.g. byte + -> smallint, because truncating a byte happens via "and 255", and the + result is a longint in Dalvik's type verification model (so we have + to "truncate" it back to smallint) } if (not(fromcgsize in [OS_S64,OS_64,OS_32,OS_S32]) or not(tocgsize in [OS_S64,OS_64,OS_32,OS_S32])) and - ((tcgsize2size[fromcgsize]>tcgsize2size[tocgsize]) or + (((current_settings.cputype=cpu_dalvik) and + not(tocgsize in [OS_32,OS_S32]) and + not is_signed(fromsize) and + is_signed(tosize)) or + (tcgsize2size[fromcgsize]>tcgsize2size[tocgsize]) or ((tcgsize2size[fromcgsize]=tcgsize2size[tocgsize]) and (fromcgsize<>tocgsize)) or { needs to mask out the sign in the top 16 bits }