Skip to content

Commit

Permalink
Fix UT failures with UBSan (vesoft-inc#1661)
Browse files Browse the repository at this point in the history
 * Fixed two failures found by UBSan
 * Tweaks to make UBSan more usable
  • Loading branch information
dutor authored Jan 19, 2020
1 parent c62e5cf commit f80b1aa
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,11 @@ endif()

include(CheckCXXCompilerFlag)

if(ENABLE_ASAN)
if(ENABLE_ASAN OR ENABLE_UBSAN)
add_definitions(-DBUILT_WITH_SANITIZER)
endif()

if(ENABLE_ASAN)
set(CMAKE_REQUIRED_FLAGS "-fsanitize=address")
check_cxx_compiler_flag("-fsanitize=address" ENABLE_ASAN_OK)
if (NOT ENABLE_ASAN_OK)
Expand All @@ -294,6 +297,7 @@ if(ENABLE_UBSAN)
MESSAGE(FATAL_ERROR "The compiler does not support Undefined Behavior Sanitizer")
endif()
add_compile_options(-fsanitize=undefined -fno-sanitize=alignment)
add_compile_options(-fno-sanitize-recover=all) # Exit on failure
# TODO(dutor) Remove the following line when RTTI-enabled RocksDB is ready
add_compile_options(-fno-sanitize=vptr)
if(NOT ENABLE_ASAN)
Expand Down
6 changes: 6 additions & 0 deletions src/common/base/SanitizerOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ const char* __lsan_default_suppressions() {
"";
}


SANITIZER_HOOK_ATTRIBUTES
const char* __ubsan_default_options() {
return "print_stacktrace=1 \n";
}

} // extern "C"

#undef SANITIZER_HOOK_ATTRIBUTES
Expand Down
3 changes: 3 additions & 0 deletions src/graph/test/YieldTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -570,12 +570,15 @@ TEST_F(YieldTest, calculateOverflow) {
auto code = client->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
}
// Negation of -9223372036854775808 incurs a runtime error under UBSan
#ifndef BUILT_WITH_SANITIZER
{
cpp2::ExecutionResponse resp;
std::string query = "YIELD -9223372036854775808";
auto code = client->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
}
#endif
{
cpp2::ExecutionResponse resp;
std::string query = "YIELD -9223372036854775809";
Expand Down
2 changes: 1 addition & 1 deletion src/storage/test/QueryVertexPropsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ TEST(QueryVertexPropsTest, QueryAfterTagAltered) {
auto schemaMng = TestUtils::mockSchemaMan();

auto spaceId = 0;
TagVersion version = std::numeric_limits<int64_t>::max() - 0;
TagVersion version = std::numeric_limits<int64_t>::max() / 2 /* in case of overflow */;

{
LOG(INFO) << "Prepare data...";
Expand Down

0 comments on commit f80b1aa

Please sign in to comment.