From c7c3d03391ad4f1c6a914b32780eb786712f61e4 Mon Sep 17 00:00:00 2001 From: Erik Verbruggen Date: Tue, 15 Apr 2014 15:26:54 +0200 Subject: [PATCH] V4 IR: prevent accidental detaches of QVectors. Change-Id: I20ebf44ff0609f6833f7e59a4f2fb312be11b8c1 Reviewed-by: Simon Hausmann --- src/qml/compiler/qv4ssa.cpp | 5 +++-- src/qml/compiler/qv4ssa_p.h | 4 ++-- src/qml/jit/qv4isel_masm.cpp | 8 ++++---- src/qml/jit/qv4isel_masm_p.h | 2 +- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/qml/compiler/qv4ssa.cpp b/src/qml/compiler/qv4ssa.cpp index fd6b7b537..9c5407e74 100644 --- a/src/qml/compiler/qv4ssa.cpp +++ b/src/qml/compiler/qv4ssa.cpp @@ -3538,6 +3538,7 @@ public: _sortedRanges.append(range); } std::sort(_sortedRanges.begin(), _sortedRanges.end(), LifeTimeInterval::lessThan); + _intervals.clear(); } QVector ranges() const { return _sortedRanges; } @@ -3692,8 +3693,8 @@ LifeTimeInterval LifeTimeInterval::split(int atPosition, int newStart) // search where to split the interval for (int i = 0, ei = _ranges.size(); i < ei; ++i) { - if (_ranges[i].start <= atPosition) { - if (_ranges[i].end >= atPosition) { + if (_ranges.at(i).start <= atPosition) { + if (_ranges.at(i).end >= atPosition) { // split happens in the middle of a range. Keep this range in both the old and the // new interval, and correct the end/start later _ranges.resize(i + 1); diff --git a/src/qml/compiler/qv4ssa_p.h b/src/qml/compiler/qv4ssa_p.h index 9bbe92dfa..13f3eed4d 100644 --- a/src/qml/compiler/qv4ssa_p.h +++ b/src/qml/compiler/qv4ssa_p.h @@ -82,7 +82,7 @@ public: , _reg(Invalid) , _isFixedInterval(0) , _isSplitFromInterval(0) - {} + { _ranges.reserve(2); } bool isValid() const { return _end != Invalid; } @@ -92,7 +92,7 @@ public: void setFrom(Stmt *from); void addRange(int from, int to); - Ranges ranges() const { return _ranges; } + const Ranges &ranges() const { return _ranges; } void reserveRanges(int capacity) { _ranges.reserve(capacity); } int start() const { return _ranges.first().start; } diff --git a/src/qml/jit/qv4isel_masm.cpp b/src/qml/jit/qv4isel_masm.cpp index 57ca94073..74b404a79 100644 --- a/src/qml/jit/qv4isel_masm.cpp +++ b/src/qml/jit/qv4isel_masm.cpp @@ -374,14 +374,14 @@ void InstructionSelection::run(int functionIndex) qSwap(_removableJumps, removableJumps); } -void *InstructionSelection::addConstantTable(QVector *values) +const void *InstructionSelection::addConstantTable(QVector *values) { compilationUnit->constantValues.append(*values); values->clear(); QVector &finalValues = compilationUnit->constantValues.last(); finalValues.squeeze(); - return finalValues.data(); + return finalValues.constData(); } QV4::CompiledData::CompilationUnit *InstructionSelection::backendCompileStep() @@ -1620,10 +1620,10 @@ Assembler::ImplicitAddress Assembler::ConstantTable::loadValueAddress(const Prim void Assembler::ConstantTable::finalize(JSC::LinkBuffer &linkBuffer, InstructionSelection *isel) { - void *tablePtr = isel->addConstantTable(&_values); + const void *tablePtr = isel->addConstantTable(&_values); foreach (DataLabelPtr label, _toPatch) - linkBuffer.patch(label, tablePtr); + linkBuffer.patch(label, const_cast(tablePtr)); } bool InstructionSelection::visitCJumpDouble(IR::AluOp op, IR::Expr *left, IR::Expr *right, diff --git a/src/qml/jit/qv4isel_masm_p.h b/src/qml/jit/qv4isel_masm_p.h index 0e8db93e8..d589223d7 100644 --- a/src/qml/jit/qv4isel_masm_p.h +++ b/src/qml/jit/qv4isel_masm_p.h @@ -72,7 +72,7 @@ public: virtual void run(int functionIndex); - void *addConstantTable(QVector *values); + const void *addConstantTable(QVector *values); protected: virtual QV4::CompiledData::CompilationUnit *backendCompileStep(); -- 2.34.1