Browse Source

* 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 -

Jonas Maebe 13 years ago
parent
commit
fc6be612fd
1 changed files with 11 additions and 2 deletions
  1. 11 2
      compiler/jvm/hlcgcpu.pas

+ 11 - 2
compiler/jvm/hlcgcpu.pas

@@ -1993,10 +1993,19 @@ implementation
         above. We still may have to truncare or sign extend in case the
         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
         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
         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
       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
           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
           ((tcgsize2size[fromcgsize]=tcgsize2size[tocgsize]) and
            (fromcgsize<>tocgsize)) or
            (fromcgsize<>tocgsize)) or
           { needs to mask out the sign in the top 16 bits }
           { needs to mask out the sign in the top 16 bits }