Skip to content

Commit

Permalink
Stop using Vector::unsafeAppendWithoutCapacityCheck() in WasmBBQJIT.cpp
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=264646

Reviewed by Darin Adler.

* Source/JavaScriptCore/wasm/WasmBBQJIT.cpp:
(JSC::Wasm::BBQJIT::addSwitch):

Canonical link: https://commits.webkit.org/270622@main
  • Loading branch information
cdumez committed Nov 13, 2023
1 parent 6b87ac8 commit 41848d9
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions Source/JavaScriptCore/wasm/WasmBBQJIT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7559,28 +7559,26 @@ class BBQJIT {

constexpr unsigned minCasesForTable = 7;
if (minCasesForTable <= targets.size()) {
Vector<Box<CCallHelpers::Label>> labels;
labels.reserveInitialCapacity(targets.size());
auto* jumpTable = m_callee.addJumpTable(targets.size());
auto fallThrough = m_jit.branch32(RelationalCondition::AboveOrEqual, wasmScratchGPR, TrustedImm32(targets.size()));
m_jit.zeroExtend32ToWord(wasmScratchGPR, wasmScratchGPR);
m_jit.lshiftPtr(TrustedImm32(3), wasmScratchGPR);
m_jit.addPtr(TrustedImmPtr(jumpTable->data()), wasmScratchGPR);
m_jit.farJump(Address(wasmScratchGPR), JSSwitchPtrTag);

for (unsigned index = 0; index < targets.size(); ++index) {
Box<CCallHelpers::Label> label = Box<CCallHelpers::Label>::create(m_jit.label());
labels.unsafeAppendWithoutCapacityCheck(label);
bool isCodeEmitted = currentControlData().addExit(*this, targets[index]->targetLocations(), results);
auto labels = WTF::map(targets, [&](auto& target) {
auto label = Box<CCallHelpers::Label>::create(m_jit.label());
bool isCodeEmitted = currentControlData().addExit(*this, target->targetLocations(), results);
if (isCodeEmitted)
targets[index]->addBranch(m_jit.jump());
target->addBranch(m_jit.jump());
else {
// It is common that we do not need to emit anything before jumping to the target block.
// In that case, we put Box<Label> which will be filled later when the end of the block is linked.
// We put direct jump to that block in the link task.
targets[index]->addLabel(WTFMove(label));
target->addLabel(Box { label });
}
}
return label;
});

m_jit.addLinkTask([labels = WTFMove(labels), jumpTable](LinkBuffer& linkBuffer) {
for (unsigned index = 0; index < labels.size(); ++index)
Expand Down

0 comments on commit 41848d9

Please sign in to comment.