mirror of
https://gitee.com/openharmony/arkcompiler_ets_runtime
synced 2024-11-27 04:00:37 +00:00
fix warning of signed type cannot be involved in the bit operation
Signed-off-by: yangxiaoshuai2022 <yangxiaoshuai@huawei.com>
This commit is contained in:
parent
a405fe574a
commit
0aeb702aa0
@ -125,9 +125,9 @@ public:
|
||||
int BitAt(int position)
|
||||
{
|
||||
if (position >= SHIFT_64BIT) {
|
||||
return static_cast<int>(high_bits_ >> (position - SHIFT_64BIT)) & 1;
|
||||
return static_cast<int>((high_bits_ >> (position - SHIFT_64BIT)) & 1);
|
||||
} else {
|
||||
return static_cast<int>(low_bits_ >> position) & 1;
|
||||
return static_cast<int>((low_bits_ >> position) & 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1675,7 +1675,7 @@ JSTaggedValue BuiltinsString::CreateArrayFromString(JSThread *thread, EcmaVM *ec
|
||||
if (EcmaStringAccessor(thisString).IsLineOrConstantString()) {
|
||||
canBeCompressed = EcmaStringAccessor::CanBeCompressed(*thisString);
|
||||
}
|
||||
bool isOneByte = isUtf8 & canBeCompressed;
|
||||
bool isOneByte = isUtf8 && canBeCompressed;
|
||||
JSHandle<EcmaString> seperatorString = thread->GetEcmaVM()->GetFactory()->GetEmptyString();
|
||||
if (lim == UINT32_MAX - 1) {
|
||||
JSHandle<StringSplitResultCache> cacheTable(thread->GetCurrentEcmaContext()->GetStringSplitResultCache());
|
||||
|
@ -170,10 +170,10 @@ void BaselineCompiler::GetJumpToOffsets(const uint8_t *start, const uint8_t *end
|
||||
case EcmaOpcode::JEQZ_IMM16:
|
||||
case EcmaOpcode::JNEZ_IMM16:
|
||||
case EcmaOpcode::JMP_IMM16: {
|
||||
int16_t jumpOffset = *(start + 2); // 2: get two bytes in bytecodes
|
||||
jumpOffset <<= 8; // 8: left shift 8 bits
|
||||
jumpOffset += *(start + 1); // 1: get one byte in bytecodes
|
||||
size_t jumpTo = offset + jumpOffset;
|
||||
int16_t jumpOffset = *(start + 2); // 2: get two bytes in bytecodes
|
||||
uint16_t tmpValue = static_cast<uint16_t>(jumpOffset) << 8; // 8: left shift 8 bits
|
||||
tmpValue += static_cast<uint8_t>(*(start + 1)); // 1: get one byte in bytecodes
|
||||
size_t jumpTo = offset + static_cast<int16_t>(tmpValue);
|
||||
jumpToOffsets.insert(jumpTo);
|
||||
break;
|
||||
}
|
||||
@ -181,13 +181,13 @@ void BaselineCompiler::GetJumpToOffsets(const uint8_t *start, const uint8_t *end
|
||||
case EcmaOpcode::JNEZ_IMM32:
|
||||
case EcmaOpcode::JMP_IMM32: {
|
||||
int32_t jumpOffset = *(start + 4); // 4: get four bytes in bytecodes
|
||||
jumpOffset <<= 8; // 8: left shift 8 bits
|
||||
jumpOffset += *(start + 3); // 3: get three bytes in bytecodes
|
||||
jumpOffset <<= 8; // 8: left shift 8 bits
|
||||
jumpOffset += *(start + 2); // 2: get two bytes in bytecodes
|
||||
jumpOffset <<= 8; // 8: left shift 8 bits
|
||||
jumpOffset += *(start + 1); // 1: get one byte in bytecodes
|
||||
size_t jumpTo = offset + jumpOffset;
|
||||
uint32_t tmpValue = static_cast<uint32_t>(jumpOffset) << 8; // 8: left shift 8 bits
|
||||
tmpValue += static_cast<uint8_t>(*(start + 3)); // 3: get three bytes in bytecodes
|
||||
tmpValue <<= 8; // 8: left shift 8 bits
|
||||
tmpValue += static_cast<uint8_t>(*(start + 2)); // 2: get two bytes in bytecodes
|
||||
tmpValue <<= 8; // 8: left shift 8 bits
|
||||
tmpValue += static_cast<uint8_t>(*(start + 1)); // 1: get one byte in bytecodes
|
||||
size_t jumpTo = offset + static_cast<int32_t>(tmpValue);
|
||||
jumpToOffsets.insert(jumpTo);
|
||||
break;
|
||||
}
|
||||
|
@ -1135,9 +1135,9 @@ T ConstantFold::CalIntValueFromFloatValue(T value, const MIRType &resultType) co
|
||||
DEBUG_ASSERT(kByteSizeOfBit64 >= resultType.GetSize(), "unsupported type");
|
||||
size_t shiftNum = (kByteSizeOfBit64 - resultType.GetSize()) * kBitSizePerByte;
|
||||
bool isSigned = IsSignedInteger(resultType.GetPrimType());
|
||||
int64 max = std::numeric_limits<int64>::max() >> shiftNum;
|
||||
int64 max = static_cast<uint64_t>(std::numeric_limits<int64>::max()) >> shiftNum;
|
||||
uint64 umax = std::numeric_limits<uint64>::max() >> shiftNum;
|
||||
int64 min = isSigned ? (std::numeric_limits<int64>::min() >> shiftNum) : 0;
|
||||
int64 min = isSigned ? (static_cast<uint64_t>(std::numeric_limits<int64>::min()) >> shiftNum) : 0;
|
||||
if (isSigned && (value > max)) {
|
||||
return static_cast<T>(max);
|
||||
} else if (!isSigned && (value > umax)) {
|
||||
|
@ -184,7 +184,9 @@ struct IntMatcher final : public ValueMatcher<T, kOpcode, kMachineType> {
|
||||
if (!this->HasResolvedValue() || this->ResolvedValue() <= 0) {
|
||||
return false;
|
||||
}
|
||||
return (this->ResolvedValue() & (this->ResolvedValue() - 1)) == 0;
|
||||
using unsigned_type = typename std::make_unsigned<T>::type;
|
||||
const unsigned_type resolvedValue = static_cast<unsigned_type>(this->ResolvedValue());
|
||||
return (resolvedValue & (resolvedValue - 1)) == 0;
|
||||
}
|
||||
|
||||
bool IsNegativePowerOf2() const
|
||||
|
@ -123,7 +123,7 @@ template <typename signed_type> inline signed_type ShlWithWraparound(signed_type
|
||||
{
|
||||
using unsigned_type = typename std::make_unsigned<signed_type>::type;
|
||||
const unsigned_type kMask = (sizeof(a) * 8) - 1;
|
||||
return static_cast<signed_type>(static_cast<unsigned_type>(a) << (b & kMask));
|
||||
return static_cast<signed_type>(static_cast<unsigned_type>(a) << (static_cast<unsigned_type>(b) & kMask));
|
||||
}
|
||||
|
||||
template <typename signed_type> inline signed_type NegateWithWraparound(signed_type a)
|
||||
@ -334,7 +334,7 @@ GateRef InstructionCombine::VisitICMP(GateRef gate)
|
||||
Int64BinopMatcher orOp(andOp.Left().Gate(), circuit_);
|
||||
auto constant2 = andOp.Right().ResolvedValue();
|
||||
auto constant1 = orOp.Right().HasResolvedValue() ? orOp.Right().ResolvedValue() : 0;
|
||||
bool flag = ((constant1 & constant2) != 0);
|
||||
bool flag = ((static_cast<uint64_t>(constant1) & static_cast<uint64_t>(constant2)) != 0);
|
||||
result = flag ? builder_.False() : Circuit::NullGate();
|
||||
}
|
||||
}
|
||||
@ -1060,7 +1060,8 @@ GateRef InstructionCombine::ReduceWord64Or(GateRef gate)
|
||||
if (m.Right().HasResolvedValue() && m.Left().IsmInt64And()) {
|
||||
Int64BinopMatcher mand(m.Left().Gate(), circuit_);
|
||||
if (mand.Right().HasResolvedValue()) {
|
||||
if ((m.Right().ResolvedValue() | mand.Right().ResolvedValue()) == -1) {
|
||||
if ((static_cast<uint64_t>(m.Right().ResolvedValue()) |
|
||||
static_cast<uint64_t>(mand.Right().ResolvedValue())) == -1) {
|
||||
acc_.ReplaceValueIn(gate, mand.Left().Gate(), 0);
|
||||
return gate;
|
||||
}
|
||||
@ -1163,7 +1164,8 @@ GateRef InstructionCombine::ReduceWord64Lsr(GateRef gate)
|
||||
}
|
||||
if (m.IsFoldable()) {
|
||||
// The '63' here is used as a mask to limit the shift amount to 0-63 bits, preventing overflow.
|
||||
return builder_.Int64(m.Left().ResolvedValue() >> (m.Right().ResolvedValue() & 63));
|
||||
return builder_.Int64(static_cast<uint64_t>(m.Left().ResolvedValue()) >>
|
||||
(static_cast<uint64_t>(m.Right().ResolvedValue()) & 63));
|
||||
}
|
||||
return Circuit::NullGate();
|
||||
}
|
||||
@ -1177,7 +1179,8 @@ GateRef InstructionCombine::ReduceWord32Lsr(GateRef gate)
|
||||
}
|
||||
if (m.IsFoldable()) {
|
||||
// The '31' here is used as a mask to limit the shift amount to 0-31 bits, preventing overflow.
|
||||
return builder_.Int32(m.Left().ResolvedValue() >> (m.Right().ResolvedValue() & 31));
|
||||
return builder_.Int32(static_cast<uint32_t>(m.Left().ResolvedValue()) >>
|
||||
(static_cast<uint32_t>(m.Right().ResolvedValue()) & 31));
|
||||
}
|
||||
// (m >>> s) == 0 implies ((x & m) >>> s) == 0
|
||||
if (m.Left().IsmInt32And() && m.Right().HasResolvedValue()) {
|
||||
|
@ -2032,7 +2032,7 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t
|
||||
int32_t opNumber1 = right.GetInt();
|
||||
uint32_t shift =
|
||||
static_cast<uint32_t>(opNumber1) & 0x1f; // NOLINT(hicpp-signed-bitwise, readability-magic-numbers)
|
||||
auto ret = static_cast<int32_t>(opNumber0 >> shift); // NOLINT(hicpp-signed-bitwise)
|
||||
auto ret = static_cast<int32_t>(static_cast<uint32_t>(opNumber0) >> shift); // NOLINT(hicpp-signed-bitwise)
|
||||
SET_ACC(JSTaggedValue(ret));
|
||||
} else if (left.IsNumber() && right.IsNumber()) {
|
||||
int32_t opNumber0 =
|
||||
@ -2041,7 +2041,7 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t
|
||||
right.IsInt() ? right.GetInt() : base::NumberHelper::DoubleToInt(right.GetDouble(), base::INT32_BITS);
|
||||
uint32_t shift =
|
||||
static_cast<uint32_t>(opNumber1) & 0x1f; // NOLINT(hicpp-signed-bitwise, readability-magic-numbers)
|
||||
auto ret = static_cast<int32_t>(opNumber0 >> shift); // NOLINT(hicpp-signed-bitwise)
|
||||
auto ret = static_cast<int32_t>(static_cast<uint32_t>(opNumber0) >> shift); // NOLINT(hicpp-signed-bitwise)
|
||||
SET_ACC(JSTaggedValue(ret));
|
||||
} else {
|
||||
// slow path
|
||||
|
Loading…
Reference in New Issue
Block a user