From 3b14e2ffdd8eb4b7f7f4508768b75f2acc399370 Mon Sep 17 00:00:00 2001 From: Erik Verbruggen Date: Fri, 9 Sep 2016 15:37:57 +0200 Subject: QML: Make Heap::Object and all subclasses trivial GCC6 might dead-store-eliminate out our secret write to Base::mmdata, because it expects all memory content to be "undefined" before constructor calls. Clang might take the same approach if the constructor of Heap::Object is removed. By making these structs trivial, it also makes them memcpy-able. Change-Id: I055b2ad28311b997fbe059849ebda4d5894eaa9b Reviewed-by: Simon Hausmann --- src/qml/jsruntime/qv4object_p.h | 45 +++++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 17 deletions(-) (limited to 'src/qml/jsruntime/qv4object_p.h') diff --git a/src/qml/jsruntime/qv4object_p.h b/src/qml/jsruntime/qv4object_p.h index 54ce2ea60d..6ddeb84d3c 100644 --- a/src/qml/jsruntime/qv4object_p.h +++ b/src/qml/jsruntime/qv4object_p.h @@ -68,7 +68,7 @@ namespace QV4 { namespace Heap { struct Object : Base { - inline Object() { Base::init(); } + void init() { Base::init(); } const Value *propertyData(uint index) const { if (index < inlineMemberSize) return reinterpret_cast(this) + inlineMemberOffset + index; return memberData->data + index - inlineMemberSize; } Value *propertyData(uint index) { if (index < inlineMemberSize) return reinterpret_cast(this) + inlineMemberOffset + index; return memberData->data + index - inlineMemberSize; } @@ -93,9 +93,10 @@ struct Object : Base { Data *d_unchecked() const { return static_cast(m()); } \ Data *d() const { \ Data *dptr = d_unchecked(); \ - if (std::is_trivial::value) dptr->_checkIsInitialized(); \ + dptr->_checkIsInitialized(); \ return dptr; \ - } + } \ + V4_ASSERT_IS_TRIVIAL(Data); #define V4_OBJECT2(DataClass, superClass) \ private: \ @@ -111,9 +112,10 @@ struct Object : Base { QV4::Heap::DataClass *d_unchecked() const { return static_cast(m()); } \ QV4::Heap::DataClass *d() const { \ QV4::Heap::DataClass *dptr = d_unchecked(); \ - if (std::is_trivial::value) dptr->_checkIsInitialized(); \ + dptr->_checkIsInitialized(); \ return dptr; \ - } + } \ + V4_ASSERT_IS_TRIVIAL(QV4::Heap::DataClass); #define V4_INTERNALCLASS(c) \ static QV4::InternalClass *defaultInternalClass(QV4::ExecutionEngine *e) \ @@ -375,18 +377,22 @@ private: namespace Heap { struct BooleanObject : Object { - BooleanObject() {} - BooleanObject(bool b) - : b(b) - {} + void init() { Object::init(); } + void init(bool b) { + Object::init(); + this->b = b; + } + bool b; }; struct NumberObject : Object { - NumberObject() {} - NumberObject(double val) - : value(val) - {} + void init() { Object::init(); } + void init(double val) { + Object::init(); + value = val; + } + double value; }; @@ -395,10 +401,15 @@ struct ArrayObject : Object { LengthPropertyIndex = 0 }; - ArrayObject() - { init(); } - ArrayObject(const QStringList &list); - void init() + void init() { + Object::init(); + commonInit(); + } + + void init(const QStringList &list); + +private: + void commonInit() { *propertyData(LengthPropertyIndex) = Primitive::fromInt32(0); } }; -- cgit v1.2.3 From 57c9d6969ac474177c77d5ea59768b39620a3b2f Mon Sep 17 00:00:00 2001 From: Erik Verbruggen Date: Fri, 9 Sep 2016 16:20:57 +0200 Subject: QML: Also check for correct destroy() chaining Check that the destroy() method of Heap::Base was called when a Managed object needs destruction. This checks if a call to the parent's destroy() method was accidentally omitted. Change-Id: Id025ecd6d4744bf3eab23503fbe317ed2a461138 Reviewed-by: Simon Hausmann --- src/qml/jsruntime/qv4object_p.h | 1 + 1 file changed, 1 insertion(+) (limited to 'src/qml/jsruntime/qv4object_p.h') diff --git a/src/qml/jsruntime/qv4object_p.h b/src/qml/jsruntime/qv4object_p.h index 6ddeb84d3c..e13a701b0f 100644 --- a/src/qml/jsruntime/qv4object_p.h +++ b/src/qml/jsruntime/qv4object_p.h @@ -69,6 +69,7 @@ namespace Heap { struct Object : Base { void init() { Base::init(); } + void destroy() { Base::destroy(); } const Value *propertyData(uint index) const { if (index < inlineMemberSize) return reinterpret_cast(this) + inlineMemberOffset + index; return memberData->data + index - inlineMemberSize; } Value *propertyData(uint index) { if (index < inlineMemberSize) return reinterpret_cast(this) + inlineMemberOffset + index; return memberData->data + index - inlineMemberSize; } -- cgit v1.2.3 From 376077a8e73100ccada6f2bb81c6664817bb44ba Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Sat, 8 Oct 2016 13:03:35 +0200 Subject: Fix developer-build with gcc 6 Locally suppress bogus tautological compare warnings. Task-number: QTBUG-56266 Change-Id: Ic1b554982a778cdd89c8047483523c44d53bbadd Reviewed-by: Thiago Macieira --- src/qml/jsruntime/qv4object_p.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/qml/jsruntime/qv4object_p.h') diff --git a/src/qml/jsruntime/qv4object_p.h b/src/qml/jsruntime/qv4object_p.h index 4e39ccaf99..7e826b4c51 100644 --- a/src/qml/jsruntime/qv4object_p.h +++ b/src/qml/jsruntime/qv4object_p.h @@ -124,7 +124,7 @@ struct ObjectVTable void (*advanceIterator)(Managed *m, ObjectIterator *it, Value *name, uint *index, Property *p, PropertyAttributes *attributes); }; -#define DEFINE_OBJECT_VTABLE(classname) \ +#define DEFINE_OBJECT_VTABLE_BASE(classname) \ const QV4::ObjectVTable classname::static_vtbl = \ { \ DEFINE_MANAGED_VTABLE_INT(classname, (QT_PREPEND_NAMESPACE(QtPrivate)::is_same::value) ? Q_NULLPTR : &classname::SuperClass::static_vtbl.vTable), \ @@ -144,7 +144,15 @@ const QV4::ObjectVTable classname::static_vtbl = \ advanceIterator \ } - +#define DEFINE_OBJECT_VTABLE(classname) \ +QT_WARNING_SUPPRESS_GCC_TAUTOLOGICAL_COMPARE_ON \ +DEFINE_OBJECT_VTABLE_BASE(classname) \ +QT_WARNING_SUPPRESS_GCC_TAUTOLOGICAL_COMPARE_OFF + +#define DEFINE_OBJECT_TEMPLATE_VTABLE(classname) \ +QT_WARNING_SUPPRESS_GCC_TAUTOLOGICAL_COMPARE_ON \ +template<> DEFINE_OBJECT_VTABLE_BASE(classname) \ +QT_WARNING_SUPPRESS_GCC_TAUTOLOGICAL_COMPARE_OFF struct Q_QML_EXPORT Object: Managed { V4_OBJECT2(Object, Object) -- cgit v1.2.3