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
This commit is contained in:
Islam AbdelRahman 2016-11-28 17:46:35 -08:00
parent 826b5013a5
commit 60f60c8475
3 changed files with 16 additions and 0 deletions

View File

@ -228,6 +228,11 @@ class FaultInjectionTest : public testing::Test,
return Status::OK(); 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 // Return the ith key
Slice Key(int i, std::string* storage) const { Slice Key(int i, std::string* storage) const {
int num = i; int num = i;

View File

@ -13,6 +13,12 @@
namespace rocksdb { 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) { uint32_t Hash(const char* data, size_t n, uint32_t seed) {
// Similar to murmur hash // Similar to murmur hash
const uint32_t m = 0xc6a4a793; const uint32_t m = 0xc6a4a793;

View File

@ -46,6 +46,11 @@ ColBufEncoder *ColBufEncoder::NewColBufEncoder(
return nullptr; 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) { size_t FixedLengthColBufEncoder::Append(const char *buf) {
if (nullable_) { if (nullable_) {
if (buf == nullptr) { if (buf == nullptr) {