From 52fd1ff2c2570ce0c3b79be4d1b6a7a700718d42 Mon Sep 17 00:00:00 2001 From: Islam AbdelRahman Date: Mon, 28 Nov 2016 17:46:35 -0800 Subject: [PATCH] disable UBSAN for functions with intentional -ve shift / overflow Summary: disable UBSAN for functions with intentional left shift on -ve number / overflow These functions are rocksdb:: Hash FixedLengthColBufEncoder::Append FaultInjectionTest:: Key Closes https://github.com/facebook/rocksdb/pull/1577 Differential Revision: D4240801 Pulled By: IslamAbdelRahman fbshipit-source-id: 3e1caf6 --- db/fault_injection_test.cc | 5 +++++ util/hash.cc | 6 ++++++ utilities/col_buf_encoder.cc | 5 +++++ 3 files changed, 16 insertions(+) diff --git a/db/fault_injection_test.cc b/db/fault_injection_test.cc index 8200de1b6..d06db2847 100644 --- a/db/fault_injection_test.cc +++ b/db/fault_injection_test.cc @@ -228,6 +228,11 @@ class FaultInjectionTest : public testing::Test, return Status::OK(); } +#if defined(__clang__) +__attribute__((__no_sanitize__("undefined"))) +#elif __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 9) +__attribute__((__no_sanitize_undefined__)) +#endif // Return the ith key Slice Key(int i, std::string* storage) const { int num = i; diff --git a/util/hash.cc b/util/hash.cc index dfd2dc403..ce0790a8f 100644 --- a/util/hash.cc +++ b/util/hash.cc @@ -13,6 +13,12 @@ namespace rocksdb { +// This function may intentionally do a left shift on a -ve number +#if defined(__clang__) +__attribute__((__no_sanitize__("undefined"))) +#elif __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 9) +__attribute__((__no_sanitize_undefined__)) +#endif uint32_t Hash(const char* data, size_t n, uint32_t seed) { // Similar to murmur hash const uint32_t m = 0xc6a4a793; diff --git a/utilities/col_buf_encoder.cc b/utilities/col_buf_encoder.cc index fc5d6cdac..f9098d403 100644 --- a/utilities/col_buf_encoder.cc +++ b/utilities/col_buf_encoder.cc @@ -46,6 +46,11 @@ ColBufEncoder *ColBufEncoder::NewColBufEncoder( return nullptr; } +#if defined(__clang__) +__attribute__((__no_sanitize__("undefined"))) +#elif __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 9) +__attribute__((__no_sanitize_undefined__)) +#endif size_t FixedLengthColBufEncoder::Append(const char *buf) { if (nullable_) { if (buf == nullptr) {