From 1996912b34f5213bdf0a90f54a26b0d9aaa7bd90 Mon Sep 17 00:00:00 2001 From: Coldwings Date: Thu, 29 Feb 2024 15:08:50 +0800 Subject: [PATCH] Fix compile in gcc492, ignore some designed warning with diagnostic pragma Signed-off-by: Coldwings --- CMakeLists.txt | 2 ++ common/alog.h | 13 +++++++------ examples/perf/net-perf.cpp | 1 - net/http/client.cpp | 4 ++-- net/http/headers.cpp | 3 +++ net/utils.cpp | 3 +++ thread/thread.cpp | 3 +++ 7 files changed, 20 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1167c143..842fecea 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -61,6 +61,8 @@ set(CMAKE_BUILD_RPATH_USE_ORIGIN ON) set(CMAKE_POSITION_INDEPENDENT_CODE ON) set(CMAKE_BUILD_PARALLEL_LEVEL ${NumCPU}) +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-packed-bitfield-compat") + if (${ARCH} STREQUAL x86_64) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.2") elseif (${ARCH} STREQUAL aarch64) diff --git a/common/alog.h b/common/alog.h index c3a7de17..c1ca1790 100644 --- a/common/alog.h +++ b/common/alog.h @@ -347,13 +347,13 @@ struct Prologue int len_func, len_file; int line, level; - template - constexpr Prologue(const char (&addr_func_)[N], FILEN addr_file_, int line_, - int level_) + template + constexpr Prologue(const char (&addr_func_)[N], const char (&addr_file_)[M], + int line_, int level_) : addr_func(addr_func_), - addr_file(addr_file_.chars), + addr_file(addr_file_), len_func(N - 1), - len_file(addr_file_.len), + len_file(M - 1), line(line_), level(level_) {} }; @@ -456,7 +456,8 @@ struct LogBuilder { auto _partial_file = \ ConstString::TSpliter<'/', ' ', \ decltype(_prologue_file_r)>::Current::reverse(); \ - constexpr static Prologue prolog(__func__, _partial_file, __LINE__, level); + constexpr static Prologue prolog(__func__, _partial_file.chars, __LINE__, \ + level); #define _IS_LITERAL_STRING(x) \ (sizeof(#x) > 2 && (#x[0] == '"') && (#x[sizeof(#x) - 2] == '"')) diff --git a/examples/perf/net-perf.cpp b/examples/perf/net-perf.cpp index c2b94edd..eb24e28a 100644 --- a/examples/perf/net-perf.cpp +++ b/examples/perf/net-perf.cpp @@ -35,7 +35,6 @@ DEFINE_uint64(port, 9527, "port"); DEFINE_uint64(buf_size, 512, "buffer size"); DEFINE_uint64(vcpu_num, 1, "server vcpu num. Increase this value to enable multi-vcpu scheduling"); -static int event_engine = 0; static bool stop_test = false; static uint64_t qps = 0; static uint64_t time_cost = 0; diff --git a/net/http/client.cpp b/net/http/client.cpp index b78203d8..df349ba3 100644 --- a/net/http/client.cpp +++ b/net/http/client.cpp @@ -113,8 +113,8 @@ class ClientImpl : public Client { CommonHeaders<> m_common_headers; ICookieJar *m_cookie_jar; ClientImpl(ICookieJar *cookie_jar, TLSContext *tls_ctx) : - m_cookie_jar(cookie_jar), - m_dialer(tls_ctx) { + m_dialer(tls_ctx), + m_cookie_jar(cookie_jar) { } using SocketStream_ptr = std::unique_ptr; diff --git a/net/http/headers.cpp b/net/http/headers.cpp index de85a649..467e1ab7 100644 --- a/net/http/headers.cpp +++ b/net/http/headers.cpp @@ -151,7 +151,10 @@ HeadersBase::KV* HeadersBase::kv_add_sort(KV kv) { if ((char*)(begin - 1) <= m_buf + m_buf_size) LOG_ERROR_RETURN(ENOBUFS, nullptr, "no buffer"); auto it = std::lower_bound(begin, kv_end(), kv, HA(this)); +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wclass-memaccess" memmove(begin - 1, begin, sizeof(KV) * (it - begin)); +#pragma GCC diagnostic pop m_kv_size++; *(it - 1) = kv; return it - 1; diff --git a/net/utils.cpp b/net/utils.cpp index 3820e65a..4512733a 100644 --- a/net/utils.cpp +++ b/net/utils.cpp @@ -105,7 +105,10 @@ inline __attribute__((always_inline)) void base64_translate_3to4(const char *in, static const unsigned char tbl[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; auto v = htonl(*(uint32_t *)in); +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wstrict-aliasing" auto x = *(xlator *)(&v); +#pragma GCC diagnostic pop *(uint32_t *)out = ((tbl[x.a] << 24) + (tbl[x.b] << 16) + (tbl[x.c] << 8) + (tbl[x.d] << 0)); } diff --git a/thread/thread.cpp b/thread/thread.cpp index c3de95b5..473feed4 100644 --- a/thread/thread.cpp +++ b/thread/thread.cpp @@ -931,7 +931,10 @@ R"( stack_size = align_up(randomizer + stack_size + sizeof(thread), PAGE_SIZE); char* ptr = (char*)photon_thread_alloc(stack_size); auto p = ptr + stack_size - sizeof(thread) - randomizer; +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wstrict-aliasing" (uint64_t&)p &= ~63; +#pragma GCC diagnostic pop auto th = new (p) thread; th->buf = ptr; th->stackful_alloc_top = ptr;