diff --git a/ecmascript/compiler/codegen/maple/maple_ir/include/parse_preg_no.h b/ecmascript/compiler/codegen/maple/maple_ir/include/parse_preg_no.h new file mode 100644 index 0000000000..1a3a244f36 --- /dev/null +++ b/ecmascript/compiler/codegen/maple/maple_ir/include/parse_preg_no.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2026 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef PARSE_PREG_NO_H +#define PARSE_PREG_NO_H + +#include +#include +#include +#include + +inline bool ParsePregNo(const std::string &s, uint32_t &out) +{ + if (s.empty()) { + return false; + } + uint32_t value = 0; + const char *first = s.data(); + const char *last = first + s.size(); + auto result = std::from_chars(first, last, value); + if (result.ec != std::errc() || result.ptr != last) { + return false; + } + out = value; + return true; +} + +#endif diff --git a/ecmascript/compiler/codegen/maple/maple_ir/src/mir_function.cpp b/ecmascript/compiler/codegen/maple/maple_ir/src/mir_function.cpp index b826b54f25..2ddc668bba 100644 --- a/ecmascript/compiler/codegen/maple/maple_ir/src/mir_function.cpp +++ b/ecmascript/compiler/codegen/maple/maple_ir/src/mir_function.cpp @@ -14,7 +14,9 @@ */ #include "mir_function.h" +#include "parse_preg_no.h" #include "printing.h" +#include namespace { using namespace maple; @@ -440,12 +442,13 @@ void MIRFunction::EnterFormals() formalDef.formalSym->SetTyIdx(formalDef.formalTyIdx); formalDef.formalSym->SetAttrs(formalDef.formalAttrs); const std::string &formalName = GlobalTables::GetStrTable().GetStringFromStrIdx(formalDef.formalStrIdx); - if (!isdigit(formalName.front())) { + uint32 thepregno = 0; + if (formalName.empty() || !isdigit(static_cast(formalName.front())) || + !ParsePregNo(formalName, thepregno)) { formalDef.formalSym->SetSKind(kStVar); (void)symTab->AddToStringSymbolMap(*formalDef.formalSym); } else { formalDef.formalSym->SetSKind(kStPreg); - uint32 thepregno = static_cast(std::stoi(formalName)); MIRType *mirType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(formalDef.formalTyIdx); PrimType pType = mirType->GetPrimType(); // if mirType info is not needed, set mirType to nullptr