Modifying Code Alarms

Signed-off-by: hwx1163501 <hanjing35@huawei.com>
issue:https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/I7S5SX
This commit is contained in:
hwx1163501 2023-08-10 17:35:58 +08:00
parent 905f840797
commit b59da810e0
13 changed files with 46 additions and 42 deletions

View File

@ -65,7 +65,7 @@ uint32_t DependChains::FoundIndexCheckedForLength(RangeGuard* rangeGuard, GateRe
{
for (Node* node = head_; node != nullptr; node = node->next) {
uint32_t length = rangeGuard->CheckIndexCheckLengthInput(node->gate, input);
if(length > 0) { // found !!!
if (length > 0) { // found !!!
return length;
}
}
@ -76,7 +76,7 @@ uint32_t DependChains::FoundIndexCheckedForIndex(RangeGuard* rangeGuard, GateRef
{
for (Node* node = head_; node != nullptr; node = node->next) {
uint32_t length = rangeGuard->CheckIndexCheckIndexInput(node->gate, input);
if(length > 0) { // found !!!
if (length > 0) { // found !!!
return length;
}
}

View File

@ -252,7 +252,7 @@ bool EarlyElimination::MayAccessOneMemory(GateRef lhs, GateRef rhs)
ASSERT(acc_.GetMemoryType(rhs) == MemoryType::ELEMENT_TYPE);
return acc_.GetOpCode(lhs) == OpCode::LOAD_ELEMENT;
case OpCode::STORE_ELEMENT: {
if(lop == OpCode::LOAD_ELEMENT) {
if (lop == OpCode::LOAD_ELEMENT) {
auto lopIsTypedArray = acc_.GetTypedLoadOp(lhs) >= TypedLoadOp::TYPED_ARRAY_FIRST;
auto ropIsTypedArray = acc_.GetTypedStoreOp(rhs) >= TypedStoreOp::TYPED_ARRAY_FIRST;
return lopIsTypedArray == ropIsTypedArray;

View File

@ -172,7 +172,7 @@ GateRef RangeAnalysis::VisitLoadTypedArrayLength(GateRef gate)
}
GateRef RangeAnalysis::VisitRangeGuard(GateRef gate)
{
{
auto left = acc_.GetFirstValue(gate);
auto right = acc_.GetSecondValue(gate);
return UpdateRange(gate, RangeInfo(left, right));

View File

@ -93,7 +93,8 @@ GateRef RangeGuard::TryApplyRangeGuardForLength(DependChains* dependChain, GateR
uint32_t length = dependChain->FoundIndexCheckedForLength(this, input);
if (length) { // when length not equal to 0, then Found the IndexCheck Success
Environment env(gate, circuit_, &builder_);
auto rangeGuardGate = builder_.RangeGuard(input, 1, length); // If the IndexCheck before the ArrayLength used, the ArrayLength must start by 1.
// If the IndexCheck before the ArrayLength used, the ArrayLength must start by 1.
auto rangeGuardGate = builder_.RangeGuard(input, 1, length);
return rangeGuardGate;
}
return Circuit::NullGate();
@ -105,7 +106,8 @@ GateRef RangeGuard::TryApplyRangeGuardForIndex(DependChains* dependChain, GateRe
uint32_t length = dependChain->FoundIndexCheckedForIndex(this, input);
if (length) { // when length not equal to 0, then Found the IndexCheck Success
Environment env(gate, circuit_, &builder_);
auto rangeGuardGate = builder_.RangeGuard(input, 0, length); // If the IndexCheck used in the Array, the index must in the Array range.
// If the IndexCheck used in the Array, the index must in the Array range.
auto rangeGuardGate = builder_.RangeGuard(input, 0, length);
return rangeGuardGate;
}
return Circuit::NullGate();
@ -129,7 +131,8 @@ GateRef RangeGuard::TryApplyRangeGuardGate(GateRef gate)
auto originalInput = acc_.GetValueIn(gate, i);
auto originalInputOpcode = acc_.GetOpCode(originalInput);
auto rangeGuardGate = Circuit::NullGate();
if (originalInputOpcode == OpCode::LOAD_TYPED_ARRAY_LENGTH || originalInputOpcode == OpCode::LOAD_ARRAY_LENGTH) {
if (originalInputOpcode == OpCode::LOAD_TYPED_ARRAY_LENGTH ||
originalInputOpcode == OpCode::LOAD_ARRAY_LENGTH) {
rangeGuardGate = TryApplyRangeGuardForLength(dependChain, gate, originalInput);
} else if(originalInputOpcode != OpCode::CONSTANT && rangeGuardGate == Circuit::NullGate()) {
rangeGuardGate = TryApplyRangeGuardForIndex(dependChain, gate, originalInput);
@ -165,9 +168,9 @@ uint32_t RangeGuard::CheckIndexCheckLengthInput(GateRef lhs, GateRef rhs)
if (lhsOpcode == OpCode::INDEX_CHECK) {
auto indexCheckLengthInput = acc_.GetValueIn(lhs, 0); // length
auto indexCheckLengthInputOpcode = acc_.GetOpCode(indexCheckLengthInput);
if(indexCheckLengthInput == rhs && indexCheckLengthInputOpcode == OpCode::LOAD_TYPED_ARRAY_LENGTH) {
if (indexCheckLengthInput == rhs && indexCheckLengthInputOpcode == OpCode::LOAD_TYPED_ARRAY_LENGTH) {
return RangeInfo::TYPED_ARRAY_ONHEAP_MAX;
} else if(indexCheckLengthInput == rhs && indexCheckLengthInputOpcode == OpCode::LOAD_ARRAY_LENGTH) {
} else if (indexCheckLengthInput == rhs && indexCheckLengthInputOpcode == OpCode::LOAD_ARRAY_LENGTH) {
return INT32_MAX;
}
}
@ -181,9 +184,10 @@ uint32_t RangeGuard::CheckIndexCheckIndexInput(GateRef lhs, GateRef rhs)
auto indexCheckLengthInput = acc_.GetValueIn(lhs, 0); // length
auto indexCheckIndexInput = acc_.GetValueIn(lhs, 1); // index
auto indexCheckLengthInputOpcode = acc_.GetOpCode(indexCheckLengthInput);
if(indexCheckIndexInput == rhs && indexCheckLengthInputOpcode == OpCode::LOAD_TYPED_ARRAY_LENGTH) { // TYPED_ARRAY
// TYPED_ARRAY
if (indexCheckIndexInput == rhs && indexCheckLengthInputOpcode == OpCode::LOAD_TYPED_ARRAY_LENGTH) {
return RangeInfo::TYPED_ARRAY_ONHEAP_MAX;
} else if(indexCheckIndexInput == rhs && indexCheckLengthInputOpcode == OpCode::LOAD_ARRAY_LENGTH) { // ARRAY
} else if (indexCheckIndexInput == rhs && indexCheckLengthInputOpcode == OpCode::LOAD_ARRAY_LENGTH) { // ARRAY
return INT32_MAX;
}
}

View File

@ -182,7 +182,7 @@ void DropframeManager::RemoveLexModifyRecordOfTopFrame(JSThread *thread)
GlobalHandleCollection globalHandleCollection(thread);
for (const auto &item : modifiedLexVar_.top()) {
JSHandle<JSTaggedValue> envHandle = std::get<0>(item);
JSHandle<JSTaggedValue> valueHandle = std::get<2>(item); // get the third item of the tuple
JSHandle<JSTaggedValue> valueHandle = std::get<2>(item); // 2get the third item of the tuple
globalHandleCollection.Dispose(envHandle);
globalHandleCollection.Dispose(valueHandle);
}

View File

@ -563,7 +563,8 @@ static void DumpHClass(const JSHClass *jshclass, std::ostream &os, bool withDeta
if (supers.IsTaggedArray()) {
length = WeakVector::Cast(supers.GetTaggedObject())->GetExtraLength();
}
os << " - Supers[" << std::dec << length << "]: " << std::setw(DUMP_TYPE_OFFSET);;
os << " - Supers[" << std::dec << length << "]: ";
os << std::setw(DUMP_TYPE_OFFSET);
supers.DumpTaggedValue(os);
if (withDetail && !supers.IsUndefined()) {
WeakVector::Cast(supers.GetTaggedObject())->Dump(os);

View File

@ -103,7 +103,7 @@ EcmaString *EcmaString::CopyStringToOldSpace(const EcmaVM *vm, const JSHandle<Ec
EcmaString *newString = nullptr;
if (strOrigin->IsLineString()) {
newString = CreateLineStringWithSpaceType(vm, length, compressed, MemSpaceType::OLD_SPACE);
} else if (strOrigin->IsConstantString()){
} else if (strOrigin->IsConstantString()) {
return CreateConstantString(vm, strOrigin->GetDataUtf8(), length, MemSpaceType::OLD_SPACE);
}
strOrigin = *original;

View File

@ -16,8 +16,8 @@
#ifndef ECMASCRIPT_FILTER_HELPER_H
#define ECMASCRIPT_FILTER_HELPER_H
#include "ecmascript/property_attributes.h"
#include "ecmascript/object_operator.h"
#include "ecmascript/property_attributes.h"
#define NATIVE_DEFAULT 0
#define NATIVE_WRITABLE 1 << 0

View File

@ -337,7 +337,7 @@ void JSObject::GetAllKeys(const JSThread *thread, const JSHandle<JSObject> &obj,
}
void JSObject::GetAllKeysByFilter(const JSThread *thread, const JSHandle<JSObject> &obj,
uint32_t& keyArrayEffectivelength,
uint32_t &keyArrayEffectivelength,
const JSHandle<TaggedArray> &keyArray,
uint32_t filter)
{
@ -345,8 +345,8 @@ void JSObject::GetAllKeysByFilter(const JSThread *thread, const JSHandle<JSObjec
if (!array->IsDictionaryMode()) {
uint32_t numberOfProps = obj->GetJSHClass()->NumberOfProps();
if (numberOfProps > 0) {
LayoutInfo::Cast(obj->GetJSHClass()->GetLayout().GetTaggedObject())
->GetAllKeysByFilter(thread, numberOfProps, keyArrayEffectivelength, *keyArray, obj, filter);
LayoutInfo::Cast(obj->GetJSHClass()->GetLayout().GetTaggedObject())->
GetAllKeysByFilter(thread, numberOfProps, keyArrayEffectivelength, *keyArray, obj, filter);
}
return;
}
@ -468,7 +468,7 @@ void JSObject::GetAllElementKeys(JSThread *thread, const JSHandle<JSObject> &obj
void JSObject::GetAllElementKeysByFilter(JSThread *thread,
const JSHandle<JSObject> &obj,
const JSHandle<TaggedArray> &keyArray,
uint32_t &keyArrayEffectivelength,
uint32_t &keyArrayEffectiveLength,
uint32_t filter)
{
ASSERT_PRINT(obj->IsECMAObject(), "obj is not object");
@ -478,8 +478,8 @@ void JSObject::GetAllElementKeysByFilter(JSThread *thread,
if ((filter & NATIVE_ENUMERABLE) && obj->IsJSPrimitiveRef() && JSPrimitiveRef::Cast(*obj)->IsString()) {
elementIndex = JSPrimitiveRef::Cast(*obj)->GetStringLength();
for (uint32_t i = 0; i < elementIndex; ++i) {
keyArray->Set(thread, keyArrayEffectivelength, JSTaggedValue(i));
keyArrayEffectivelength++;
keyArray->Set(thread, keyArrayEffectiveLength, JSTaggedValue(i));
keyArrayEffectiveLength++;
}
}
@ -495,13 +495,13 @@ void JSObject::GetAllElementKeysByFilter(JSThread *thread,
if (bIgnore) {
continue;
}
keyArray->Set(thread, keyArrayEffectivelength, JSTaggedValue(i));
keyArrayEffectivelength++;
keyArray->Set(thread, keyArrayEffectiveLength, JSTaggedValue(i));
keyArrayEffectiveLength++;
}
}
} else {
NumberDictionary::GetAllKeysByFilter(thread, JSHandle<NumberDictionary>(elements),
keyArrayEffectivelength, keyArray, filter);
keyArrayEffectiveLength, keyArray, filter);
}
}
@ -1278,16 +1278,15 @@ JSHandle<TaggedArray> JSObject::GetOwnPropertyKeys(JSThread *thread, const JSHan
JSHandle<TaggedArray> JSObject::GetAllPropertyKeys(JSThread *thread, const JSHandle<JSObject> &obj, uint32_t filter)
{
bool isInculdePrototypes = (filter & NATIVE_KEY_INCLUDE_PROTOTYPES);
JSMutableHandle<JSObject> currentObj(thread, obj);
JSMutableHandle<JSTaggedValue> currentObjValue(thread, currentObj);
uint32_t curObjNumberOfElements = currentObj->GetNumberOfElements();
uint32_t curObjNumberOfKeys = currentObj->GetNumberOfKeys();
uint32_t curObjectKeysLength = curObjNumberOfElements + curObjNumberOfKeys;
uint32_t retArraylength = curObjectKeysLength;
uint32_t retArrayLength = curObjectKeysLength;
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
JSMutableHandle<TaggedArray> retArray(thread, factory->NewTaggedArray(retArraylength));
JSMutableHandle<TaggedArray> retArray(thread, factory->NewTaggedArray(retArrayLength));
uint32_t retArrayEffectivelength = 0;
do {
@ -1295,16 +1294,16 @@ JSHandle<TaggedArray> JSObject::GetAllPropertyKeys(JSThread *thread, const JSHan
curObjNumberOfKeys = currentObj->GetNumberOfKeys();
curObjectKeysLength = curObjNumberOfElements + curObjNumberOfKeys;
uint32_t minRequireLength = curObjectKeysLength + retArrayEffectivelength;
if (retArraylength < minRequireLength) {
if (retArrayLength < minRequireLength) {
// expand retArray
retArray.Update(factory->NewAndCopyTaggedArray(retArray, minRequireLength, retArraylength));
retArraylength = minRequireLength;
retArray.Update(factory->NewAndCopyTaggedArray(retArray, minRequireLength, retArrayLength));
retArrayLength = minRequireLength;
}
GetAllElementKeysByFilter(thread, currentObj, retArray, retArrayEffectivelength, filter);
GetAllKeysByFilter(thread, currentObj, retArrayEffectivelength, retArray, filter);
bool isInculdePrototypes = (filter & NATIVE_KEY_INCLUDE_PROTOTYPES);
if (!isInculdePrototypes) {
break;
}

View File

@ -576,7 +576,7 @@ public:
static void GetAllKeys(const JSHandle<JSObject> &obj, std::vector<JSTaggedValue> &keyVector);
static void GetAllKeysByFilter(const JSThread *thread, const JSHandle<JSObject> &obj,
uint32_t& keyArrayEffectivelength,
uint32_t &keyArrayEffectivelength,
const JSHandle<TaggedArray> &keyArray,
uint32_t filter);
static void GetAllElementKeys(JSThread *thread, const JSHandle<JSObject> &obj, int offset,
@ -584,7 +584,7 @@ public:
static void GetAllElementKeysByFilter(JSThread *thread,
const JSHandle<JSObject> &obj,
const JSHandle<TaggedArray> &keyArray,
uint32_t &keyArrayEffectivelength,
uint32_t &keyArrayEffectiveLength,
uint32_t filter);
static void GetALLElementKeysIntoVector(const JSThread *thread, const JSHandle<JSObject> &obj,

View File

@ -855,7 +855,7 @@ JSHandle<TaggedArray> JSTaggedValue::GetOwnPropertyKeys(JSThread *thread, const
}
JSHandle<TaggedArray> JSTaggedValue::GetAllPropertyKeys(JSThread *thread,
const JSHandle<JSTaggedValue> &obj, uint32_t filter)
const JSHandle<JSTaggedValue> &obj, uint32_t filter)
{
if (obj->IsJSProxy()) {
LOG_ECMA(WARN) << "GetAllPropertyKeys do not support JSProxy yet";

View File

@ -86,7 +86,7 @@ void LayoutInfo::GetAllKeys(const JSThread *thread, int end, int offset, TaggedA
}
}
void LayoutInfo::GetAllKeysByFilter(const JSThread *thread, uint32_t numberOfProps, uint32_t &keyArrayEffectivelength,
TaggedArray *keyArray, const JSHandle<JSObject> object, uint32_t filter)
TaggedArray *keyArray, const JSHandle<JSObject> object, uint32_t filter)
{
ASSERT(numberOfProps <= static_cast<uint32_t>(NumberOfElements()));
ASSERT_PRINT(keyArrayEffectivelength + numberOfProps <= keyArray->GetLength(),

View File

@ -83,7 +83,7 @@ void NameDictionary::GetAllKeys(const JSThread *thread, int offset, TaggedArray
}
void NameDictionary::GetAllKeysByFilter(const JSThread *thread, uint32_t &keyArrayEffectivelength,
TaggedArray *keyArray, uint32_t filter) const
TaggedArray *keyArray, uint32_t filter) const
{
int size = Size();
CVector<std::pair<JSTaggedValue, PropertyAttributes>> sortArr;
@ -115,8 +115,8 @@ void NameDictionary::GetAllKeysByFilter(const JSThread *thread, uint32_t &keyArr
void NameDictionary::GetAllEnumKeys(const JSThread *thread, int offset, TaggedArray *keyArray, uint32_t *keys) const
{
uint32_t arrayIndex = 0;
int size = Size();
CVector<std::pair<JSTaggedValue, PropertyAttributes>> sortArr;
int size = Size();
for (int hashIndex = 0; hashIndex < size; hashIndex++) {
JSTaggedValue key = GetKey(hashIndex);
if (key.IsString()) {
@ -187,7 +187,7 @@ int NumberDictionary::Hash(const JSTaggedValue &key)
}
if (key.IsDouble()) {
int32_t keyValue = static_cast<int32_t>(static_cast<uint32_t>(key.GetDouble()));
return GetHash32(reinterpret_cast<uint8_t *>(&keyValue), sizeof(keyValue) / sizeof(uint8_t));
return GetHash32(reinterpret_cast<uint8_t *>(&keyValue), sizeof(keyValue) / sizeof(uint8_t));
}
// key must be object
LOG_ECMA(FATAL) << "this branch is unreachable";
@ -247,22 +247,22 @@ void NumberDictionary::GetAllKeys(const JSThread *thread, const JSHandle<NumberD
}
void NumberDictionary::GetAllKeysByFilter(const JSThread *thread, const JSHandle<NumberDictionary> &obj,
uint32_t &keyArrayEffectivelength, const JSHandle<TaggedArray> &keyArray, uint32_t filter)
uint32_t &keyArrayEffectivelength, const JSHandle<TaggedArray> &keyArray,
uint32_t filter)
{
ASSERT_PRINT(keyArrayEffectivelength + static_cast<uint32_t>(obj->EntriesCount()) <= keyArray->GetLength(),
"keyArray capacity is not enough for dictionary");
uint32_t size = static_cast<uint32_t>(obj->Size());
CVector<JSTaggedValue> sortArr;
uint32_t size = static_cast<uint32_t>(obj->Size());
for (uint32_t hashIndex = 0; hashIndex < size; hashIndex++) {
JSTaggedValue key = obj->GetKey(hashIndex);
if (key.IsUndefined() || key.IsHole()) {
continue;
}
PropertyAttributes attr = obj->GetAttributes(hashIndex);
bool bIgnore = FilterHelper::IgnoreKeyByFilter<PropertyAttributes>(attr, filter);
if (!bIgnore) {
sortArr.push_back(JSTaggedValue(static_cast<uint32_t>(key.GetInt())));
}