message: Add a new cmake option "ENABLE_UBSAN" to enable UndefinedBehaviorSanitizer.
diff: @@ -39,9 +39,11 @@ option(ENABLE_NATIVE "Whether to build native client" OFF)
  option(ENABLE_CCACHE "Whether to use ccache to speed up compiling" ON)
  option(ENABLE_ASAN "Whether to turn AddressSanitizer ON or OFF" OFF)
  option(ENABLE_TESTING "Whether to turn unit test ON or OFF" ON)
  +option(ENABLE_UBSAN "Whether to turn Undefined Behavior Sanitizer ON or OFF" OFF)
  message(STATUS "ENABLE_ASAN: ${ENABLE_ASAN}")
  message(STATUS "ENABLE_TESTING: ${ENABLE_TESTING}")
  +message(STATUS "ENABLE_UBSAN: ${ENABLE_UBSAN}")
  if (ENABLE_NATIVE)
  @@ -322,15 +324,34 @@ elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
  set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -latomic")
  endif()
  +include(CheckCXXCompilerFlag)
  if(ENABLE_ASAN)
  add_definitions(-DBUILT_WITH_SANITIZER)
  + set(CMAKE_REQUIRED_FLAGS "-fsanitize=address")
  + check_cxx_compiler_flag("-fsanitize=address" ENABLE_ASAN_OK)
  + if (NOT ENABLE_ASAN_OK)
  + MESSAGE(FATAL_ERROR "The compiler does not support address sanitizer")
  + endif()
  add_compile_options(-fsanitize=address)
  add_compile_options(-g)
  add_compile_options(-fno-omit-frame-pointer)
  set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address")
  endif()
  +if(ENABLE_UBSAN)
  + check_cxx_compiler_flag("-fsanitize=undefined -fno-sanitize=alignment" ENABLE_UBSAN_OK)
  + if (NOT ENABLE_UBSAN_OK)
  + MESSAGE(FATAL_ERROR "The compiler does not support Undefined Behavior Sanitizer")
  + endif()
  + add_compile_options(-fsanitize=undefined -fno-sanitize=alignment)
  + if(NOT ENABLE_ASAN)
  + add_compile_options(-g)
  + add_compile_options(-fno-omit-frame-pointer)
  + endif()
  + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=undefined")
  +endif()
  +
  macro(nebula_add_executable)
  cmake_parse_arguments(
  nebula_exec # prefix
  