diff --git a/ecmascript/base/json_stringifier.cpp b/ecmascript/base/json_stringifier.cpp index 5d9d06abe2..6497c7ca69 100644 --- a/ecmascript/base/json_stringifier.cpp +++ b/ecmascript/base/json_stringifier.cpp @@ -269,9 +269,9 @@ bool JsonStringifier::CalculateNumberGap(JSTaggedValue gap) bool JsonStringifier::CalculateStringGap(const JSHandle &primString) { CString gapString = ConvertToString(*primString, StringConvertedUsage::LOGICOPERATION); - int gapLen = gapString.length(); + uint32_t gapLen = gapString.length(); if (gapLen > 0) { - int gapLength = std::min(gapLen, GAP_MAX_LEN); + int gapLength = std::min(gapLen, static_cast(GAP_MAX_LEN)); CString str = gapString.substr(0, gapLength); gap_ += str; gap_.append("\0"); @@ -696,7 +696,7 @@ bool JsonStringifier::SerializeKeys(const JSHandle &obj, const JSHandl JSHandle jsHclass(thread_, obj->GetJSHClass()); JSTaggedValue enumCache = jsHclass->GetEnumCache(); if (!enumCache.IsNull()) { - int propsNumber = jsHclass->NumberOfProps(); + int propsNumber = static_cast(jsHclass->NumberOfProps()); JSHandle cache(thread_, enumCache); uint32_t length = cache->GetLength(); for (uint32_t i = 0; i < length; i++) { @@ -711,8 +711,8 @@ bool JsonStringifier::SerializeKeys(const JSHandle &obj, const JSHandl PropertyAttributes attr(layoutInfo->GetAttr(index)); ASSERT(static_cast(attr.GetOffset()) == index); value = attr.IsInlinedProps() - ? obj->GetPropertyInlinedProps(index) - : propertiesArr->Get(index - jsHclass->GetInlinedProperties()); + ? obj->GetPropertyInlinedProps(static_cast(index)) + : propertiesArr->Get(static_cast(index - jsHclass->GetInlinedProperties())); if (UNLIKELY(value.IsAccessor())) { value = JSObject::CallGetter(thread_, AccessorData::Cast(value.GetTaggedObject()), JSHandle(obj)); @@ -723,11 +723,11 @@ bool JsonStringifier::SerializeKeys(const JSHandle &obj, const JSHandl } return hasContent; } - int end = jsHclass->NumberOfProps(); + int end = static_cast(jsHclass->NumberOfProps()); if (end <= 0) { return hasContent; } - int propsNumber = jsHclass->NumberOfProps(); + int propsNumber = static_cast(jsHclass->NumberOfProps()); for (int i = 0; i < end; i++) { LayoutInfo *layoutInfo = LayoutInfo::Cast(jsHclass->GetLayout().GetTaggedObject()); JSTaggedValue key = layoutInfo->GetKey(i); @@ -738,8 +738,8 @@ bool JsonStringifier::SerializeKeys(const JSHandle &obj, const JSHandl PropertyAttributes attr(layoutInfo->GetAttr(index)); ASSERT(static_cast(attr.GetOffset()) == index); value = attr.IsInlinedProps() - ? obj->GetPropertyInlinedProps(index) - : propertiesArr->Get(index - jsHclass->GetInlinedProperties()); + ? obj->GetPropertyInlinedProps(static_cast(index)) + : propertiesArr->Get(static_cast(index - jsHclass->GetInlinedProperties())); if (UNLIKELY(value.IsAccessor())) { value = JSObject::CallGetter(thread_, AccessorData::Cast(value.GetTaggedObject()), JSHandle(obj)); diff --git a/ecmascript/base/number_helper.cpp b/ecmascript/base/number_helper.cpp index 805d480d68..beb33ba6c2 100644 --- a/ecmascript/base/number_helper.cpp +++ b/ecmascript/base/number_helper.cpp @@ -238,7 +238,7 @@ JSTaggedValue NumberHelper::StringToDoubleWithRadix(const uint8_t *start, const break; } - int currentBit = ToDigit(*p); + int currentBit = static_cast(ToDigit(*p)); if (currentBit >= radix) { isDone = true; break; @@ -581,10 +581,10 @@ double NumberHelper::StringToDouble(const uint8_t *start, const uint8_t *end, ui } uint8_t digit; while ((digit = ToDigit(*p)) < radix) { - if (additionalExponent > MAX_EXPONENT / radix) { + if (additionalExponent > static_cast(MAX_EXPONENT / radix)) { additionalExponent = MAX_EXPONENT; } else { - additionalExponent = additionalExponent * radix + digit; + additionalExponent = static_cast(additionalExponent * radix + digit); } if (++p == end) { break; diff --git a/ecmascript/base/string_helper.cpp b/ecmascript/base/string_helper.cpp index fb1355d5a1..cdc8ae2e30 100644 --- a/ecmascript/base/string_helper.cpp +++ b/ecmascript/base/string_helper.cpp @@ -81,7 +81,7 @@ EcmaString *StringHelper::Trim(JSThread *thread, const std::u16string &thisStr) const char16_t *constChar16tData = tmpStr.data(); auto *char16tData = const_cast(constChar16tData); auto *uint16tData = reinterpret_cast(char16tData); - int32_t length = tmpStr.size(); + uint32_t length = tmpStr.size(); return *factory->NewFromUtf16(uint16tData, length); } } // namespace panda::ecmascript::base diff --git a/ecmascript/base/string_helper.h b/ecmascript/base/string_helper.h index a4b09ff0d9..31455ad77a 100644 --- a/ecmascript/base/string_helper.h +++ b/ecmascript/base/string_helper.h @@ -186,7 +186,7 @@ public: static inline std::string Utf32ToString(uint32_t u32Data) { - UChar32 charData = u32Data; + UChar32 charData = static_cast(u32Data); icu::UnicodeString uString(charData); std::string res; uString.toUTF8String(res); diff --git a/ecmascript/base/typed_array_helper.cpp b/ecmascript/base/typed_array_helper.cpp index 104afedeaa..b28c18d218 100644 --- a/ecmascript/base/typed_array_helper.cpp +++ b/ecmascript/base/typed_array_helper.cpp @@ -111,7 +111,7 @@ JSTaggedValue TypedArrayHelper::CreateFromOrdinaryObject(EcmaRuntimeCallInfo *ar vec.push_back(nextValue); } } - int32_t len = vec.size(); + int32_t len = static_cast(vec.size()); TypedArrayHelper::AllocateTypedArrayBuffer(thread, ecmaVm, obj, len); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // d. Let k be 0. @@ -276,11 +276,11 @@ JSTaggedValue TypedArrayHelper::CreateFromArrayBuffer(EcmaRuntimeCallInfo *argv, [[maybe_unused]] EcmaHandleScope handleScope(thread); // 5. Let elementSize be the Element Size value specified in Table 61 for constructorName. // 6. Let offset be ? ToIndex(byteOffset). - int32_t elementSize = TypedArrayHelper::GetSizeFromName(thread, constructorName); + uint32_t elementSize = static_cast(TypedArrayHelper::GetSizeFromName(thread, constructorName)); JSHandle byteOffset = BuiltinsBase::GetCallArg(argv, 1); JSTaggedNumber index = JSTaggedValue::ToIndex(thread, byteOffset); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - auto offset = static_cast(index.GetNumber()); + auto offset = static_cast(index.GetNumber()); // 7. If offset modulo elementSize ≠ 0, throw a RangeError exception. if (offset % elementSize != 0) { THROW_RANGE_ERROR_AND_RETURN(thread, "The offset cannot be an integral multiple of elementSize.", @@ -312,7 +312,7 @@ JSTaggedValue TypedArrayHelper::CreateFromArrayBuffer(EcmaRuntimeCallInfo *argv, THROW_RANGE_ERROR_AND_RETURN(thread, "The bufferByteLength cannot be an integral multiple of elementSize.", JSTaggedValue::Exception()); } - newByteLength = bufferByteLength - offset; + newByteLength = static_cast(bufferByteLength - offset); if (newByteLength < 0) { THROW_RANGE_ERROR_AND_RETURN(thread, "The newByteLength is less than 0.", JSTaggedValue::Exception()); } diff --git a/ecmascript/base/utf_helper.cpp b/ecmascript/base/utf_helper.cpp index 88602385d1..f92c11b4a1 100644 --- a/ecmascript/base/utf_helper.cpp +++ b/ecmascript/base/utf_helper.cpp @@ -207,7 +207,7 @@ std::pair ConvertUtf8ToUtf16Pair(const uint8_t *data, bool com if (combine) { uint32_t lead = ((codePoint >> (utf::PAIR_ELEMENT_WIDTH - utf::DATA_WIDTH)) + utf::U16_LEAD); uint32_t tail = ((codePoint & utf::MASK_10BIT) + utf::U16_TAIL) & utf::MASK_16BIT; - pair = U16_GET_SUPPLEMENTARY(lead, tail); // NOLINTNEXTLINE(hicpp-signed-bitwise) + pair = static_cast(U16_GET_SUPPLEMENTARY(lead, tail)); // NOLINTNEXTLINE(hicpp-signed-bitwise) } else { pair |= ((codePoint >> (utf::PAIR_ELEMENT_WIDTH - utf::DATA_WIDTH)) + utf::U16_LEAD) << utf::PAIR_ELEMENT_WIDTH; pair |= ((codePoint & utf::MASK_10BIT) + utf::U16_TAIL) & utf::MASK_16BIT; diff --git a/ecmascript/builtins/builtins_array.cpp b/ecmascript/builtins/builtins_array.cpp index 0ab066913e..46c4ec903d 100644 --- a/ecmascript/builtins/builtins_array.cpp +++ b/ecmascript/builtins/builtins_array.cpp @@ -1195,7 +1195,7 @@ JSTaggedValue BuiltinsArray::Join(EcmaRuntimeCallInfo *argv) JSHandle sepStringHandle = JSTaggedValue::ToString(thread, sepHandle); // 7. ReturnIfAbrupt(sep). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - int32_t sepLen = sepStringHandle->GetLength(); + uint32_t sepLen = sepStringHandle->GetLength(); std::u16string sepStr; if (sepStringHandle->IsUtf16()) { sepStr = base::StringHelper::Utf16ToU16String(sepStringHandle->GetDataUtf16(), sepLen); @@ -1228,7 +1228,7 @@ JSTaggedValue BuiltinsArray::Join(EcmaRuntimeCallInfo *argv) if (!element->IsUndefined() && !element->IsNull()) { JSHandle nextStringHandle = JSTaggedValue::ToString(thread, element); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - int32_t nextLen = nextStringHandle->GetLength(); + uint32_t nextLen = nextStringHandle->GetLength(); if (nextStringHandle->IsUtf16()) { nextStr = base::StringHelper::Utf16ToU16String(nextStringHandle->GetDataUtf16(), nextLen); } else { @@ -1247,7 +1247,7 @@ JSTaggedValue BuiltinsArray::Join(EcmaRuntimeCallInfo *argv) const char16_t *constChar16tData = concatStr.data(); auto *char16tData = const_cast(constChar16tData); auto *uint16tData = reinterpret_cast(char16tData); - int32_t u16strSize = concatStr.size(); + uint32_t u16strSize = concatStr.size(); return factory->NewFromUtf16Literal(uint16tData, u16strSize).GetTaggedValue(); } diff --git a/ecmascript/builtins/builtins_arraybuffer.cpp b/ecmascript/builtins/builtins_arraybuffer.cpp index e9c980b75f..f6e538b31b 100644 --- a/ecmascript/builtins/builtins_arraybuffer.cpp +++ b/ecmascript/builtins/builtins_arraybuffer.cpp @@ -128,7 +128,7 @@ JSTaggedValue BuiltinsArrayBuffer::Slice(EcmaRuntimeCallInfo *argv) THROW_TYPE_ERROR_AND_RETURN(thread, "this value IsDetachedBuffer", JSTaggedValue::Exception()); } // 5. Let len be the value of O’s [[ArrayBufferByteLength]] internal slot. - int32_t len = arrBuf->GetArrayBufferByteLength(); + int32_t len = static_cast(arrBuf->GetArrayBufferByteLength()); JSHandle startHandle = GetCallArg(argv, 0); // 6. Let relativeStart be ToInteger(start). JSTaggedNumber relativeStart = JSTaggedValue::ToInteger(thread, startHandle); @@ -284,7 +284,7 @@ JSTaggedValue BuiltinsArrayBuffer::CloneArrayBuffer(JSThread *thread, const JSHa // 5. Assert: srcByteOffset ≤ srcLength. ASSERT(srcByteOffset <= srcLen); // 6. Let cloneLength be srcLength – srcByteOffset. - int32_t cloneLen = srcLen - srcByteOffset; + int32_t cloneLen = static_cast(srcLen - srcByteOffset); // 8. Let targetBuffer be AllocateArrayBuffer(cloneConstructor, cloneLength). JSTaggedValue taggedBuf = AllocateArrayBuffer(thread, constructor, cloneLen); // 9. ReturnIfAbrupt(targetBuffer). @@ -559,7 +559,7 @@ void BuiltinsArrayBuffer::SetValueInBufferForUint8Clamped(double val, uint8_t *b val = val >= UINT8_MAX ? UINT8_MAX : val; constexpr double HALF = 0.5; val = val == HALF ? 0 : std::round(val); - res = static_cast(val); + res = static_cast(val); SetTypeData(block, res, byteIndex); } diff --git a/ecmascript/builtins/builtins_dataview.cpp b/ecmascript/builtins/builtins_dataview.cpp index 5663b42c61..64b787e9e5 100644 --- a/ecmascript/builtins/builtins_dataview.cpp +++ b/ecmascript/builtins/builtins_dataview.cpp @@ -56,7 +56,7 @@ JSTaggedValue BuiltinsDataView::DataViewConstructor(EcmaRuntimeCallInfo *argv) if (offsetInt < 0) { THROW_RANGE_ERROR_AND_RETURN(thread, "Offset out of range", JSTaggedValue::Exception()); } - uint32_t offset = offsetInt; + uint32_t offset = static_cast(offsetInt); // 8. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. if (BuiltinsArrayBuffer::IsDetachedBuffer(bufferHandle.GetTaggedValue())) { THROW_TYPE_ERROR_AND_RETURN(thread, "buffer is Detached Buffer", JSTaggedValue::Exception()); @@ -78,7 +78,7 @@ JSTaggedValue BuiltinsDataView::DataViewConstructor(EcmaRuntimeCallInfo *argv) JSTaggedNumber byteLen = JSTaggedValue::ToIndex(thread, byteLenHandle); // ReturnIfAbrupt(viewByteLength). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - viewByteLen = byteLen.ToInt32(); + viewByteLen = static_cast(byteLen.ToInt32()); // If offset+viewByteLength > bufferByteLength, throw a RangeError exception. if (offset + viewByteLen > bufByteLen) { THROW_RANGE_ERROR_AND_RETURN(thread, "offset + viewByteLen > bufByteLen", JSTaggedValue::Exception()); @@ -347,7 +347,7 @@ JSTaggedValue BuiltinsDataView::GetViewValue(JSThread *thread, const JSHandle(indexInt); // 7. Let isLittleEndian be ToBoolean(isLittleEndian). bool isLittleEndian = false; if (littleEndian.IsUndefined()) { @@ -424,11 +424,11 @@ JSTaggedValue BuiltinsDataView::SetViewValue(JSThread *thread, const JSHandle viewSize, throw a RangeError exception. - if (index + elementSize > size) { + if (static_cast(index) + elementSize > size) { THROW_RANGE_ERROR_AND_RETURN(thread, "getIndex +elementSize > viewSize", JSTaggedValue::Exception()); } // 14. Let bufferIndex be getIndex + viewOffset. - uint32_t bufferIndex = index + offset; + uint32_t bufferIndex = static_cast(index) + offset; // 15. Return SetValueFromBuffer(buffer, bufferIndex, type, value, isLittleEndian). return BuiltinsArrayBuffer::SetValueInBuffer(thread, buffer, bufferIndex, type, numValueHandle, isLittleEndian); } diff --git a/ecmascript/builtins/builtins_global.cpp b/ecmascript/builtins/builtins_global.cpp index fd15c942b4..332c74a978 100644 --- a/ecmascript/builtins/builtins_global.cpp +++ b/ecmascript/builtins/builtins_global.cpp @@ -201,7 +201,7 @@ JSTaggedValue BuiltinsGlobal::Encode(JSThread *thread, const JSHandle(resStr.data()); - int32_t resSize = resStr.size(); + uint32_t resSize = resStr.size(); return factory->NewFromUtf16Literal(uint16tData, resSize).GetTaggedValue(); } @@ -261,7 +261,7 @@ JSTaggedValue BuiltinsGlobal::Encode(JSThread *thread, const JSHandle(oct.at(j)); tmpStr << '%' << hexStr.at((joct >> 4U) & BIT_MASK) // NOLINT << hexStr.at(joct & BIT_MASK); // 4: means shift right by 4 digits } @@ -300,7 +300,7 @@ JSTaggedValue BuiltinsGlobal::Decode(JSThread *thread, const JSHandle(resStr.data()); - int32_t resSize = resStr.size(); + uint32_t resSize = resStr.size(); return factory->NewFromUtf16Literal(uint16tData, resSize).GetTaggedValue(); } @@ -378,7 +378,7 @@ JSTaggedValue BuiltinsGlobal::Decode(JSThread *thread, const JSHandle> 10) & 0x3FF) + 0xD800). // c. Let S be the String containing the two code units H and L. uint32_t n = 0; - while ((((bb << n) & BIT_MASK_ONE) != 0)) { + while ((((static_cast(bb) << n) & BIT_MASK_ONE) != 0)) { n++; if (n > 4) // 4 : 4 means less than 4 break; diff --git a/ecmascript/builtins/builtins_math.cpp b/ecmascript/builtins/builtins_math.cpp index 6121227e56..69d32de8c6 100644 --- a/ecmascript/builtins/builtins_math.cpp +++ b/ecmascript/builtins/builtins_math.cpp @@ -363,9 +363,9 @@ JSTaggedValue BuiltinsMath::Hypot(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); double result = 0; double value = 0; - int argLen = argv->GetArgsNumber(); + uint32_t argLen = argv->GetArgsNumber(); auto numberValue = JSTaggedNumber(0); - for (int i = 0; i < argLen; i++) { + for (uint32_t i = 0; i < argLen; i++) { JSHandle msg = GetCallArg(argv, i); numberValue = JSTaggedValue::ToNumber(thread, msg); value = numberValue.GetNumber(); @@ -482,13 +482,13 @@ JSTaggedValue BuiltinsMath::Max(EcmaRuntimeCallInfo *argv) BUILTINS_API_TRACE(argv->GetThread(), Math, Max); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handleScope(thread); - int argLen = argv->GetArgsNumber(); + uint32_t argLen = argv->GetArgsNumber(); auto numberValue = JSTaggedNumber(-base::POSITIVE_INFINITY); // If no arguments are given, the result is -inf auto result = JSTaggedNumber(-base::POSITIVE_INFINITY); auto tmpMax = -base::POSITIVE_INFINITY; auto value = -base::POSITIVE_INFINITY; - for (int i = 0; i < argLen; i++) { + for (uint32_t i = 0; i < argLen; i++) { JSHandle msg = GetCallArg(argv, i); numberValue = JSTaggedValue::ToNumber(thread, msg); value = numberValue.GetNumber(); @@ -516,13 +516,13 @@ JSTaggedValue BuiltinsMath::Min(EcmaRuntimeCallInfo *argv) BUILTINS_API_TRACE(argv->GetThread(), Math, Min); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handleScope(thread); - int argLen = argv->GetArgsNumber(); + uint32_t argLen = argv->GetArgsNumber(); auto numberValue = JSTaggedNumber(base::POSITIVE_INFINITY); // If no arguments are given, the result is inf auto result = JSTaggedNumber(base::POSITIVE_INFINITY); auto tmpMin = base::POSITIVE_INFINITY; auto value = base::POSITIVE_INFINITY; - for (int i = 0; i < argLen; i++) { + for (uint32_t i = 0; i < argLen; i++) { JSHandle msg = GetCallArg(argv, i); numberValue = JSTaggedValue::ToNumber(thread, msg); value = numberValue.GetNumber(); diff --git a/ecmascript/builtins/builtins_regexp.cpp b/ecmascript/builtins/builtins_regexp.cpp index 9dafa2d501..3c8b80c096 100644 --- a/ecmascript/builtins/builtins_regexp.cpp +++ b/ecmascript/builtins/builtins_regexp.cpp @@ -513,7 +513,7 @@ JSTaggedValue BuiltinsRegExp::RegExpReplaceFast(JSThread *thread, JSHandle(thisIndex.GetInt()); } else { JSHandle thisIndexHandle(thread, thisIndex); lastIndex = JSTaggedValue::ToLength(thread, thisIndexHandle).GetNumber(); @@ -751,7 +751,7 @@ JSTaggedValue BuiltinsRegExp::Replace(EcmaRuntimeCallInfo *argv) thread, FastRuntimeStub::FastGetProperty(thread, thisObj.GetTaggedValue(), lastIndex.GetTaggedValue())); uint32_t thisIndex = 0; if (thisIndexHandle->IsInt()) { - thisIndex = thisIndexHandle->GetInt(); + thisIndex = static_cast(thisIndexHandle->GetInt()); } else { thisIndex = JSTaggedValue::ToLength(thread, thisIndexHandle).GetNumber(); // b. ReturnIfAbrupt(thisIndex). @@ -802,7 +802,7 @@ JSTaggedValue BuiltinsRegExp::Replace(EcmaRuntimeCallInfo *argv) JSHandle positionHandle(thread, positionTag); uint32_t position = 0; if (positionHandle->IsInt()) { - position = positionHandle->GetInt(); + position = static_cast(positionHandle->GetInt()); } else { position = JSTaggedValue::ToUint32(thread, positionHandle); // h. ReturnIfAbrupt(position). @@ -1325,7 +1325,7 @@ JSTaggedValue BuiltinsRegExp::RegExpBuiltinExec(JSThread *thread, const JSHandle JSHandle flagsStr = JSTaggedValue::ToString(thread, flagsValue); JSHandle uString(globalConst->GetHandledUString()); [[maybe_unused]] bool fullUnicode = base::StringHelper::Contains(*flagsStr, *uString); - if (lastIndex > length) { + if (lastIndex > static_cast(length)) { FastRuntimeStub::FastSetPropertyByValue(thread, regexp.GetTaggedValue(), lastIndexHandle.GetTaggedValue(), JSTaggedValue(0)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -1742,7 +1742,7 @@ void RegExpExecResultCache::AddResultInCache(JSThread *thread, JSHandleMatch(entry, patternValue, flagsValue, inputValue, extend)) { cache->UpdateResultArray(thread, entry, resultArray.GetTaggedValue(), type); } else { - uint32_t entry2 = (entry + 1) & (cache->GetCacheLength() - 1); + uint32_t entry2 = (entry + 1) & static_cast(cache->GetCacheLength() - 1); uint32_t index2 = CACHE_TABLE_HEADER_SIZE + entry2 * ENTRY_SIZE; JSHandle extendHandle(thread, extend); if (cache->GetCacheLength() < DEFAULT_CACHE_NUMBER) { @@ -1753,7 +1753,7 @@ void RegExpExecResultCache::AddResultInCache(JSThread *thread, JSHandleSetCacheLength(thread, DEFAULT_CACHE_NUMBER); - entry2 = hash & (cache->GetCacheLength() - 1); + entry2 = hash & static_cast(cache->GetCacheLength() - 1); index2 = CACHE_TABLE_HEADER_SIZE + entry2 * ENTRY_SIZE; } JSTaggedValue extendValue = extendHandle.GetTaggedValue(); diff --git a/ecmascript/builtins/builtins_string.cpp b/ecmascript/builtins/builtins_string.cpp index 7649ab2165..b39a14cc9c 100644 --- a/ecmascript/builtins/builtins_string.cpp +++ b/ecmascript/builtins/builtins_string.cpp @@ -86,7 +86,7 @@ JSTaggedValue BuiltinsString::FromCharCode(EcmaRuntimeCallInfo *argv) JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handleScope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - int32_t argLength = argv->GetArgsNumber(); + uint32_t argLength = argv->GetArgsNumber(); if (argLength == 0) { return factory->GetEmptyString().GetTaggedValue(); } @@ -100,7 +100,7 @@ JSTaggedValue BuiltinsString::FromCharCode(EcmaRuntimeCallInfo *argv) std::u16string u16str = base::StringHelper::Utf16ToU16String(&codePointValue, 1); CVector valueTable; valueTable.reserve(argLength - 1); - for (int32_t i = 1; i < argLength; i++) { + for (uint32_t i = 1; i < argLength; i++) { JSHandle nextCp = BuiltinsString::GetCallArg(argv, i); uint16_t nextCv = JSTaggedValue::ToUint16(thread, nextCp); valueTable.emplace_back(nextCv); @@ -111,7 +111,7 @@ JSTaggedValue BuiltinsString::FromCharCode(EcmaRuntimeCallInfo *argv) const char16_t *constChar16tData = u16str.data(); auto *char16tData = const_cast(constChar16tData); auto *uint16tData = reinterpret_cast(char16tData); - int32_t u16strSize = u16str.size(); + uint32_t u16strSize = u16str.size(); return factory->NewFromUtf16Literal(uint16tData, u16strSize).GetTaggedValue(); } @@ -123,13 +123,13 @@ JSTaggedValue BuiltinsString::FromCodePoint(EcmaRuntimeCallInfo *argv) JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handleScope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - int32_t argLength = argv->GetArgsNumber(); + uint32_t argLength = argv->GetArgsNumber(); if (argLength == 0) { return factory->GetEmptyString().GetTaggedValue(); } std::u16string u16str; - int32_t u16strSize = argLength; - for (int i = 0; i < argLength; i++) { + uint32_t u16strSize = argLength; + for (uint32_t i = 0; i < argLength; i++) { JSHandle nextCpTag = BuiltinsString::GetCallArg(argv, i); JSTaggedNumber nextCpVal = JSTaggedValue::ToNumber(thread, nextCpTag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -145,8 +145,10 @@ JSTaggedValue BuiltinsString::FromCodePoint(EcmaRuntimeCallInfo *argv) return factory->NewFromUtf16Literal(data.data(), 1).GetTaggedValue(); } if (cp > UINT16_MAX) { - uint16_t cu1 = std::floor((cp - ENCODE_SECOND_FACTOR) / ENCODE_FIRST_FACTOR) + ENCODE_LEAD_LOW; - uint16_t cu2 = ((cp - ENCODE_SECOND_FACTOR) % ENCODE_FIRST_FACTOR) + ENCODE_TRAIL_LOW; + uint16_t cu1 = + std::floor((static_cast(cp) - ENCODE_SECOND_FACTOR) / ENCODE_FIRST_FACTOR) + ENCODE_LEAD_LOW; + uint16_t cu2 = + ((static_cast(cp) - ENCODE_SECOND_FACTOR) % ENCODE_FIRST_FACTOR) + ENCODE_TRAIL_LOW; std::u16string nextU16str1 = base::StringHelper::Utf16ToU16String(&cu1, 1); std::u16string nextU16str2 = base::StringHelper::Utf16ToU16String(&cu2, 1); u16str = base::StringHelper::Append(u16str, nextU16str1); @@ -190,7 +192,7 @@ JSTaggedValue BuiltinsString::Raw(EcmaRuntimeCallInfo *argv) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); JSTaggedNumber lengthNumber = JSTaggedValue::ToLength(thread, rawLen); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - int length = lengthNumber.ToUint32(); + int length = static_cast(lengthNumber.ToUint32()); if (length <= 0) { return factory->GetEmptyString().GetTaggedValue(); } @@ -242,7 +244,7 @@ JSTaggedValue BuiltinsString::CharAt(EcmaRuntimeCallInfo *argv) JSHandle thisTag(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv))); JSHandle thisHandle = JSTaggedValue::ToString(thread, thisTag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - int32_t thisLen = thisHandle->GetLength(); + int32_t thisLen = static_cast(thisHandle->GetLength()); JSHandle posTag = BuiltinsString::GetCallArg(argv, 0); int32_t pos; if (posTag->IsUndefined()) { @@ -269,7 +271,7 @@ JSTaggedValue BuiltinsString::CharCodeAt(EcmaRuntimeCallInfo *argv) JSHandle thisTag(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv))); JSHandle thisHandle = JSTaggedValue::ToString(thread, thisTag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - int32_t thisLen = thisHandle->GetLength(); + int32_t thisLen = static_cast(thisHandle->GetLength()); JSHandle posTag = BuiltinsString::GetCallArg(argv, 0); int32_t pos; if (posTag->IsUndefined()) { @@ -301,7 +303,7 @@ JSTaggedValue BuiltinsString::CodePointAt(EcmaRuntimeCallInfo *argv) JSTaggedNumber posVal = JSTaggedValue::ToNumber(thread, posTag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); int32_t pos = base::NumberHelper::DoubleInRangeInt32(posVal.GetNumber()); - int32_t thisLen = thisHandle->GetLength(); + int32_t thisLen = static_cast(thisHandle->GetLength()); if (pos < 0 || pos >= thisLen) { return JSTaggedValue::Undefined(); } @@ -328,8 +330,8 @@ JSTaggedValue BuiltinsString::Concat(EcmaRuntimeCallInfo *argv) JSHandle thisTag(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv))); JSHandle thisHandle = JSTaggedValue::ToString(thread, thisTag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - int32_t thisLen = thisHandle->GetLength(); - int32_t argLength = argv->GetArgsNumber(); + uint32_t thisLen = thisHandle->GetLength(); + uint32_t argLength = argv->GetArgsNumber(); if (argLength == 0) { return thisHandle.GetTaggedValue(); } @@ -342,10 +344,10 @@ JSTaggedValue BuiltinsString::Concat(EcmaRuntimeCallInfo *argv) } else { u16strThis = base::StringHelper::Utf8ToU16String(thisHandle->GetDataUtf8(), thisLen); } - for (int i = 0; i < argLength; i++) { + for (uint32_t i = 0; i < argLength; i++) { JSHandle nextTag = BuiltinsString::GetCallArg(argv, i); JSHandle nextHandle = JSTaggedValue::ToString(thread, nextTag); - int32_t nextLen = nextHandle->GetLength(); + uint32_t nextLen = nextHandle->GetLength(); if (nextHandle->IsUtf16()) { u16strNext = base::StringHelper::Utf16ToU16String(nextHandle->GetDataUtf16(), nextLen); canBeCompress = false; @@ -380,9 +382,9 @@ JSTaggedValue BuiltinsString::EndsWith(EcmaRuntimeCallInfo *argv) } JSHandle searchHandle = JSTaggedValue::ToString(thread, searchTag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - int32_t thisLen = thisHandle->GetLength(); - int32_t searchLen = searchHandle->GetLength(); - int32_t pos; + uint32_t thisLen = thisHandle->GetLength(); + uint32_t searchLen = searchHandle->GetLength(); + uint32_t pos; JSHandle posTag = BuiltinsString::GetCallArg(argv, 1); if (posTag->IsUndefined()) { pos = thisLen; @@ -391,8 +393,8 @@ JSTaggedValue BuiltinsString::EndsWith(EcmaRuntimeCallInfo *argv) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); pos = posVal.ToInt32(); } - int32_t end = std::min(std::max(pos, 0), thisLen); - int32_t start = end - searchLen; + uint32_t end = std::min(std::max(pos, 0U), thisLen); + int32_t start = static_cast(end - searchLen); if (start < 0) { return BuiltinsString::GetTaggedBoolean(false); } @@ -410,7 +412,7 @@ JSTaggedValue BuiltinsString::EndsWith(EcmaRuntimeCallInfo *argv) const uint8_t *uint8Search = searchHandle->GetDataUtf8(); u16strSearch = base::StringHelper::Utf8ToU16String(uint8Search, searchLen); } - int32_t idx = base::StringHelper::Find(u16strThis, u16strSearch, start); + int32_t idx = static_cast(base::StringHelper::Find(u16strThis, u16strSearch, start)); if (idx == start) { return BuiltinsString::GetTaggedBoolean(true); } @@ -434,8 +436,8 @@ JSTaggedValue BuiltinsString::Includes(EcmaRuntimeCallInfo *argv) } JSHandle searchHandle = JSTaggedValue::ToString(thread, searchTag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - int32_t thisLen = thisHandle->GetLength(); - int32_t searchLen = searchHandle->GetLength(); + uint32_t thisLen = thisHandle->GetLength(); + uint32_t searchLen = searchHandle->GetLength(); int32_t pos = 0; JSHandle posTag = BuiltinsBase::GetCallArg(argv, 1); if (argv->GetArgsNumber() == 1) { @@ -445,7 +447,7 @@ JSTaggedValue BuiltinsString::Includes(EcmaRuntimeCallInfo *argv) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); pos = base::NumberHelper::DoubleInRangeInt32(posVal.GetNumber()); } - int32_t start = std::min(std::max(pos, 0), thisLen); + int32_t start = std::min(std::max(pos, 0), static_cast(thisLen)); std::u16string u16strThis; std::u16string u16strSearch; if (thisHandle->IsUtf16()) { @@ -460,7 +462,7 @@ JSTaggedValue BuiltinsString::Includes(EcmaRuntimeCallInfo *argv) const uint8_t *uint8Search = searchHandle->GetDataUtf8(); u16strSearch = base::StringHelper::Utf8ToU16String(uint8Search, searchLen); } - int32_t idx = base::StringHelper::Find(u16strThis, u16strSearch, start); + uint32_t idx = base::StringHelper::Find(u16strThis, u16strSearch, start); if (idx < 0 || idx > thisLen) { return BuiltinsString::GetTaggedBoolean(false); } @@ -478,7 +480,7 @@ JSTaggedValue BuiltinsString::IndexOf(EcmaRuntimeCallInfo *argv) JSHandle thisTag(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv))); JSHandle thisHandle = JSTaggedValue::ToString(thread, thisTag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - int32_t thisLen = thisHandle->GetLength(); + uint32_t thisLen = thisHandle->GetLength(); JSHandle searchHandle = JSTaggedValue::ToString(thread, searchTag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); int32_t searchLen = searchHandle->GetLength(); @@ -491,11 +493,11 @@ JSTaggedValue BuiltinsString::IndexOf(EcmaRuntimeCallInfo *argv) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); pos = posVal.ToInt32(); } - pos = std::min(std::max(pos, 0), thisLen); + pos = std::min(std::max(pos, 0), static_cast(thisLen)); if (thisHandle->IsUtf8() && searchHandle->IsUtf8()) { std::string thisString = base::StringHelper::Utf8ToString(thisHandle->GetDataUtf8(), thisLen); std::string searchString = base::StringHelper::Utf8ToString(searchHandle->GetDataUtf8(), searchLen); - int32_t res = base::StringHelper::Find(thisString, searchString, pos); + uint32_t res = base::StringHelper::Find(thisString, searchString, pos); if (res >= 0 && res < thisLen) { return GetTaggedInt(res); } @@ -515,7 +517,7 @@ JSTaggedValue BuiltinsString::IndexOf(EcmaRuntimeCallInfo *argv) const uint8_t *uint8Search = searchHandle->GetDataUtf8(); u16strSearch = base::StringHelper::Utf8ToU16String(uint8Search, searchLen); } - int32_t res = base::StringHelper::Find(u16strThis, u16strSearch, pos); + uint32_t res = base::StringHelper::Find(u16strThis, u16strSearch, pos); if (res >= 0 && res < thisLen) { return GetTaggedInt(res); } @@ -533,11 +535,11 @@ JSTaggedValue BuiltinsString::LastIndexOf(EcmaRuntimeCallInfo *argv) JSHandle thisTag(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv))); JSHandle thisHandle = JSTaggedValue::ToString(thread, thisTag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - int32_t thisLen = thisHandle->GetLength(); + uint32_t thisLen = thisHandle->GetLength(); JSHandle searchHandle = JSTaggedValue::ToString(thread, searchTag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - int32_t searchLen = searchHandle->GetLength(); - int32_t pos; + uint32_t searchLen = searchHandle->GetLength(); + uint32_t pos; if (argv->GetArgsNumber() == 1) { pos = thisLen; } else { @@ -547,10 +549,10 @@ JSTaggedValue BuiltinsString::LastIndexOf(EcmaRuntimeCallInfo *argv) if (std::isnan(JSTaggedValue::ToNumber(thread, posTag).GetNumber())) { pos = thisLen; } else { - pos = posVal.ToInt32(); + pos = static_cast(posVal.ToInt32()); } } - pos = std::min(std::max(pos, 0), thisLen); + pos = std::min(std::max(pos, 0U), thisLen); std::u16string u16strThis; std::u16string u16strSearch; if (thisHandle->IsUtf16()) { @@ -565,7 +567,7 @@ JSTaggedValue BuiltinsString::LastIndexOf(EcmaRuntimeCallInfo *argv) const uint8_t *uint8Search = searchHandle->GetDataUtf8(); u16strSearch = base::StringHelper::Utf8ToU16String(uint8Search, searchLen); } - int32_t res = base::StringHelper::RFind(u16strThis, u16strSearch, pos); + uint32_t res = base::StringHelper::RFind(u16strThis, u16strSearch, pos); if (res >= 0 && res < thisLen) { return GetTaggedInt(res); } @@ -707,7 +709,7 @@ JSTaggedValue BuiltinsString::Repeat(EcmaRuntimeCallInfo *argv) JSHandle thisTag(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv))); JSHandle thisHandle = JSTaggedValue::ToString(thread, thisTag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - int32_t thisLen = thisHandle->GetLength(); + uint32_t thisLen = thisHandle->GetLength(); JSHandle countTag = BuiltinsString::GetCallArg(argv, 0); JSTaggedNumber num = JSTaggedValue::ToInteger(thread, countTag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -948,7 +950,7 @@ JSTaggedValue BuiltinsString::GetSubstitution(JSThread *thread, const JSHandleGetLength(); + int32_t srcLength = static_cast(srcString->GetLength()); if (tailPos < srcLength) { EcmaString *sufffix = EcmaString::FastSubString(srcString, tailPos, srcLength - tailPos, ecmaVm); if (sufffix->IsUtf16()) { @@ -973,15 +975,15 @@ JSTaggedValue BuiltinsString::GetSubstitution(JSThread *thread, const JSHandleGetLength(); + uint32_t capturesLength = captureList->GetLength(); // Valid indices are $1 .. $9, $01 .. $09 and $10 .. $99 - int32_t scaledIndex = (peek - '0'); + uint32_t scaledIndex = peek - '0'; int32_t advance = 1; if (peekIndex + 1 < replaceLength) { uint16_t nextPeek = replacement->At(peekIndex + 1); if (nextPeek >= '0' && nextPeek <= '9') { - constexpr int32_t TEN_BASE = 10; - int32_t newScaledIndex = scaledIndex * TEN_BASE + (nextPeek - '0'); + constexpr uint32_t TEN_BASE = 10; + uint32_t newScaledIndex = scaledIndex * TEN_BASE + (nextPeek - '0'); if (newScaledIndex <= capturesLength) { scaledIndex = newScaledIndex; advance = 2; // 2: 2 means from index needs to add two. @@ -1099,7 +1101,7 @@ JSTaggedValue BuiltinsString::Slice(EcmaRuntimeCallInfo *argv) JSHandle thisTag(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv))); JSHandle thisHandle = JSTaggedValue::ToString(thread, thisTag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - int32_t thisLen = thisHandle->GetLength(); + int32_t thisLen = static_cast(thisHandle->GetLength()); JSHandle startTag = BuiltinsString::GetCallArg(argv, 0); JSTaggedNumber startVal = JSTaggedValue::ToInteger(thread, startTag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -1181,7 +1183,7 @@ JSTaggedValue BuiltinsString::Split(EcmaRuntimeCallInfo *argv) return resultArray.GetTaggedValue(); } // Let s be the number of elements in S. - int32_t thisLength = thisString->GetLength(); + int32_t thisLength = static_cast(thisString->GetLength()); JSHandle seperatorString = JSTaggedValue::ToString(thread, seperatorTag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (seperatorTag->IsUndefined()) { @@ -1234,8 +1236,8 @@ JSTaggedValue BuiltinsString::Split(EcmaRuntimeCallInfo *argv) int32_t BuiltinsString::SplitMatch(const JSHandle &str, int32_t q, const JSHandle ®) { - int32_t s = str->GetLength(); - int32_t r = reg->GetLength(); + int32_t s = static_cast(str->GetLength()); + int32_t r = static_cast(reg->GetLength()); if (q + r > s) { return -1; } @@ -1267,8 +1269,8 @@ JSTaggedValue BuiltinsString::StartsWith(EcmaRuntimeCallInfo *argv) JSHandle searchHandle = JSTaggedValue::ToString(thread, searchTag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - int32_t thisLen = thisHandle->GetLength(); - int32_t searchLen = searchHandle->GetLength(); + uint32_t thisLen = thisHandle->GetLength(); + uint32_t searchLen = searchHandle->GetLength(); int32_t pos; JSHandle posTag = BuiltinsString::GetCallArg(argv, 1); if (posTag->IsUndefined()) { @@ -1278,8 +1280,8 @@ JSTaggedValue BuiltinsString::StartsWith(EcmaRuntimeCallInfo *argv) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); pos = posVal.ToInt32(); } - pos = std::min(std::max(pos, 0), thisLen); - if (pos + searchLen > thisLen) { + pos = std::min(std::max(pos, 0), static_cast(thisLen)); + if (static_cast(pos + searchLen) > thisLen) { return BuiltinsString::GetTaggedBoolean(false); } std::u16string u16strThis; @@ -1296,8 +1298,8 @@ JSTaggedValue BuiltinsString::StartsWith(EcmaRuntimeCallInfo *argv) const uint8_t *uint8Search = searchHandle->GetDataUtf8(); u16strSearch = base::StringHelper::Utf8ToU16String(uint8Search, searchLen); } - int32_t idx = base::StringHelper::Find(u16strThis, u16strSearch, pos); - if (idx == pos) { + uint32_t idx = base::StringHelper::Find(u16strThis, u16strSearch, pos); + if (static_cast(idx) == pos) { return BuiltinsString::GetTaggedBoolean(true); } return BuiltinsString::GetTaggedBoolean(false); @@ -1482,7 +1484,7 @@ JSTaggedValue BuiltinsString::ToLowerCase(EcmaRuntimeCallInfo *argv) JSHandle thisTag(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv))); JSHandle thisHandle = JSTaggedValue::ToString(thread, thisTag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - int32_t thisLen = thisHandle->GetLength(); + uint32_t thisLen = thisHandle->GetLength(); std::u16string u16strThis; if (thisHandle->IsUtf16()) { u16strThis = base::StringHelper::Utf16ToU16String(thisHandle->GetDataUtf16(), thisLen); @@ -1511,7 +1513,7 @@ JSTaggedValue BuiltinsString::ToUpperCase(EcmaRuntimeCallInfo *argv) JSHandle thisTag(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv))); JSHandle thisHandle = JSTaggedValue::ToString(thread, thisTag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - int32_t thisLen = thisHandle->GetLength(); + uint32_t thisLen = thisHandle->GetLength(); std::u16string u16strThis; if (thisHandle->IsUtf16()) { u16strThis = base::StringHelper::Utf16ToU16String(thisHandle->GetDataUtf16(), thisLen); @@ -1532,7 +1534,7 @@ JSTaggedValue BuiltinsString::Trim(EcmaRuntimeCallInfo *argv) JSHandle thisTag(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv))); JSHandle thisHandle = JSTaggedValue::ToString(thread, thisTag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - int32_t thisLen = thisHandle->GetLength(); + uint32_t thisLen = thisHandle->GetLength(); std::u16string u16strThis; if (thisHandle->IsUtf16()) { u16strThis = base::StringHelper::Utf16ToU16String(thisHandle->GetDataUtf16(), thisLen); @@ -1604,7 +1606,7 @@ JSTaggedValue BuiltinsString::SubStr(EcmaRuntimeCallInfo *argv) end = lengthNumber.ToInt32(); } // 8. Let size be the number of code units in S. - int32_t size = thisString->GetLength(); + int32_t size = static_cast(thisString->GetLength()); // 9. If intStart < 0, let intStart be max(size + intStart,0). if (start < 0) { start = std::max(size + start, 0); diff --git a/ecmascript/builtins/builtins_typedarray.cpp b/ecmascript/builtins/builtins_typedarray.cpp index 27ea0ed04b..65b3a1b6f6 100644 --- a/ecmascript/builtins/builtins_typedarray.cpp +++ b/ecmascript/builtins/builtins_typedarray.cpp @@ -713,7 +713,8 @@ JSTaggedValue BuiltinsTypedArray::Join(EcmaRuntimeCallInfo *argv) THROW_TYPE_ERROR_AND_RETURN(argv->GetThread(), "This is not a TypedArray.", JSTaggedValue::Exception()); } - uint32_t length = TypedArrayHelper::GetArrayLength(thread, JSHandle::Cast(thisHandle)); + uint32_t length = + static_cast(TypedArrayHelper::GetArrayLength(thread, JSHandle::Cast(thisHandle))); JSHandle sepHandle = GetCallArg(argv, 0); int sep = ','; @@ -779,8 +780,8 @@ JSTaggedValue BuiltinsTypedArray::Join(EcmaRuntimeCallInfo *argv) current += sepLength; } JSHandle nextStr = vec[k]; - int nextLength = nextStr->GetLength(); - newString->WriteData(*nextStr, current, allocateLength - current, nextLength); + int nextLength = static_cast(nextStr->GetLength()); + newString->WriteData(*nextStr, current, static_cast(allocateLength - current), nextLength); current += nextLength; } return JSTaggedValue(newString); diff --git a/ecmascript/compiler/bytecode_circuit_builder.cpp b/ecmascript/compiler/bytecode_circuit_builder.cpp index ab8de103bd..aa9b03d333 100644 --- a/ecmascript/compiler/bytecode_circuit_builder.cpp +++ b/ecmascript/compiler/bytecode_circuit_builder.cpp @@ -121,7 +121,7 @@ void BytecodeCircuitBuilder::CollectBytecodeBlockInfo(uint8_t *pc, std::vector temp; temp.emplace_back(pc + BytecodeOffset::THREE); // first successor - int8_t offset = READ_INST_16_0(); + int8_t offset = static_cast(READ_INST_16_0()); temp.emplace_back(pc + offset); // second successor bytecodeBlockInfos.emplace_back(pc, SplitKind::END, temp); bytecodeBlockInfos.emplace_back(pc + BytecodeOffset::THREE, SplitKind::START, @@ -457,17 +457,17 @@ void BytecodeCircuitBuilder::ComputeDominatorTree(BytecodeGraph &byteCodeGraph) #endif // compute immediate dominator - immDom[0] = doms[0].front(); + immDom[0] = static_cast(doms[0].front()); for (size_t i = 1; i < doms.size(); i++) { if (graph[i].isDead) { continue; } auto it = std::remove(doms[i].begin(), doms[i].end(), i); doms[i].resize(it - doms[i].begin()); - immDom[i] = *std::max_element( + immDom[i] = static_cast(*std::max_element( doms[i].begin(), doms[i].end(), [graph, bbIdToDfsTimestamp](size_t lhs, size_t rhs) -> bool { return bbIdToDfsTimestamp.at(graph[lhs].id) < bbIdToDfsTimestamp.at(graph[rhs].id); - }); + })); } #if ECMASCRIPT_ENABLE_TS_AOT_PRINT @@ -2006,7 +2006,7 @@ GateRef BytecodeCircuitBuilder::SetGateConstant(const BytecodeInfo &info) gate = GetCommonArgByIndex(CommonArgIdx::FUNC); break; default: - abort(); + UNREACHABLE(); } return gate; } @@ -2204,7 +2204,7 @@ void BytecodeCircuitBuilder::BuildCircuit(BytecodeGraph &byteCodeGraph) auto ifTrue = circuit_.NewGate(OpCode(OpCode::IF_TRUE), 0, {gate}, GateType::EMPTY); auto ifFalse = circuit_.NewGate(OpCode(OpCode::IF_FALSE), 0, {gate}, GateType::EMPTY); ASSERT(bb.succs.size() == 2); // 2 : 2 num of successors - int bitSet = 0; + uint32_t bitSet = 0; for (auto &bbNext: bb.succs) { if (bbNext->id == bb.id + 1) { circuit_.NewIn(bbNext->stateStart, bbNext->statePredIndex, ifFalse); @@ -2270,7 +2270,7 @@ void BytecodeCircuitBuilder::BuildCircuit(BytecodeGraph &byteCodeGraph) } else if (IsDiscarded(static_cast(bytecodeInfo.opcode))) { continue; } else { - abort(); + UNREACHABLE(); } } } diff --git a/ecmascript/compiler/llvm/llvm_stackmap_parser.cpp b/ecmascript/compiler/llvm/llvm_stackmap_parser.cpp index 0541ded941..190cf0bee0 100644 --- a/ecmascript/compiler/llvm/llvm_stackmap_parser.cpp +++ b/ecmascript/compiler/llvm/llvm_stackmap_parser.cpp @@ -137,7 +137,7 @@ void LLVMStackMapParser::PrintCallSiteInfo(const CallSiteInfo *infos, uintptr_t bool LLVMStackMapParser::IsDeriveredPointer(int callsitetime) const { - return callsitetime & 1; + return static_cast(callsitetime) & 1; } bool LLVMStackMapParser::CollectStackMapSlots(uintptr_t callSiteAddr, uintptr_t frameFp, diff --git a/ecmascript/compiler/llvm_ir_builder.cpp b/ecmascript/compiler/llvm_ir_builder.cpp index f5b87d7a07..209caab24e 100644 --- a/ecmascript/compiler/llvm_ir_builder.cpp +++ b/ecmascript/compiler/llvm_ir_builder.cpp @@ -211,7 +211,7 @@ void LLVMIRBuilder::Build() for (size_t bbIdx = 0; bbIdx < schedule_->size(); bbIdx++) { for (size_t instIdx = (*schedule_)[bbIdx].size(); instIdx > 0; instIdx--) { GateId gateId = circuit_->GetId((*schedule_)[bbIdx][instIdx - 1]); - instIdMapBbId_[gateId] = bbIdx; + instIdMapBbId_[gateId] = static_cast(bbIdx); } } COMPILER_LOG(INFO) << "LLVM IR Builder Visit Gate..."; @@ -511,7 +511,7 @@ void LLVMIRBuilder::HandleRuntimeCall(GateRef gate) void LLVMIRBuilder::VisitRuntimeCall(GateRef gate, const std::vector &inList) { - int paraStartIndex = 3; + size_t paraStartIndex = 3; ASSERT(llvmModule_ != nullptr); LLVMValueRef callee; LLVMValueRef rtoffset; @@ -523,11 +523,11 @@ void LLVMIRBuilder::VisitRuntimeCall(GateRef gate, const std::vector &i if (circuit_->GetFrameType() == FrameType::INTERPRETER_FRAME || circuit_->GetFrameType() == FrameType::OPTIMIZED_ENTRY_FRAME) { rtoffset = LLVMConstInt(glueType, - JSThread::GlueData::GetRTStubEntriesOffset(compCfg_->Is32Bit()) + + static_cast(JSThread::GlueData::GetRTStubEntriesOffset(compCfg_->Is32Bit())) + (RTSTUB_ID(AsmIntCallRuntime)) * slotSize_, 0); } else if (circuit_->GetFrameType() == FrameType::OPTIMIZED_FRAME) { rtoffset = LLVMConstInt(glueType, - JSThread::GlueData::GetRTStubEntriesOffset(compCfg_->Is32Bit()) + + static_cast(JSThread::GlueData::GetRTStubEntriesOffset(compCfg_->Is32Bit())) + (RTSTUB_ID(OptimizedCallRuntime)) * slotSize_, 0); } else { abort(); @@ -539,7 +539,7 @@ void LLVMIRBuilder::VisitRuntimeCall(GateRef gate, const std::vector &i // 16 : params limit LLVMValueRef params[16]; params[0] = glue; - int index = circuit_->GetBitField(inList[1]); + int index = static_cast(circuit_->GetBitField(inList[1])); params[1] = LLVMConstInt(LLVMInt64Type(), index, 0); params[2] = LLVMConstInt(LLVMInt64Type(), inList.size() - paraStartIndex, 0); // 2 : 2 means third parameter for (size_t paraIdx = paraStartIndex; paraIdx < inList.size(); ++paraIdx) { @@ -643,11 +643,11 @@ void LLVMIRBuilder::VisitCall(GateRef gate, const std::vector &inList, LLVMTypeRef glueType = LLVMTypeOf(glue); // runtime case if (op == OpCode::CALL) { - rtoffset = LLVMConstInt(glueType, - JSThread::GlueData::GetCOStubEntriesOffset(compCfg_->Is32Bit()) + index * slotSize_, 0); + rtoffset = LLVMConstInt(glueType, JSThread::GlueData::GetCOStubEntriesOffset(compCfg_->Is32Bit()) + + index * static_cast(slotSize_), 0); } else { - rtoffset = LLVMConstInt(glueType, - JSThread::GlueData::GetRTStubEntriesOffset(compCfg_->Is32Bit()) + index * slotSize_, 0); + rtoffset = LLVMConstInt(glueType, JSThread::GlueData::GetRTStubEntriesOffset(compCfg_->Is32Bit()) + + index * static_cast(slotSize_), 0); } LLVMValueRef rtbaseoffset = LLVMBuildAdd(builder_, glue, rtoffset, ""); LLVMValueRef rtbaseAddr = LLVMBuildIntToPtr(builder_, rtbaseoffset, LLVMPointerType(glueType, 0), ""); @@ -671,7 +671,7 @@ void LLVMIRBuilder::VisitCall(GateRef gate, const std::vector &inList, } } // then push the actual parameter for js function call - for (size_t paraIdx = paraStartIndex + 1; paraIdx < inList.size(); ++paraIdx) { + for (size_t paraIdx = static_cast(paraStartIndex + 1); paraIdx < inList.size(); ++paraIdx) { GateRef gateTmp = inList[paraIdx]; params[dstParaIndex++] = gateToLLVMMaps_[gateTmp]; } @@ -700,7 +700,7 @@ void LLVMIRBuilder::VisitCall(GateRef gate, const std::vector &inList, void LLVMIRBuilder::VisitBytecodeCall(GateRef gate, const std::vector &inList) { - int paraStartIndex = 3; + size_t paraStartIndex = 3; LLVMValueRef opcodeOffset = gateToLLVMMaps_[inList[1]]; ASSERT(llvmModule_ != nullptr); LLVMValueRef callee; @@ -767,7 +767,7 @@ void LLVMIRBuilder::VisitPhi(GateRef gate, const std::vector &srcGates) int bbIdx = instIdMapBbId_[gateId]; COMPILER_LOG(DEBUG) << "srcGate: " << srcGates[i] << " dominated gateId:" << gateId << "dominated bbIdx: " << bbIdx; - int cnt = bbIdMapBb_.count(bbIdx); + int cnt = static_cast(bbIdMapBb_.count(bbIdx)); // if cnt = 0 means bb with current bbIdx hasn't been created if (cnt > 0) { BasicBlock *bb = bbIdMapBb_[bbIdx].get(); @@ -988,7 +988,7 @@ void LLVMIRBuilder::HandleParameter(GateRef gate) void LLVMIRBuilder::VisitParameter(GateRef gate) { - int argth = circuit_->LoadGatePtrConst(gate)->GetBitField(); + int argth = static_cast(circuit_->LoadGatePtrConst(gate)->GetBitField()); COMPILER_LOG(DEBUG) << " Parameter value" << argth; if (callConv_ == CallSignature::CallConv::WebKitJSCallConv) { if (compCfg_->Is32Bit() && argth > 0) { @@ -1078,19 +1078,19 @@ void LLVMIRBuilder::HandleSwitch(GateRef gate) void LLVMIRBuilder::VisitSwitch(GateRef gate, GateRef input, const std::vector &outList) { LLVMValueRef cond = gateToLLVMMaps_[input]; - unsigned caseNum = outList.size(); + int caseNum = static_cast(outList.size()); BasicBlock *curOutBB = nullptr; LLVMBasicBlockRef llvmDefaultOutBB = nullptr; - for (int i = 0; i < static_cast(caseNum); i++) { + for (int i = 0; i < caseNum; i++) { curOutBB = EnsureBasicBlock(instIdMapBbId_[circuit_->GetId(outList[i])]); EnsureBasicBlock(curOutBB); if (circuit_->GetOpCode(outList[i]) == OpCode::DEFAULT_CASE) { llvmDefaultOutBB = curOutBB->GetImpl()->llvm_bb_; } } - LLVMValueRef result = LLVMBuildSwitch(builder_, cond, llvmDefaultOutBB, caseNum - 1); + LLVMValueRef result = LLVMBuildSwitch(builder_, cond, llvmDefaultOutBB, static_cast(caseNum - 1)); LLVMBasicBlockRef llvmCurOutBB = nullptr; - for (int i = 0; i < static_cast(caseNum); i++) { + for (int i = 0; i < caseNum; i++) { if (circuit_->GetOpCode(outList[i]) == OpCode::DEFAULT_CASE) { continue; } @@ -1903,19 +1903,23 @@ LLVMTypeRef LLVMModule::GetFuncType(const CallSignature *stubDescriptor) auto paramsType = stubDescriptor->GetParametersType(); ASSERT(paramCount > 0); // first argument is glue - LLVMTypeRef glueType = ConvertLLVMTypeFromVariableType(paramsType[0]); - paramTys.push_back(glueType); - if (cfg_.Is32Bit() && stubDescriptor->GetTargetKind() != CallSignature::TargetKind::RUNTIME_STUB) { - if (stubDescriptor->GetCallConv() == CallSignature::CallConv::WebKitJSCallConv) { - for (int i = 0; i < CompilationConfig::FAKE_REGISTER_PARAMTERS_ARM32; i++) { - paramTys.push_back(glueType); // fake paramter's type is same with glue type + if (paramsType != nullptr) { + LLVMTypeRef glueType = ConvertLLVMTypeFromVariableType(paramsType[0]); + paramTys.push_back(glueType); + if (cfg_.Is32Bit() && stubDescriptor->GetTargetKind() != CallSignature::TargetKind::RUNTIME_STUB) { + if (stubDescriptor->GetCallConv() == CallSignature::CallConv::WebKitJSCallConv) { + for (int i = 0; i < CompilationConfig::FAKE_REGISTER_PARAMTERS_ARM32; i++) { + paramTys.push_back(glueType); // fake paramter's type is same with glue type + } + extraParameterCnt += CompilationConfig::FAKE_REGISTER_PARAMTERS_ARM32; } - extraParameterCnt += CompilationConfig::FAKE_REGISTER_PARAMTERS_ARM32; } - } - for (int i = 1; i < paramCount; i++) { - paramTys.push_back(ConvertLLVMTypeFromVariableType(paramsType[i])); + for (int i = 1; i < paramCount; i++) { + paramTys.push_back(ConvertLLVMTypeFromVariableType(paramsType[i])); + } + } else { + UNREACHABLE(); } auto functype = LLVMFunctionType(returnType, paramTys.data(), paramCount + extraParameterCnt, stubDescriptor->GetVariableArgs()); diff --git a/ecmascript/compiler/stub-inl.h b/ecmascript/compiler/stub-inl.h index 27273d584e..8658d79b3b 100644 --- a/ecmascript/compiler/stub-inl.h +++ b/ecmascript/compiler/stub-inl.h @@ -1591,7 +1591,7 @@ inline void Stub::SetNumberOfPropsToHClass(GateRef glue, GateRef hClass, GateRef { GateRef bitfield1 = Load(VariableType::INT32(), hClass, IntPtr(JSHClass::BIT_FIELD1_OFFSET)); GateRef oldWithMask = Int32And(bitfield1, - Int32(~static_cast(JSHClass::NumberOfPropsBits::Mask()))); + Int32(~static_cast(JSHClass::NumberOfPropsBits::Mask()))); GateRef newValue = UInt32LSR(value, Int32(JSHClass::NumberOfPropsBits::START_BIT)); Store(VariableType::INT32(), glue, hClass, IntPtr(JSHClass::BIT_FIELD1_OFFSET), Int32Or(oldWithMask, newValue)); diff --git a/ecmascript/compiler/stub.cpp b/ecmascript/compiler/stub.cpp index 64525a19c9..a2117a48e1 100644 --- a/ecmascript/compiler/stub.cpp +++ b/ecmascript/compiler/stub.cpp @@ -285,6 +285,7 @@ Stub::Environment::Environment(size_t arguments, Circuit *circuit) currentLabel_->Seal(); auto depend_entry = Circuit::GetCircuitRoot(OpCode(OpCode::DEPEND_ENTRY)); currentLabel_->SetDepend(depend_entry); + compCfg_ = nullptr; } Stub::Environment::~Environment() diff --git a/ecmascript/containers/containers_treemap.cpp b/ecmascript/containers/containers_treemap.cpp index b95f71c08c..9c1056977a 100644 --- a/ecmascript/containers/containers_treemap.cpp +++ b/ecmascript/containers/containers_treemap.cpp @@ -348,7 +348,7 @@ JSTaggedValue ContainersTreeMap::ForEach(EcmaRuntimeCallInfo *argv) RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, ret); // check entries should be update, size will be update in tmap set or remove. - if (tmap->GetSize() != length) { + if (tmap->GetSize() != static_cast(length)) { iteratedMap.Update(tmap->GetTreeMap()); entries.Update(TaggedTreeMap::GetArrayFromMap(thread, iteratedMap).GetTaggedValue()); elements = iteratedMap->NumberOfElements(); diff --git a/ecmascript/containers/containers_treeset.cpp b/ecmascript/containers/containers_treeset.cpp index 85d864a1ee..f4756454ce 100644 --- a/ecmascript/containers/containers_treeset.cpp +++ b/ecmascript/containers/containers_treeset.cpp @@ -301,7 +301,7 @@ JSTaggedValue ContainersTreeSet::ForEach(EcmaRuntimeCallInfo *argv) RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, ret); // check entries should be update, size will be update by set add and remove. - if (tset->GetSize() != length) { + if (tset->GetSize() != static_cast(length)) { iteratedSet.Update(tset->GetTreeSet()); entries.Update(TaggedTreeSet::GetArrayFromSet(thread, iteratedSet).GetTaggedValue()); elements = iteratedSet->NumberOfElements(); diff --git a/ecmascript/dfx/cpu_profiler/cpu_profiler.cpp b/ecmascript/dfx/cpu_profiler/cpu_profiler.cpp index f937c9bf32..111c192102 100644 --- a/ecmascript/dfx/cpu_profiler/cpu_profiler.cpp +++ b/ecmascript/dfx/cpu_profiler/cpu_profiler.cpp @@ -166,10 +166,14 @@ void CpuProfiler::GetCurrentProcessInfo(struct CurrentProcessInfo ¤tProces { currentProcessInfo.nowTimeStamp = ProfileProcessor::GetMicrosecondsTimeStamp() % TIME_CHANGE; currentProcessInfo.pid = getpid(); - tid_ = currentProcessInfo.tid = syscall(SYS_gettid); + if (syscall(SYS_gettid) == -1) { + LOG_ECMA(FATAL) << "syscall failed"; + UNREACHABLE(); + } + tid_ = currentProcessInfo.tid = static_cast(syscall(SYS_gettid)); struct timespec time = {0, 0}; clock_gettime(CLOCK_MONOTONIC, &time); - currentProcessInfo.tts = time.tv_nsec / 1000; // 1000:Nanoseconds to milliseconds. + currentProcessInfo.tts = static_cast(time.tv_nsec) / 1000; // 1000:Nanoseconds to milliseconds. } void CpuProfiler::GetFrameStack(JSThread *thread) @@ -218,7 +222,7 @@ void CpuProfiler::ParseMethodInfo(JSMethod *method, InterpretedFrameHandler fram auto iter = scriptIdMap_.find(codeEntry.url); if (iter == scriptIdMap_.end()) { scriptIdMap_.insert(std::make_pair(codeEntry.url, scriptIdMap_.size() + 1)); - codeEntry.scriptId = scriptIdMap_.size(); + codeEntry.scriptId = static_cast(scriptIdMap_.size()); } else { codeEntry.scriptId = iter->second; } diff --git a/ecmascript/dfx/cpu_profiler/profile_generator.cpp b/ecmascript/dfx/cpu_profiler/profile_generator.cpp index 1ec83abf86..0fc3ba0a87 100644 --- a/ecmascript/dfx/cpu_profiler/profile_generator.cpp +++ b/ecmascript/dfx/cpu_profiler/profile_generator.cpp @@ -49,7 +49,7 @@ void ProfileGenerator::AddSample(CVector sample, uint64_t sampleTime methodNode.parentId = methodkey.parentId = PreviousId; auto result = methodMap_.find(methodkey); if (result == methodMap_.end()) { - methodNode.id = methodMap_.size() + 1; + methodNode.id = static_cast(methodMap_.size() + 1); methodMap_.insert(std::make_pair(methodkey, methodNode.id)); methodNode.codeEntry = GetGcInfo(); stackTopLines_.push_back(0); @@ -69,7 +69,7 @@ void ProfileGenerator::AddSample(CVector sample, uint64_t sampleTime } auto result = methodMap_.find(methodkey); if (result == methodMap_.end()) { - int id = methodMap_.size() + 1; + int id = static_cast(methodMap_.size() + 1); methodMap_.insert(std::make_pair(methodkey, id)); PreviousId = methodNode.id = id; methodNode.codeEntry = GetMethodInfo(methodkey.method); @@ -161,12 +161,12 @@ void ProfileGenerator::WriteMethodsAndSampleInfo(bool timeEnd) sampleData_ += "\"cat\":\"disabled-by-default-ark.cpu_profiler\",\"id\":" "\"0x2\",\"name\":\"ProfileChunk\",\"ph\":\"P\",\"pid\":"; pid_t pid = getpid(); - pthread_t tid = syscall(SYS_gettid); + int64_t tid = syscall(SYS_gettid); uint64_t ts = ProfileProcessor::GetMicrosecondsTimeStamp(); ts = ts % TIME_CHANGE; struct timespec time = {0, 0}; clock_gettime(CLOCK_MONOTONIC, &time); - uint64_t tts = time.tv_nsec / 1000; // 1000:Nanoseconds to milliseconds. + uint64_t tts = static_cast(time.tv_nsec) / 1000; // 1000:Nanoseconds to milliseconds. sampleData_ += std::to_string(pid) + ",\"tid\":" + std::to_string(tid) + ",\"ts\":" + std::to_string(ts) + ",\"tts\":" + diff --git a/ecmascript/dfx/hprof/heap_profiler.cpp b/ecmascript/dfx/hprof/heap_profiler.cpp index 46f46a43c2..3619e85fd8 100644 --- a/ecmascript/dfx/hprof/heap_profiler.cpp +++ b/ecmascript/dfx/hprof/heap_profiler.cpp @@ -131,6 +131,10 @@ CString HeapProfiler::GetTimeStamp() struct tm tm { }; struct tm *timeData = localtime_r(&timeSource, &tm); + if (timeData == nullptr) { + LOG_ECMA(FATAL) << "localtime_r failed"; + UNREACHABLE(); + } CString stamp; const int TIME_START = 1900; stamp.append(ToCString(timeData->tm_year + TIME_START)) diff --git a/ecmascript/dfx/hprof/heap_snapshot.cpp b/ecmascript/dfx/hprof/heap_snapshot.cpp index 0d9409c3dd..ca9271a988 100644 --- a/ecmascript/dfx/hprof/heap_snapshot.cpp +++ b/ecmascript/dfx/hprof/heap_snapshot.cpp @@ -133,7 +133,7 @@ void HeapSnapShot::MoveNode(uintptr_t address, uintptr_t forward_address) int sequenceId = -1; Node *node = entryMap_.FindAndEraseNode(address); if (node != nullptr) { - sequenceId = node->GetId(); + sequenceId = static_cast(node->GetId()); EraseNodeUnique(node); } GenerateNode(JSTaggedValue(forward_address), sequenceId); @@ -705,18 +705,18 @@ CString EntryVisitor::ConvertKey(JSTaggedValue key) keyString = EcmaString::Cast(symbol->GetDescription().GetTaggedObject()); } // convert, expensive but safe - int length = 0; + uint32_t length = 0; if (keyString->IsUtf8()) { length = keyString->GetUtf8Length(); std::vector buffer(length); - [[maybe_unused]] int size = keyString->CopyDataUtf8(buffer.data(), length); + [[maybe_unused]] size_t size = keyString->CopyDataUtf8(buffer.data(), length); ASSERT(size == length); CString keyCopy(reinterpret_cast(buffer.data())); return keyCopy; } else { // NOLINT(readability-else-after-return) length = keyString->GetLength(); std::vector buffer(length); - [[maybe_unused]] int size = keyString->CopyDataUtf16(buffer.data(), length); + [[maybe_unused]] size_t size = keyString->CopyDataUtf16(buffer.data(), length); ASSERT(size == length); CString keyCopy(reinterpret_cast(buffer.data())); return keyCopy; diff --git a/ecmascript/dfx/hprof/heap_snapshot.h b/ecmascript/dfx/hprof/heap_snapshot.h index 9c9c6aa5e8..8faf8352a6 100644 --- a/ecmascript/dfx/hprof/heap_snapshot.h +++ b/ecmascript/dfx/hprof/heap_snapshot.h @@ -272,11 +272,11 @@ public: } void AccumulateNodeSize(size_t size) { - totalNodesSize_ += size; + totalNodesSize_ += static_cast(size); } void DecreaseNodeSize(size_t size) { - totalNodesSize_ -= size; + totalNodesSize_ -= static_cast(size); } CString *GenerateNodeName(TaggedObject *entry); NodeType GenerateNodeType(TaggedObject *entry); diff --git a/ecmascript/dfx/hprof/string_hashmap.cpp b/ecmascript/dfx/hprof/string_hashmap.cpp index 6199aadf60..01d871c419 100644 --- a/ecmascript/dfx/hprof/string_hashmap.cpp +++ b/ecmascript/dfx/hprof/string_hashmap.cpp @@ -49,7 +49,7 @@ CString *StringHashMap::GetStringByKey(StringKey key) const CString *StringHashMap::FormatString(CString *string) const { // remove "\"" | "\r\n" | "\\" | "\t" | "\f" - int length = string->length(); + int length = static_cast(string->length()); char *charSeq = const_cast(string->c_str()); for (int i = 0; i < length; i++) { if (charSeq[i] == '\"') { // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) diff --git a/ecmascript/dump.cpp b/ecmascript/dump.cpp index 9ede88323f..732b03979e 100644 --- a/ecmascript/dump.cpp +++ b/ecmascript/dump.cpp @@ -991,7 +991,7 @@ void JSObject::Dump(std::ostream &os) const } LayoutInfo *layoutInfo = LayoutInfo::Cast(attrs.GetTaggedObject()); - int propNumber = jshclass->NumberOfProps(); + int propNumber = static_cast(jshclass->NumberOfProps()); os << " \n"; for (int i = 0; i < propNumber; i++) { JSTaggedValue key = layoutInfo->GetKey(i); @@ -1004,7 +1004,7 @@ void JSObject::Dump(std::ostream &os) const if (attr.IsInlinedProps()) { val = GetPropertyInlinedProps(i); } else { - val = properties->Get(i - jshclass->GetInlinedProperties()); + val = properties->Get(i - static_cast(jshclass->GetInlinedProperties())); } val.DumpTaggedValue(os); os << ") "; @@ -3143,7 +3143,7 @@ void JSObject::DumpForSnapshot(std::vector> &v } LayoutInfo *layoutInfo = LayoutInfo::Cast(attrs.GetTaggedObject()); - int propNumber = jshclass->NumberOfProps(); + int propNumber = static_cast(jshclass->NumberOfProps()); for (int i = 0; i < propNumber; i++) { JSTaggedValue key = layoutInfo->GetKey(i); PropertyAttributes attr = layoutInfo->GetAttr(i); @@ -3152,7 +3152,7 @@ void JSObject::DumpForSnapshot(std::vector> &v if (attr.IsInlinedProps()) { val = GetPropertyInlinedProps(i); } else { - val = properties->Get(i - jshclass->GetInlinedProperties()); + val = properties->Get(i - static_cast(jshclass->GetInlinedProperties())); } CString str; diff --git a/ecmascript/ecma_string-inl.h b/ecmascript/ecma_string-inl.h index b15acddf91..bf8a6ae445 100644 --- a/ecmascript/ecma_string-inl.h +++ b/ecmascript/ecma_string-inl.h @@ -100,7 +100,7 @@ inline EcmaString *EcmaString::CreateFromUtf16(const uint16_t *utf16Data, uint32 template inline uint16_t EcmaString::At(int32_t index) const { - int32_t length = GetLength(); + int32_t length = static_cast(GetLength()); if (verify) { if ((index < 0) || (index >= length)) { return 0; diff --git a/ecmascript/ecma_string.cpp b/ecmascript/ecma_string.cpp index 4a5952326e..110e582404 100644 --- a/ecmascript/ecma_string.cpp +++ b/ecmascript/ecma_string.cpp @@ -127,8 +127,8 @@ int32_t EcmaString::Compare(const EcmaString *rhs) const if (lhs == rhs) { return 0; } - int32_t lhsCount = lhs->GetLength(); - int32_t rhsCount = rhs->GetLength(); + int32_t lhsCount = static_cast(lhs->GetLength()); + int32_t rhsCount = static_cast(rhs->GetLength()); int32_t countDiff = lhsCount - rhsCount; int32_t minCount = (countDiff < 0) ? lhsCount : rhsCount; if (!lhs->IsUtf16() && !rhs->IsUtf16()) { @@ -199,8 +199,8 @@ int32_t EcmaString::IndexOf(const EcmaString *rhs, int32_t pos) const return -1; } const EcmaString *lhs = this; - int32_t lhsCount = lhs->GetLength(); - int32_t rhsCount = rhs->GetLength(); + int32_t lhsCount = static_cast(lhs->GetLength()); + int32_t rhsCount = static_cast(rhs->GetLength()); if (rhsCount == 0) { return pos; } @@ -433,7 +433,7 @@ static int32_t ComputeHashForUtf8(const uint8_t *utf8Data) uint32_t EcmaString::ComputeHashcode(uint32_t hashSeed) const { - uint32_t hash; + int32_t hash; if (compressedStringsEnabled) { if (!IsUtf16()) { hash = ComputeHashForData(GetDataUtf8(), GetLength(), hashSeed); @@ -444,13 +444,13 @@ uint32_t EcmaString::ComputeHashcode(uint32_t hashSeed) const ASSERT(static_cast(GetLength())<(std::numeric_limits::max()>>1U)); hash = ComputeHashForData(GetDataUtf16(), GetLength(), hashSeed); } - return hash; + return static_cast(hash); } /* static */ uint32_t EcmaString::ComputeHashcodeUtf8(const uint8_t *utf8Data, size_t utf8Len, bool canBeCompress) { - uint32_t hash; + int32_t hash; if (canBeCompress) { hash = ComputeHashForUtf8(utf8Data); } else { @@ -461,7 +461,7 @@ uint32_t EcmaString::ComputeHashcodeUtf8(const uint8_t *utf8Data, size_t utf8Len ASSERT(len == utf16Len); hash = ComputeHashForData(tmpBuffer.data(), utf16Len, 0); } - return hash; + return static_cast(hash); } /* static */ diff --git a/ecmascript/ecma_vm.cpp b/ecmascript/ecma_vm.cpp index a8524ec4be..7bf639f730 100644 --- a/ecmascript/ecma_vm.cpp +++ b/ecmascript/ecma_vm.cpp @@ -107,8 +107,12 @@ EcmaVM *EcmaVM::Create(Runtime *runtime) { EcmaVM *vm = runtime->GetInternalAllocator()->New(); auto jsThread = ecmascript::JSThread::Create(runtime, vm); - vm->thread_ = jsThread; - return vm; + if (vm == nullptr) { + return nullptr; + } else { + vm->thread_ = jsThread; + return vm; + } } // NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init) diff --git a/ecmascript/global_dictionary-inl.h b/ecmascript/global_dictionary-inl.h index aaac2b4638..6404b59e75 100644 --- a/ecmascript/global_dictionary-inl.h +++ b/ecmascript/global_dictionary-inl.h @@ -159,7 +159,7 @@ void GlobalDictionary::InvalidatePropertyBox(JSThread *thread, const JSHandleGetValue().IsHole()); - int index = originAttr.GetDictionaryOrder(); + int index = static_cast(originAttr.GetDictionaryOrder()); JSHandle oldValue(thread, box->GetValue()); GlobalDictionary::InvalidateAndReplaceEntry(thread, dictHandle, index, oldValue); dictHandle->SetAttributes(thread, entry, newAttr); diff --git a/ecmascript/global_env.h b/ecmascript/global_env.h index e21f4fe0a9..3e325b70e8 100644 --- a/ecmascript/global_env.h +++ b/ecmascript/global_env.h @@ -183,7 +183,7 @@ public: template \ inline void Set##name(const JSThread *thread, JSHandle value, BarrierMode mode = WRITE_BARRIER) \ { \ - int offset = HEADER_SIZE + index * JSTaggedValue::TaggedTypeSize(); \ + uint32_t offset = HEADER_SIZE + index * JSTaggedValue::TaggedTypeSize(); \ if (mode == WRITE_BARRIER && value.GetTaggedValue().IsHeapObject()) { \ Barriers::SetDynObject(thread, this, offset, value.GetTaggedValue().GetRawData()); \ } else { \ @@ -192,7 +192,7 @@ public: } \ inline void Set##name(const JSThread *thread, type value, BarrierMode mode = WRITE_BARRIER) \ { \ - int offset = HEADER_SIZE + index * JSTaggedValue::TaggedTypeSize(); \ + uint32_t offset = HEADER_SIZE + index * JSTaggedValue::TaggedTypeSize(); \ if (mode == WRITE_BARRIER && value.IsHeapObject()) { \ Barriers::SetDynObject(thread, this, offset, value.GetRawData()); \ } else { \ diff --git a/ecmascript/global_env_constants-inl.h b/ecmascript/global_env_constants-inl.h index acf7e43238..af0413ef5f 100644 --- a/ecmascript/global_env_constants-inl.h +++ b/ecmascript/global_env_constants-inl.h @@ -47,7 +47,7 @@ inline void GlobalEnvConstants::SetConstant(ConstantIndex index, JSHandle val inline uintptr_t GlobalEnvConstants::GetGlobalConstantAddr(ConstantIndex index) const { - return ToUintPtr(this) + sizeof(JSTaggedValue) * static_cast(index); + return ToUintPtr(this) + sizeof(JSTaggedValue) * static_cast(index); } // clang-format off diff --git a/ecmascript/ic/ic_runtime_stub-inl.h b/ecmascript/ic/ic_runtime_stub-inl.h index dcc34c4377..72b048628c 100644 --- a/ecmascript/ic/ic_runtime_stub-inl.h +++ b/ecmascript/ic/ic_runtime_stub-inl.h @@ -240,12 +240,12 @@ void ICRuntimeStub::StoreWithTransition(JSThread *thread, JSObject *receiver, JS TransitionHandler *transitionHandler = TransitionHandler::Cast(handler.GetTaggedObject()); JSHClass *newHClass = JSHClass::Cast(transitionHandler->GetTransitionHClass().GetTaggedObject()); receiver->SetClass(newHClass); - uint32_t handlerInfo = transitionHandler->GetHandlerInfo().GetInt(); + uint32_t handlerInfo = static_cast(transitionHandler->GetHandlerInfo().GetInt()); ASSERT(HandlerBase::IsField(handlerInfo)); if (!HandlerBase::IsInlinedProps(handlerInfo)) { TaggedArray *array = TaggedArray::Cast(receiver->GetProperties().GetHeapObject()); - int capacity = array->GetLength(); + int capacity = static_cast(array->GetLength()); int index = HandlerBase::GetOffset(handlerInfo); if (index >= capacity) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); @@ -275,7 +275,7 @@ ARK_INLINE void ICRuntimeStub::StoreField(JSThread *thread, JSObject *receiver, INTERPRETER_TRACE(thread, StoreField); int index = HandlerBase::GetOffset(handler); if (HandlerBase::IsInlinedProps(handler)) { - SET_VALUE_WITH_BARRIER(thread, receiver, index * JSTaggedValue::TaggedTypeSize(), value); + SET_VALUE_WITH_BARRIER(thread, receiver, static_cast(index) * JSTaggedValue::TaggedTypeSize(), value); return; } TaggedArray *array = TaggedArray::Cast(receiver->GetProperties().GetHeapObject()); @@ -287,7 +287,7 @@ ARK_INLINE JSTaggedValue ICRuntimeStub::LoadFromField(JSObject *receiver, uint32 { int index = HandlerBase::GetOffset(handlerInfo); if (HandlerBase::IsInlinedProps(handlerInfo)) { - return JSTaggedValue(GET_VALUE(receiver, index * JSTaggedValue::TaggedTypeSize())); + return JSTaggedValue(GET_VALUE(receiver, static_cast(index) * JSTaggedValue::TaggedTypeSize())); } return TaggedArray::Cast(receiver->GetProperties().GetHeapObject())->Get(index); } @@ -363,7 +363,7 @@ ARK_INLINE JSTaggedValue ICRuntimeStub::LoadElement(JSObject *receiver, JSTagged if (index < 0) { return JSTaggedValue::Hole(); } - uint32_t elementIndex = index; + uint32_t elementIndex = static_cast(index); TaggedArray *elements = TaggedArray::Cast(receiver->GetElements().GetHeapObject()); if (elements->GetLength() <= elementIndex) { return JSTaggedValue::Hole(); @@ -382,7 +382,7 @@ JSTaggedValue ICRuntimeStub::StoreElement(JSThread *thread, JSObject *receiver, if (index < 0) { return JSTaggedValue::Hole(); } - uint32_t elementIndex = index; + uint32_t elementIndex = static_cast(index); if (handler.IsInt()) { auto handlerInfo = static_cast(handler.GetInt()); if (HandlerBase::IsJSArray(handlerInfo)) { diff --git a/ecmascript/linked_hash_table-inl.h b/ecmascript/linked_hash_table-inl.h index d940539495..5710d1bad2 100644 --- a/ecmascript/linked_hash_table-inl.h +++ b/ecmascript/linked_hash_table-inl.h @@ -126,55 +126,55 @@ uint32_t LinkedHashTable::BucketToIndex(uint32_t bucket) template uint32_t LinkedHashTable::EntryToIndex(uint32_t entry) const { - return ELEMENTS_START_INDEX + Capacity() + entry * (HashObject::ENTRY_SIZE + 1); + return ELEMENTS_START_INDEX + Capacity() + static_cast(entry) * (HashObject::ENTRY_SIZE + 1); } template void LinkedHashTable::SetKey(const JSThread *thread, int entry, JSTaggedValue key) { - int index = EntryToIndex(entry); + int index = static_cast(EntryToIndex(entry)); SetElement(thread, index, key); } template JSTaggedValue LinkedHashTable::GetKey(int entry) const { - int index = EntryToIndex(entry); + int index = static_cast(EntryToIndex(entry)); return GetElement(index); } template JSTaggedValue LinkedHashTable::GetValue(int entry) const { - int index = EntryToIndex(entry) + HashObject::ENTRY_VALUE_INDEX; + int index = static_cast(EntryToIndex(entry)) + HashObject::ENTRY_VALUE_INDEX; return GetElement(index); } template void LinkedHashTable::SetValue(const JSThread *thread, int entry, JSTaggedValue value) { - int index = EntryToIndex(entry) + HashObject::ENTRY_VALUE_INDEX; + int index = static_cast(EntryToIndex(entry)) + HashObject::ENTRY_VALUE_INDEX; SetElement(thread, index, value); } template JSTaggedValue LinkedHashTable::GetNextEntry(int entry) const { - int index = EntryToIndex(entry) + HashObject::ENTRY_SIZE; + int index = static_cast(EntryToIndex(entry)) + HashObject::ENTRY_SIZE; return GetElement(index); } template void LinkedHashTable::SetNextEntry(const JSThread *thread, int entry, JSTaggedValue nextEntry) { - int index = EntryToIndex(entry) + HashObject::ENTRY_SIZE; + int index = static_cast(EntryToIndex(entry)) + HashObject::ENTRY_SIZE; SetElement(thread, index, nextEntry); } template void LinkedHashTable::InsertNewEntry(const JSThread *thread, int bucket, int entry) { - int bucketIndex = BucketToIndex(bucket); + int bucketIndex = static_cast(BucketToIndex(bucket)); JSTaggedValue previousEntry = GetElement(bucketIndex); SetNextEntry(thread, entry, previousEntry); SetElement(thread, bucketIndex, JSTaggedValue(entry)); @@ -186,7 +186,7 @@ int LinkedHashTable::FindElement(JSTaggedValue key) const if (!IsKey(key)) { return -1; } - int hash = LinkedHash::Hash(key); + int hash = static_cast(LinkedHash::Hash(key)); int bucket = HashToBucket(hash); for (JSTaggedValue entry = GetElement(BucketToIndex(bucket)); !entry.IsHole(); entry = GetNextEntry(entry.GetInt())) { @@ -237,7 +237,7 @@ template void LinkedHashTable::RemoveEntry(const JSThread *thread, int entry) { ASSERT_PRINT(entry >= 0 && entry < Capacity(), "entry must be a non-negative integer less than capacity"); - int index = EntryToIndex(entry); + int index = static_cast(EntryToIndex(entry)); for (int i = 0; i < HashObject::ENTRY_SIZE; i++) { SetElement(thread, index + i, JSTaggedValue::Hole()); } diff --git a/ecmascript/mem/machine_code.cpp b/ecmascript/mem/machine_code.cpp index c30c1a650b..f2a76b87e3 100644 --- a/ecmascript/mem/machine_code.cpp +++ b/ecmascript/mem/machine_code.cpp @@ -21,6 +21,10 @@ namespace panda::ecmascript { void AotCodeInfo::SerializeForStub(const std::string &filename) { + if (!VerifyFilePath(filename.c_str())) { + LOG_ECMA(FATAL) << "file path illegal !"; + UNREACHABLE(); + } std::ofstream modulefile(filename.c_str(), std::ofstream::binary); SetStubNum(stubEntries_.size()); /* write stub entries offset */ @@ -43,6 +47,10 @@ bool AotCodeInfo::DeserializeForStub(JSThread *thread, const std::string &filena // by calling NewMachineCodeObject. // then MachineCode will support movable, code is saved to MachineCode and stackmap is saved // to different heap which will be freed when stackmap is parsed by EcmaVM is started. + if (!VerifyFilePath(filename.c_str())) { + LOG_ECMA(FATAL) << "file path illegal !"; + UNREACHABLE(); + } std::ifstream modulefile(filename.c_str(), std::ofstream::binary); if (!modulefile.good()) { modulefile.close(); @@ -79,6 +87,10 @@ bool AotCodeInfo::DeserializeForStub(JSThread *thread, const std::string &filena void AotCodeInfo::Serialize(const std::string &filename) { + if (!VerifyFilePath(filename.c_str())) { + LOG_ECMA(FATAL) << "file path illegal !"; + UNREACHABLE(); + } std::ofstream moduleFile(filename.c_str(), std::ofstream::binary); uint32_t funcNum = aotFuncEntryOffsets_.size(); moduleFile.write(reinterpret_cast(&funcNum), sizeof(funcNum)); @@ -102,6 +114,10 @@ void AotCodeInfo::Serialize(const std::string &filename) bool AotCodeInfo::Deserialize(EcmaVM *vm, const std::string &filename) { + if (!VerifyFilePath(filename.c_str())) { + LOG_ECMA(FATAL) << "file path illegal !"; + UNREACHABLE(); + } std::ifstream moduleFile(filename.c_str(), std::ofstream::binary); if (!moduleFile.good()) { moduleFile.close(); @@ -149,4 +165,22 @@ void AotCodeInfo::Iterate(const RootVisitor &v) { v(Root::ROOT_VM, ObjectSlot(reinterpret_cast(&code_))); } + +bool AotCodeInfo::VerifyFilePath(const CString &filePath) const +{ +#ifndef PANDA_TARGET_WINDOWS + if (filePath.size() > PATH_MAX) { + return false; + } + + CVector resolvedPath(PATH_MAX); + auto result = realpath(filePath.c_str(), resolvedPath.data()); + if (result == nullptr) { + return false; + } + return true; +#else + return false; +#endif +} } // panda::ecmascript \ No newline at end of file diff --git a/ecmascript/mem/machine_code.h b/ecmascript/mem/machine_code.h index bb8920cc30..c520084b05 100644 --- a/ecmascript/mem/machine_code.h +++ b/ecmascript/mem/machine_code.h @@ -85,6 +85,7 @@ public: void Serialize(const std::string &filename); bool DeserializeForStub(JSThread *thread, const std::string &filename); bool Deserialize(EcmaVM *vm, const std::string &filename); + bool VerifyFilePath(const CString &filePath) const; struct StubDes { uint64_t codeAddr_; @@ -215,7 +216,7 @@ public: { StubDes des; des.kind_ = kind; - des.indexInKind_ = indexInKind; + des.indexInKind_ = static_cast(indexInKind); des.codeAddr_ = offset; stubEntries_.emplace_back(des); }