Fix clang 3.6+ + libc++ CE.

GitOrigin-RevId: 743acf2c12c981ec35266356725116f568867903
This commit is contained in:
levlam 2018-04-12 20:10:23 +03:00
parent 3330d565f6
commit d8c3c2c505

View File

@ -8,8 +8,16 @@
#include "td/utils/port/thread_local.h" #include "td/utils/port/thread_local.h"
#include <cstddef>
#include <new> #include <new>
// fixes https://bugs.llvm.org/show_bug.cgi?id=33723 for clang >= 3.6 + c++11 + libc++
#if TD_CLANG && _LIBCPP_VERSION
#define TD_OFFSETOF __builtin_offsetof
#else
#define TD_OFFSETOF offsetof
#endif
namespace td { namespace td {
TD_THREAD_LOCAL BufferAllocator::BufferRawTls *BufferAllocator::buffer_raw_tls; // static zero-initialized TD_THREAD_LOCAL BufferAllocator::BufferRawTls *BufferAllocator::buffer_raw_tls; // static zero-initialized
@ -76,7 +84,7 @@ BufferAllocator::ReaderPtr BufferAllocator::create_reader(const ReaderPtr &raw)
void BufferAllocator::dec_ref_cnt(BufferRaw *ptr) { void BufferAllocator::dec_ref_cnt(BufferRaw *ptr) {
int left = ptr->ref_cnt_.fetch_sub(1, std::memory_order_acq_rel); int left = ptr->ref_cnt_.fetch_sub(1, std::memory_order_acq_rel);
if (left == 1) { if (left == 1) {
auto buf_size = max(sizeof(BufferRaw), offsetof(BufferRaw, data_) + ptr->data_size_); auto buf_size = max(sizeof(BufferRaw), TD_OFFSETOF(BufferRaw, data_) + ptr->data_size_);
buffer_mem -= buf_size; buffer_mem -= buf_size;
ptr->~BufferRaw(); ptr->~BufferRaw();
delete[] ptr; delete[] ptr;
@ -86,7 +94,7 @@ void BufferAllocator::dec_ref_cnt(BufferRaw *ptr) {
BufferRaw *BufferAllocator::create_buffer_raw(size_t size) { BufferRaw *BufferAllocator::create_buffer_raw(size_t size) {
size = (size + 7) & -8; size = (size + 7) & -8;
auto buf_size = offsetof(BufferRaw, data_) + size; auto buf_size = TD_OFFSETOF(BufferRaw, data_) + size;
if (buf_size < sizeof(BufferRaw)) { if (buf_size < sizeof(BufferRaw)) {
buf_size = sizeof(BufferRaw); buf_size = sizeof(BufferRaw);
} }