From 67c0513d2550ceec53385f1b738a996ce935d06f Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Fri, 12 Oct 2012 08:52:51 +0200 Subject: [PATCH] Store booleans as 32 bit integers 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 --- qmljs_runtime.h | 17 ++++++++--------- qv4isel_masm.cpp | 4 ++-- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/qmljs_runtime.h b/qmljs_runtime.h index 6505f89..2d205eb 100644 --- a/qmljs_runtime.h +++ b/qmljs_runtime.h @@ -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 struct ValueOffsetHelper; template <> struct ValueOffsetHelper { - enum { DataOffset = offsetof(ValueData, b) }; + enum { DataOffset = offsetof(ValueData, int_32) }; }; template <> struct ValueOffsetHelper @@ -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) diff --git a/qv4isel_masm.cpp b/qv4isel_masm.cpp index 98b9a71..0623d9a 100644 --- a/qv4isel_masm.cpp +++ b/qv4isel_masm.cpp @@ -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); -- 2.7.4