From 31f331b37b0af386cae00351bd08e3959b298a16 Mon Sep 17 00:00:00 2001 From: Brian Neradt Date: Sat, 14 May 2022 23:00:01 +0000 Subject: [PATCH] Fix Rocky Linux 8 arm64 GCC Compiler Warnings This patch addresses the compiler warnings raised by the GCC 11.2.1 compiler on Rocky Linux 8 arm64: -Werror=shift-negative-value in I_Continuation.h: In file included from src/ts_asf_master_test_build/iocore/eventsystem/I_Action.h:29, from src/ts_asf_master_test_build/iocore/eventsystem/I_EventSystem.h:32, from src/ts_asf_master_test_build/iocore/eventsystem/I_VConnection.h:29, from QUICStreamVCAdapter.cc:24: src/ts_asf_master_test_build/iocore/eventsystem/I_Continuation.h: In instantiation of _constexpr int (Continuation::* continuation_handler_void_ptr(int (C::*)(int, T*)))(int, void*) [with C = QUICStreamVCAdapter; T = void; ContinuationHandler = int (Continuation: :*)(int, void*)]_: QUICStreamVCAdapter.cc:29:3: required from here src/ts_asf_master_test_build/iocore/eventsystem/I_Continuation.h:74:10: error: left shift of negative value [-Werror=shift-negative-value] 74 | return static_cast(fp2); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Werror=sign-compare in fastlz.cc: This fixes a gcc 11.2.1 compiler warning in Rocky Linux 8 arm64: fastlz.cc: In function _void flz_copy64(uint8_t*, const uint8_t*, uint32_t)_: fastlz.cc:209:17: error: comparison of integer expressions of different signedness: _int_ and _uint32_t_ {aka _unsigned int_} [-Werror=sign-compare] 209 | for (c = 0; c < count * 8; ++c) { | ~~^~~~~~~~~~~ -Werror=maybe-uninitialized in header_rewrite: header_rewrite/conditions.cc: In static member function _static void ConditionInbound::append_value(std::string&, const Resources&, NetworkSessionQualifiers)_: header_rewrite/conditions.cc:1131:56: error: _tags_ may be used uninitialized [-Werror=maybe-uninitialized] 1131 | TSHttpTxnClientProtocolStackGet(res.txnp, tags.size(), tags.data(), &count); | ~~~~~~~~~^~ In file included from header_rewrite/conditions.cc:29: /opt/rh/gcc-toolset-11/root/usr/include/c++/11/array:176:7: note: by argument 1 of type _const std::array*_ to _constexpr std::array<_Tp, _Nm>::size_type std::array<_Tp, _Nm>::size() const [with _Tp = const char*; long unsigned int _Nm = 8]_ declared here 176 | size() const noexcept { return _Nm; } | ^~~~ header_rewrite/conditions.cc:1128:33: note: _tags_ declared here 1128 | std::array tags; | ^~~~ -Werror=type-limits in traffic_dump: experimental/traffic_dump/json_utils.cc: In function _int {anonymous}::esc_json_out(const char*, int64_t, std::ostream&)_: experimental/traffic_dump/json_utils.cc:117:18: error: comparison is always true due to limited range of data type [-Werror=type-limits] 117 | if ('\x00' <= c && c <= '\x1f') { | ~~~~~~~^~~~ --- iocore/eventsystem/I_Continuation.h | 8 ++++++++ iocore/net/quic/QUICStreamVCAdapter.cc | 2 +- iocore/net/quic/QUICStreamVCAdapter.h | 2 +- lib/fastlz/fastlz.cc | 2 +- plugins/experimental/traffic_dump/json_utils.cc | 2 +- plugins/header_rewrite/conditions.cc | 6 +++--- proxy/http3/Http3HeaderVIOAdaptor.h | 2 +- 7 files changed, 16 insertions(+), 8 deletions(-) diff --git a/iocore/eventsystem/I_Continuation.h b/iocore/eventsystem/I_Continuation.h index 10d328c5d41..8493995f3c5 100644 --- a/iocore/eventsystem/I_Continuation.h +++ b/iocore/eventsystem/I_Continuation.h @@ -71,6 +71,14 @@ constexpr ContinuationHandler continuation_handler_void_ptr(int (C::*fp)(int, T *)) { auto fp2 = reinterpret_cast(fp); + + // We keep this a static_cast for added static type analysis from the + // compiler. If a compiler warning is generated for the following line of + // code of the type "-Werror=shift-negative-value", then this may be an issue + // with multiple inheritance of the C templated type. Make sure that for type + // C the Continuation parent is listed first (either directly or indirectly + // via the inheritance tree) before any other parent in the multiple class + // heirarchy of C. return static_cast(fp2); } diff --git a/iocore/net/quic/QUICStreamVCAdapter.cc b/iocore/net/quic/QUICStreamVCAdapter.cc index b8c4afc89fd..1dc018337c7 100644 --- a/iocore/net/quic/QUICStreamVCAdapter.cc +++ b/iocore/net/quic/QUICStreamVCAdapter.cc @@ -24,7 +24,7 @@ #include "I_VConnection.h" #include "QUICStreamVCAdapter.h" -QUICStreamVCAdapter::QUICStreamVCAdapter(QUICStream &stream) : QUICStreamAdapter(stream), VConnection(new_ProxyMutex()) +QUICStreamVCAdapter::QUICStreamVCAdapter(QUICStream &stream) : VConnection(new_ProxyMutex()), QUICStreamAdapter(stream) { SET_HANDLER(&QUICStreamVCAdapter::state_stream_open); } diff --git a/iocore/net/quic/QUICStreamVCAdapter.h b/iocore/net/quic/QUICStreamVCAdapter.h index 36131599544..4b185437c75 100644 --- a/iocore/net/quic/QUICStreamVCAdapter.h +++ b/iocore/net/quic/QUICStreamVCAdapter.h @@ -25,7 +25,7 @@ #include "QUICStreamAdapter.h" #include "I_IOBuffer.h" -class QUICStreamVCAdapter : public QUICStreamAdapter, public VConnection +class QUICStreamVCAdapter : public VConnection, public QUICStreamAdapter { public: class IOInfo; diff --git a/lib/fastlz/fastlz.cc b/lib/fastlz/fastlz.cc index b29420f27b6..2e9bfb3d72d 100644 --- a/lib/fastlz/fastlz.cc +++ b/lib/fastlz/fastlz.cc @@ -205,7 +205,7 @@ flz_copy64(uint8_t *dest, const uint8_t *src, uint32_t count) { const uint8_t *p = (const uint8_t *)src; uint8_t *q = (uint8_t *)dest; - int c; + unsigned int c; for (c = 0; c < count * 8; ++c) { *q++ = *p++; } diff --git a/plugins/experimental/traffic_dump/json_utils.cc b/plugins/experimental/traffic_dump/json_utils.cc index e45f9c753f4..16b7aad98e3 100644 --- a/plugins/experimental/traffic_dump/json_utils.cc +++ b/plugins/experimental/traffic_dump/json_utils.cc @@ -114,7 +114,7 @@ esc_json_out(const char *buf, int64_t len, std::ostream &jsonfile) break; } default: { - if ('\x00' <= c && c <= '\x1f') { + if (c <= '\x1f') { write_buffered_context(buf, prevIdx, idx, jsonfile); jsonfile << "\\u" << std::hex << std::setw(4) << std::setfill('0') << static_cast(c); } diff --git a/plugins/header_rewrite/conditions.cc b/plugins/header_rewrite/conditions.cc index 74ef0ee0664..fa0e092ed92 100644 --- a/plugins/header_rewrite/conditions.cc +++ b/plugins/header_rewrite/conditions.cc @@ -1125,9 +1125,9 @@ ConditionInbound::append_value(std::string &s, const Resources &res, NetworkSess zret = TSHttpTxnClientProtocolStackContains(res.txnp, "ip"); break; case NET_QUAL_STACK: { - std::array tags; - int count = 0; - size_t len = 0; + std::array tags = {}; + int count = 0; + size_t len = 0; TSHttpTxnClientProtocolStackGet(res.txnp, tags.size(), tags.data(), &count); for (int i = 0; i < count; ++i) { len += 1 + strlen(tags[i]); diff --git a/proxy/http3/Http3HeaderVIOAdaptor.h b/proxy/http3/Http3HeaderVIOAdaptor.h index 4f064a2dac0..e4cc0ff1571 100644 --- a/proxy/http3/Http3HeaderVIOAdaptor.h +++ b/proxy/http3/Http3HeaderVIOAdaptor.h @@ -27,7 +27,7 @@ #include "Http3FrameHandler.h" -class Http3HeaderVIOAdaptor : public Http3FrameHandler, public Continuation +class Http3HeaderVIOAdaptor : public Continuation, public Http3FrameHandler { public: Http3HeaderVIOAdaptor(VIO *sink, HTTPType http_type, QPACK *qpack, uint64_t stream_id);