Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-68640

QV4 interpreter doesn't properly truncate floats using bitwise-or-with-zero trick

XMLWordPrintable

      In Javascript, a|0 should result in a truncated to an integer. The JIT version of V4 handles this properly, while the interpreter returns the value unchanged, resulting in incorrect code.

      In trivial tests, the whole computation seems to get optimized out, so slightly more complex code is needed to reproduce this bug. Example:

      import QtQml 2.0 
      QtObject {
      
          Component.onCompleted: {
              var a=1
              var b=10
              for(var i=0;i<5;i++) {
                  var c =(a+b)/2|0;
                  print(c)
                  b=c
              }
          }
      }
      

       

      When running with JIT, this correctly prints 5,3,2,1,1.

      With QV4_FORCE_INTERPRETER, I get 5.5, 3.25, 2.125, and so on

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            shausman Simon Hausmann
            anszom Andrzej Szombierski
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes