Store booleans as 32 bit integers
authorLars Knoll <lars.knoll@digia.com>
Fri, 12 Oct 2012 06:52:51 +0000 (08:52 +0200)
committerSimon Hausmann <simon.hausmann@digia.com>
Fri, 12 Oct 2012 07:20:01 +0000 (09:20 +0200)
The old code was giving valgrind warnings, because
we loaded the boolean (1 byte) as a 32 bit integer.
Instead simply store all booleans as 32 bit ints
to avoid the warnings.

Change-Id: I46c7f9fc9d8dfe52afd9bab2dbab8923aaa630f8
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
qmljs_runtime.h
qv4isel_masm.cpp

index 6505f89..2d205eb 100644 (file)
@@ -247,7 +247,6 @@ struct ValueData {
             union {
                 uint uint_32;
                 int int_32;
-                bool b;
             };
 #if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
             uint tag;
@@ -286,7 +285,7 @@ template <> struct ValueBase<4> : public ValueData
     }
 
     bool booleanValue() const {
-        return b;
+        return int_32;
     }
     double doubleValue() const {
         return dbl;
@@ -352,7 +351,7 @@ template <> struct ValueBase<8> : public ValueData
     }
 
     bool booleanValue() const {
-        return b;
+        return int_32;
     }
     double doubleValue() const {
         return dbl;
@@ -463,7 +462,7 @@ inline Value ValueBase<4>::fromBoolean(bool b)
 {
     Value v;
     v.tag = Boolean_Type;
-    v.b = b;
+    v.int_32 = b;
     return v;
 }
 
@@ -517,7 +516,7 @@ inline Value ValueBase<8>::fromBoolean(bool b)
 {
     Value v;
     v.tag = Boolean_Type;
-    v.b = b;
+    v.int_32 = b;
     return v;
 }
 
@@ -555,7 +554,7 @@ inline Value ValueBase<8>::fromObject(Object *o)
 template <Value::ValueType> struct ValueOffsetHelper;
 template <> struct ValueOffsetHelper<Value::Boolean_Type>
 {
-    enum { DataOffset = offsetof(ValueData, b) };
+    enum { DataOffset = offsetof(ValueData, int_32) };
 };
 
 template <> struct ValueOffsetHelper<Value::Undefined_Type>
@@ -799,8 +798,8 @@ inline void __qmljs_to_string(Context *ctx, Value *result, const Value *value)
     case Value::Integer_Type:
         __qmljs_string_from_number(ctx, result, value->int_32);
         break;
-    default: // double
-        __qmljs_string_from_number(ctx, result, value->doubleValue());
+    default: // number
+        __qmljs_string_from_number(ctx, result, value->asDouble());
         break;
 
     } // switch
@@ -1138,7 +1137,7 @@ inline void __qmljs_eq(Context *ctx, Value *result, const Value *left, const Val
 inline void __qmljs_ne(Context *ctx, Value *result, const Value *left, const Value *right)
 {
     __qmljs_eq(ctx, result, left, right);
-    result->b = !result->b;
+    result->int_32 = !(bool)result->int_32;
 }
 
 inline void __qmljs_se(Context *ctx, Value *result, const Value *left, const Value *right)
index 98b9a71..0623d9a 100644 (file)
@@ -548,7 +548,7 @@ void InstructionSelection::visitCJump(IR::CJump *s)
         Jump booleanConversion = branch32(NotEqual, tag, TrustedImm32(VM::Value::Boolean_Type));
 
         Address data = temp;
-        data.offset += offsetof(VM::ValueData, b);
+        data.offset += offsetof(VM::ValueData, int_32);
         load32(data, Gpr0);
         Jump testBoolean = jump();
 
@@ -559,7 +559,7 @@ void InstructionSelection::visitCJump(IR::CJump *s)
         }
 
         testBoolean.link(this);
-        Jump target = branch32(Equal, Gpr0, TrustedImm32(1));
+        Jump target = branch32(NotEqual, Gpr0, TrustedImm32(0));
         _patches[s->iftrue].append(target);
 
         jumpToBlock(s->iffalse);