Make RocksDB codebase compatible with newer compilers like clang-12 (#9370)
Summary: Pull Request resolved: https://github.com/facebook/rocksdb/pull/9370 GCC and newer clang, e.g. clang-12 treat `std::unique_ptr` slightly differently. For the following code ``` #include <iostream> #include <memory> #include <type_traits> struct A { std::unique_ptr<int> m1; }; int main() { std::cout << std::boolalpha; std::cout << std::is_standard_layout<A>::value << '\n'; return 0; } ``` GCC11(C++20) (tested on https://en.cppreference.com/w/cpp/types/is_standard_layout) will print "true", while newer clang, e.g. clang-12 will print "false". This breaks the usage of `offsetof()` on structs with non-static members of type `std::unique_ptr`. Fixing this by replacing the builtin `offsetof` with a trick documented at https://gist.github.com/graphitemaster/494f21190bb2c63c5516. Reviewed By: jay-zhuang Differential Revision: D33420840 fbshipit-source-id: 02bde281dfa28809bec787ad0f7019e85dd9c607
This commit is contained in:
parent
7bfad07194
commit
128e36ca53
@ -75,7 +75,7 @@ class Comparator : public Customizable {
|
|||||||
//
|
//
|
||||||
// Names starting with "rocksdb." are reserved and should not be used
|
// Names starting with "rocksdb." are reserved and should not be used
|
||||||
// by any clients of this package.
|
// by any clients of this package.
|
||||||
virtual const char* Name() const override = 0;
|
const char* Name() const override = 0;
|
||||||
|
|
||||||
// Advanced functions: these are used to reduce the space requirements
|
// Advanced functions: these are used to reduce the space requirements
|
||||||
// for internal data structures like index blocks.
|
// for internal data structures like index blocks.
|
||||||
|
@ -85,7 +85,7 @@ class FileChecksumGenFactory : public Customizable {
|
|||||||
const FileChecksumGenContext& context) = 0;
|
const FileChecksumGenContext& context) = 0;
|
||||||
|
|
||||||
// Return the name of this FileChecksumGenFactory.
|
// Return the name of this FileChecksumGenFactory.
|
||||||
virtual const char* Name() const override = 0;
|
const char* Name() const override = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
// FileChecksumList stores the checksum information of a list of files (e.g.,
|
// FileChecksumList stores the checksum information of a list of files (e.g.,
|
||||||
|
@ -311,7 +311,7 @@ class MemTableRepFactory : public Customizable {
|
|||||||
return CreateMemTableRep(key_cmp, allocator, slice_transform, logger);
|
return CreateMemTableRep(key_cmp, allocator, slice_transform, logger);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual const char* Name() const override = 0;
|
const char* Name() const override = 0;
|
||||||
|
|
||||||
// Return true if the current MemTableRep supports concurrent inserts
|
// Return true if the current MemTableRep supports concurrent inserts
|
||||||
// Default: false
|
// Default: false
|
||||||
|
@ -93,7 +93,7 @@ class SstPartitionerFactory : public Customizable {
|
|||||||
const SstPartitioner::Context& context) const = 0;
|
const SstPartitioner::Context& context) const = 0;
|
||||||
|
|
||||||
// Returns a name that identifies this partitioner factory.
|
// Returns a name that identifies this partitioner factory.
|
||||||
virtual const char* Name() const override = 0;
|
const char* Name() const override = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -162,7 +162,7 @@ class TablePropertiesCollectorFactory : public Customizable {
|
|||||||
TablePropertiesCollectorFactory::Context context) = 0;
|
TablePropertiesCollectorFactory::Context context) = 0;
|
||||||
|
|
||||||
// The name of the properties collector can be used for debugging purpose.
|
// The name of the properties collector can be used for debugging purpose.
|
||||||
virtual const char* Name() const override = 0;
|
const char* Name() const override = 0;
|
||||||
|
|
||||||
// Can be overridden by sub-classes to return the Name, followed by
|
// Can be overridden by sub-classes to return the Name, followed by
|
||||||
// configuration info that will // be logged to the info log when the
|
// configuration info that will // be logged to the info log when the
|
||||||
|
@ -202,22 +202,31 @@ struct SimpleOptions {
|
|||||||
TestCustomizable* cp = nullptr;
|
TestCustomizable* cp = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static SimpleOptions dummy_simple_options;
|
||||||
|
template <typename T1>
|
||||||
|
int offset_of(T1 SimpleOptions::*member) {
|
||||||
|
return static_cast<int>(
|
||||||
|
reinterpret_cast<uintptr_t>(
|
||||||
|
std::addressof(dummy_simple_options.*member)) -
|
||||||
|
reinterpret_cast<uintptr_t>(std::addressof(dummy_simple_options)));
|
||||||
|
}
|
||||||
|
|
||||||
static std::unordered_map<std::string, OptionTypeInfo> simple_option_info = {
|
static std::unordered_map<std::string, OptionTypeInfo> simple_option_info = {
|
||||||
#ifndef ROCKSDB_LITE
|
#ifndef ROCKSDB_LITE
|
||||||
{"bool",
|
{"bool",
|
||||||
{offsetof(struct SimpleOptions, b), OptionType::kBoolean,
|
{offset_of(&SimpleOptions::b), OptionType::kBoolean,
|
||||||
OptionVerificationType::kNormal, OptionTypeFlags::kNone}},
|
OptionVerificationType::kNormal, OptionTypeFlags::kNone}},
|
||||||
{"unique",
|
{"unique",
|
||||||
OptionTypeInfo::AsCustomUniquePtr<TestCustomizable>(
|
OptionTypeInfo::AsCustomUniquePtr<TestCustomizable>(
|
||||||
offsetof(struct SimpleOptions, cu), OptionVerificationType::kNormal,
|
offset_of(&SimpleOptions::cu), OptionVerificationType::kNormal,
|
||||||
OptionTypeFlags::kAllowNull)},
|
OptionTypeFlags::kAllowNull)},
|
||||||
{"shared",
|
{"shared",
|
||||||
OptionTypeInfo::AsCustomSharedPtr<TestCustomizable>(
|
OptionTypeInfo::AsCustomSharedPtr<TestCustomizable>(
|
||||||
offsetof(struct SimpleOptions, cs), OptionVerificationType::kNormal,
|
offset_of(&SimpleOptions::cs), OptionVerificationType::kNormal,
|
||||||
OptionTypeFlags::kAllowNull)},
|
OptionTypeFlags::kAllowNull)},
|
||||||
{"pointer",
|
{"pointer",
|
||||||
OptionTypeInfo::AsCustomRawPtr<TestCustomizable>(
|
OptionTypeInfo::AsCustomRawPtr<TestCustomizable>(
|
||||||
offsetof(struct SimpleOptions, cp), OptionVerificationType::kNormal,
|
offset_of(&SimpleOptions::cp), OptionVerificationType::kNormal,
|
||||||
OptionTypeFlags::kAllowNull)},
|
OptionTypeFlags::kAllowNull)},
|
||||||
#endif // ROCKSDB_LITE
|
#endif // ROCKSDB_LITE
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user