From db251e8e416b7743a27cc541ac4f7d4494598c5a Mon Sep 17 00:00:00 2001 From: Shuduo Sang Date: Wed, 9 Jun 2021 06:51:14 +0800 Subject: [PATCH] Feature/sangshuduo/td 4198 support address sanitizer for develop (#6414) * [TD-4198]: support AddressSanitizer on windows. * fix compile flag. * fix compile warning for early version visual c++. * disable memory sanitizer by default. * fix variable name * add static lib link. --- cmake/define.inc | 27 +++++++++++++++++++++------ cmake/input.inc | 5 +++++ src/query/src/qAggMain.c | 4 ++-- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/cmake/define.inc b/cmake/define.inc index cc8bd0fc35..441bf19997 100755 --- a/cmake/define.inc +++ b/cmake/define.inc @@ -122,10 +122,14 @@ IF (TD_LINUX) ADD_DEFINITIONS(-D_TD_NINGSI_60) MESSAGE(STATUS "set ningsi macro to true") ENDIF () - - SET(DEBUG_FLAGS "-O0 -g3 -DDEBUG") + + IF (TD_MEMORY_SANITIZER) + SET(DEBUG_FLAGS "-fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fno-sanitize=null -fno-sanitize=alignment -static-libasan -O0 -g3 -DDEBUG") + ELSE () + SET(DEBUG_FLAGS "-O0 -g3 -DDEBUG") + ENDIF () SET(RELEASE_FLAGS "-O3 -Wno-error") - + IF (${COVER} MATCHES "true") MESSAGE(STATUS "Test coverage mode, add extra flags") SET(GCC_COVERAGE_COMPILE_FLAGS "-fprofile-arcs -ftest-coverage") @@ -144,7 +148,11 @@ IF (TD_DARWIN_64) ADD_DEFINITIONS(-DUSE_LIBICONV) MESSAGE(STATUS "darwin64 is defined") SET(COMMON_FLAGS "-std=gnu99 -Wall -Werror -Wno-missing-braces -fPIC -msse4.2 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE") - SET(DEBUG_FLAGS "-O0 -g3 -DDEBUG") + IF (TD_MEMORY_SANITIZER) + SET(DEBUG_FLAGS "-fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fno-sanitize=null -fno-sanitize=alignment -O0 -g3 -DDEBUG") + ELSE () + SET(DEBUG_FLAGS "-O0 -g3 -DDEBUG") + ENDIF () SET(RELEASE_FLAGS "-Og") INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/cJson/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/lz4/inc) @@ -162,7 +170,14 @@ IF (TD_WINDOWS) IF (MSVC AND (MSVC_VERSION GREATER_EQUAL 1900)) SET(COMMON_FLAGS "${COMMON_FLAGS} /Wv:18") ENDIF () - SET(DEBUG_FLAGS "/fsanitize=thread /fsanitize=leak /fsanitize=memory /fsanitize=undefined /fsanitize=hwaddress /Zi /W3 /GL") + + IF (TD_MEMORY_SANITIZER) +MESSAGE("memory sanitizer detected as true") + SET(DEBUG_FLAGS "/fsanitize=address /Zi /W3 /GL") + ELSE () +MESSAGE("memory sanitizer detected as false") + SET(DEBUG_FLAGS "/Zi /W3 /GL") + ENDIF () SET(RELEASE_FLAGS "/W0 /O3 /GL") ENDIF () @@ -171,7 +186,7 @@ IF (TD_WINDOWS) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/regex) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/wepoll/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/MsvcLibX/include) -ENDIF () +ENDIF () IF (TD_WINDOWS_64) ADD_DEFINITIONS(-D_M_X64) diff --git a/cmake/input.inc b/cmake/input.inc index 9b72a35d94..c073bbbc03 100755 --- a/cmake/input.inc +++ b/cmake/input.inc @@ -83,3 +83,8 @@ SET(TD_BUILD_JDBC TRUE) IF (${BUILD_JDBC} MATCHES "false") SET(TD_BUILD_JDBC FALSE) ENDIF () + +SET(TD_MEMORY_SANITIZER FALSE) +IF (${MEMORY_SANITIZER} MATCHES "true") + SET(TD_MEMORY_SANITIZER TRUE) +ENDIF () diff --git a/src/query/src/qAggMain.c b/src/query/src/qAggMain.c index ca7b44e3a4..77185342c2 100644 --- a/src/query/src/qAggMain.c +++ b/src/query/src/qAggMain.c @@ -4687,8 +4687,8 @@ static bool rate_function_setup(SQLFunctionCtx *pCtx) { pInfo->correctionValue = 0; pInfo->firstKey = INT64_MIN; pInfo->lastKey = INT64_MIN; - pInfo->firstValue = INT64_MIN; - pInfo->lastValue = INT64_MIN; + pInfo->firstValue = (double) INT64_MIN; + pInfo->lastValue = (double) INT64_MIN; pInfo->hasResult = 0; pInfo->isIRate = (pCtx->functionId == TSDB_FUNC_IRATE); -- GitLab