Bug 1847469 - Part 22: Use column number types in SrcNote::ColSpan. r=iain

Differential Revision: https://phabricator.services.mozilla.com/D185760
This commit is contained in:
Tooru Fujisawa 2023-08-16 17:31:41 +00:00
parent 3905aba97e
commit 53ee8e4eee
5 changed files with 16 additions and 18 deletions

View File

@ -622,7 +622,7 @@ bool BytecodeEmitter::updateSourceCoordNotes(uint32_t offset) {
if (colspan != JS::ColumnNumberOffset::zero()) {
if (!newSrcNote2(SrcNoteType::ColSpan,
SrcNote::ColSpan::toOperand(colspan.value()))) {
SrcNote::ColSpan::toOperand(colspan))) {
return false;
}
bytecodeSection().setLastColumn(columnIndex, offset);

View File

@ -13,7 +13,8 @@
#include <stddef.h> // ptrdiff_t, size_t
#include <stdint.h> // int8_t, uint8_t, uint32_t
#include "jstypes.h" // js::{Bit, BitMask}
#include "jstypes.h" // js::{Bit, BitMask}
#include "js/ColumnNumber.h" // JS::ColumnNumberOffset
namespace js {
@ -210,29 +211,30 @@ class SrcNote {
*/
static constexpr ptrdiff_t ColSpanSignBit = 1 << (OperandBits - 1);
static inline ptrdiff_t fromOperand(ptrdiff_t operand) {
static inline JS::ColumnNumberOffset fromOperand(ptrdiff_t operand) {
// There should be no bits set outside the field we're going to
// sign-extend.
MOZ_ASSERT(!(operand & ~((1U << OperandBits) - 1)));
// Sign-extend the least significant OperandBits bits.
return (operand ^ ColSpanSignBit) - ColSpanSignBit;
return JS::ColumnNumberOffset((operand ^ ColSpanSignBit) -
ColSpanSignBit);
}
public:
static constexpr ptrdiff_t MinColSpan = -ColSpanSignBit;
static constexpr ptrdiff_t MaxColSpan = ColSpanSignBit - 1;
static inline ptrdiff_t toOperand(ptrdiff_t colspan) {
static inline ptrdiff_t toOperand(JS::ColumnNumberOffset colspan) {
// Truncate the two's complement colspan, for storage as an operand.
ptrdiff_t operand = colspan & ((1U << OperandBits) - 1);
ptrdiff_t operand = colspan.value() & ((1U << OperandBits) - 1);
// When we read this back, we'd better get the value we stored.
MOZ_ASSERT(fromOperand(operand) == colspan);
return operand;
}
static inline ptrdiff_t getSpan(const SrcNote* sn);
static inline JS::ColumnNumberOffset getSpan(const SrcNote* sn);
};
class SetLine {
@ -365,7 +367,7 @@ class SrcNoteReader {
};
/* static */
inline ptrdiff_t SrcNote::ColSpan::getSpan(const SrcNote* sn) {
inline JS::ColumnNumberOffset SrcNote::ColSpan::getSpan(const SrcNote* sn) {
return fromOperand(SrcNoteReader::getOperand(sn, unsigned(Operands::Span)));
}

View File

@ -880,7 +880,7 @@ void BaselinePerfSpewer::saveJitCodeSourceInfo(
lineno++;
colno = JS::LimitedColumnNumberZeroOrigin::zero();
} else if (type == SrcNoteType::ColSpan) {
colno += JS::ColumnNumberOffset(SrcNote::ColSpan::getSpan(sn));
colno += SrcNote::ColSpan::getSpan(sn);
} else {
continue;
}

View File

@ -202,9 +202,7 @@ class BytecodeRangeWithPosition : private BytecodeRange {
SrcNoteType type = sn->type();
if (type == SrcNoteType::ColSpan) {
ptrdiff_t colspan = SrcNote::ColSpan::getSpan(sn);
MOZ_ASSERT(ptrdiff_t(column.zeroOriginValue()) + colspan >= 0);
column += JS::ColumnNumberOffset(colspan);
column += SrcNote::ColSpan::getSpan(sn);
lastLinePC = snpc;
} else if (type == SrcNoteType::SetLine) {
lineno = SrcNote::SetLine::getLine(sn, initialLine);

View File

@ -2719,9 +2719,7 @@ unsigned js::PCToLineNumber(unsigned startLine,
lineno++;
column = JS::LimitedColumnNumberZeroOrigin::zero();
} else if (type == SrcNoteType::ColSpan) {
ptrdiff_t colspan = SrcNote::ColSpan::getSpan(sn);
MOZ_ASSERT(ptrdiff_t(column.zeroOriginValue()) + colspan >= 0);
column += JS::ColumnNumberOffset(colspan);
column += SrcNote::ColSpan::getSpan(sn);
}
}
@ -3533,11 +3531,11 @@ bool JSScript::dumpSrcNotes(JSContext* cx, JS::Handle<JSScript*> script,
break;
case SrcNoteType::ColSpan: {
uint32_t colspan = SrcNote::ColSpan::getSpan(sn);
if (!sp->jsprintf(" colspan %u", colspan)) {
JS::ColumnNumberOffset colspan = SrcNote::ColSpan::getSpan(sn);
if (!sp->jsprintf(" colspan %u", colspan.value())) {
return false;
}
column += JS::ColumnNumberOffset(colspan);
column += colspan;
break;
}