From ab8a040f5cf4ffbd37655c4f1859645dffc2c11b Mon Sep 17 00:00:00 2001 From: Rafael Stahl Date: Wed, 24 Mar 2021 09:02:55 +0100 Subject: [PATCH 1/2] [crt] fix shift out of type bounds When running with "-fsanitize=undefined" I got the following error: tvm/src/runtime/crt/common/crt_runtime_api.c:213:32: runtime error: left shift of 32770 by 16 places cannot be represented in type 'int' The expression "module_index | 0x8000" is of type "int" and needs to be casted to unsigned before the shift. --- src/runtime/crt/common/crt_runtime_api.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/runtime/crt/common/crt_runtime_api.c b/src/runtime/crt/common/crt_runtime_api.c index c2eb1ff903e3..b5060fae92d6 100644 --- a/src/runtime/crt/common/crt_runtime_api.c +++ b/src/runtime/crt/common/crt_runtime_api.c @@ -209,8 +209,9 @@ int SystemLibraryCreate(TVMValue* args, int* type_codes, int num_args, TVMValue* static TVMFunctionHandle EncodeFunctionHandle(tvm_module_index_t module_index, tvm_function_index_t function_index) { - return (TVMFunctionHandle)((uintptr_t)( - ((module_index | 0x8000) << (sizeof(tvm_function_index_t) * 8)) | (function_index | 0x8000))); + return (TVMFunctionHandle)( + (((uintptr_t)(module_index | 0x8000) << (sizeof(tvm_function_index_t) * 8)) | + (function_index | 0x8000))); } static int DecodeFunctionHandle(TVMFunctionHandle handle, tvm_module_index_t* module_index, From d7c9f4a60e5b9355b3e7ab14ff9be9f21de7a7cc Mon Sep 17 00:00:00 2001 From: Rafael Stahl Date: Thu, 25 Mar 2021 22:26:25 +0100 Subject: [PATCH 2/2] trigger re-build --- src/runtime/crt/common/crt_runtime_api.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/runtime/crt/common/crt_runtime_api.c b/src/runtime/crt/common/crt_runtime_api.c index b5060fae92d6..efd7ea421dda 100644 --- a/src/runtime/crt/common/crt_runtime_api.c +++ b/src/runtime/crt/common/crt_runtime_api.c @@ -366,7 +366,7 @@ int TVMCFuncSetReturn(TVMRetValueHandle ret, TVMValue* value, int* type_code, in } int TVMFuncFree(TVMFunctionHandle func) { - // A no-op, since we don't actually allocate anything in GetFunction + // A no-op, since we don't actually allocate anything in GetFunction. return 0; }