fix option overflow

Signed-off-by: wengchangcheng <wengchangcheng@huawei.com>
Change-Id: I902c827b7c5c9a43098f272f9e0d5f2649c89644
This commit is contained in:
wengchangcheng 2024-03-15 17:19:20 +08:00
parent 2da5d20bdc
commit 18ee443845
3 changed files with 28 additions and 22 deletions

View File

@ -144,7 +144,7 @@ group("ark_unittest") {
if (!run_with_asan) {
if (!(ark_standalone_build && current_os == "ohos")) {
deps += [
# "ecmascript/compiler/tests:host_unittest",
"ecmascript/compiler/tests:host_unittest",
"ecmascript/ohos/tests:host_unittest",
]
}

View File

@ -210,10 +210,8 @@ bool JSRuntimeOptions::ParseCommand(const int argc, const char **argv)
{"enable-ic", required_argument, nullptr, OPTION_ENABLE_IC},
{"enable-runtime-stat", required_argument, nullptr, OPTION_ENABLE_RUNTIME_STAT},
{"compiler-opt-constant-folding", required_argument, nullptr, OPTION_COMPILER_OPT_CONSTANT_FOLDING},
{"compiler-opt-array-bounds-check-elimination",
required_argument,
nullptr,
OPTION_COMPILER_OPT_ARRAY_BOUNDS_CHECK_ELIMINATION},
{"compiler-opt-array-bounds-check-elimination", required_argument, nullptr,
OPTION_COMPILER_OPT_ARRAY_BOUNDS_CHECK_ELIMINATION},
{"compiler-opt-type-lowering", required_argument, nullptr, OPTION_COMPILER_OPT_TYPE_LOWERING},
{"compiler-opt-early-elimination", required_argument, nullptr, OPTION_COMPILER_OPT_EARLY_ELIMINATION},
{"compiler-opt-later-elimination", required_argument, nullptr, OPTION_COMPILER_OPT_LATER_ELIMINATION},
@ -246,7 +244,6 @@ bool JSRuntimeOptions::ParseCommand(const int argc, const char **argv)
{"merge-abc", required_argument, nullptr, OPTION_MERGE_ABC},
{"enable-context", required_argument, nullptr, OPTION_ENABLE_CONTEXT},
{"compiler-opt-level", required_argument, nullptr, OPTION_ASM_OPT_LEVEL},
{"options", no_argument, nullptr, OPTION_OPTIONS},
{"compiler-print-type-info", required_argument, nullptr, OPTION_COMPILER_PRINT_TYPE_INFO},
{"reloc-mode", required_argument, nullptr, OPTION_RELOCATION_MODE},
{"serializer-buffer-size-limit", required_argument, nullptr, OPTION_SERIALIZER_BUFFER_SIZE_LIMIT},
@ -273,10 +270,8 @@ bool JSRuntimeOptions::ParseCommand(const int argc, const char **argv)
{"compiler-pkg-info", required_argument, nullptr, OPTION_COMPILER_PKG_INFO},
{"compiler-external-pkg-info", required_argument, nullptr, OPTION_COMPILER_EXTERNAL_PKG_INFO},
{"compiler-enable-external-pkg", required_argument, nullptr, OPTION_COMPILER_ENABLE_EXTERNAL_PKG},
{"compiler-enable-lexenv-specialization",
required_argument,
nullptr,
OPTION_COMPILER_ENABLE_LEXENV_SPECIALIZATION},
{"compiler-enable-lexenv-specialization", required_argument, nullptr,
OPTION_COMPILER_ENABLE_LEXENV_SPECIALIZATION},
{"compiler-enable-native-inline", required_argument, nullptr, OPTION_COMPILER_ENABLE_NATIVE_INLINE},
{"compiler-enable-lowering-builtin", required_argument, nullptr, OPTION_COMPILER_ENABLE_LOWERING_BUILTIN},
{"compiler-enable-litecg", required_argument, nullptr, OPTION_COMPILER_ENABLE_LITECG},
@ -1049,7 +1044,7 @@ bool JSRuntimeOptions::SetDefaultValue(char* argv)
return false;
}
if (optopt > OPTION_OPTIONS) { // unknown argument
if (optopt >= OPTION_LAST) { // unknown argument
LOG_ECMA(ERROR) << "getopt: \"" << argv <<"\" argument has invalid parameter value \n";
return false;
}

View File

@ -65,6 +65,7 @@ extern const std::string PUBLIC_API HELP_OPTION_MSG;
enum CommandValues {
OPTION_DEFAULT,
OPTION_HELP,
OPTION_ENABLE_ARK_TOOLS,
OPTION_STUB_FILE,
OPTION_ENABLE_FORCE_GC,
@ -126,12 +127,11 @@ enum CommandValues {
OPTION_COMPILER_OPT_PGOTYPE,
OPTION_COMPILER_OPT_TRACK_FIELD,
OPTION_COMPILER_OPT_GLOBAL_TYPEINFER,
OPTION_HELP,
OPTION_COMPILER_PGO_PROFILER_PATH,
OPTION_SPLIT_ONE,
OPTION_COMPILER_PGO_HOTNESS_THRESHOLD,
OPTION_COMPILER_PGO_SAVE_MIN_INTERVAL,
OPTION_ENABLE_PGO_PROFILER,
OPTION_OPTIONS,
OPTION_PRINT_EXECUTE_TIME,
OPTION_COMPILER_VERIFY_VTABLE,
OPTION_COMPILER_SELECT_METHODS,
@ -171,7 +171,9 @@ enum CommandValues {
OPTION_COMPILER_OPT_BC_RANGE_HELP,
OPTION_COMPILER_OPT_ESCAPE_ANALYSIS,
OPTION_COMPILER_TRACE_ESCAPE_ANALYSIS,
OPTION_LAST,
};
static_assert(OPTION_SPLIT_ONE == 64);
class PUBLIC_API JSRuntimeOptions {
public:
@ -598,7 +600,7 @@ public:
bool WasSetCompilerLogOption() const
{
return 1ULL << static_cast<uint64_t>(OPTION_COMPILER_LOG_OPT) & wasSet_ &&
return WasOptionSet(OPTION_COMPILER_LOG_OPT) &&
GetCompilerLogOption().find("none") == std::string::npos;
}
@ -614,7 +616,7 @@ public:
bool WasSetMethodsListForLog() const
{
return 1ULL << static_cast<uint64_t>(OPTION_COMPILER_LOG_METHODS) & wasSet_ &&
return WasOptionSet(OPTION_COMPILER_LOG_METHODS) &&
GetCompilerLogOption().find("none") == std::string::npos &&
GetCompilerLogOption().find("all") == std::string::npos;
}
@ -1165,11 +1167,6 @@ public:
compilerModuleMethods_ = compilerModuleMethods;
}
void WasSet(int opt)
{
wasSet_ |= 1ULL << static_cast<uint64_t>(opt);
}
void SetTraceDeopt(bool value)
{
traceDeopt_ = value;
@ -1536,9 +1533,22 @@ private:
return std::equal(needle.begin(), needle.end(), haystack.begin());
}
void WasSet(int option)
{
if (option < OPTION_SPLIT_ONE) {
wasSetPartOne_ |= (1ULL << static_cast<uint64_t>(option));
} else {
wasSetPartTwo_ |= (1ULL << static_cast<uint64_t>(option - OPTION_SPLIT_ONE));
}
}
bool WasOptionSet(int option) const
{
return ((1ULL << static_cast<uint64_t>(option)) & wasSet_) != 0;
if (option < OPTION_SPLIT_ONE) {
return ((1ULL << static_cast<uint64_t>(option)) & wasSetPartOne_) != 0;
}
return ((1ULL << static_cast<uint64_t>(option - OPTION_SPLIT_ONE)) & wasSetPartTwo_) != 0;
}
bool ParseBoolParam(bool* argBool);
@ -1613,7 +1623,8 @@ private:
bool enableGlobalTypeInfer_ {false};
bool enableOptTrackField_ {true};
uint32_t compilerModuleMethods_ {100};
uint64_t wasSet_ {0};
uint64_t wasSetPartOne_ {0};
uint64_t wasSetPartTwo_ {0};
bool enableContext_ {false};
bool enablePrintExecuteTime_ {false};
bool enablePGOProfiler_ {false};