From 67ba35bac061e3be742f35daf0c89b51c5337fa5 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Tue, 16 Apr 2024 20:30:27 +0000 Subject: [PATCH] [esoteric] Eliminate unused argument errors with GPR_DEBUG_ASSERT (#36373) Eliminate cases where we get unused parameter errors only because of a debug assert, and because of short-circuit evaluation not add any overhead into release builds. Closes #36373 COPYBARA_INTEGRATE_REVIEW=https://github.com/grpc/grpc/pull/36373 from ctiller:ugh123 073ea1236a0963972de270cf0acf02ebe4e4bf50 PiperOrigin-RevId: 625435672 --- include/grpc/support/log.h | 2 +- include/grpcpp/support/callback_common.h | 2 ++ src/core/client_channel/client_channel_filter.cc | 2 ++ src/core/load_balancing/xds/xds_cluster_impl.cc | 5 +++-- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/include/grpc/support/log.h b/include/grpc/support/log.h index a118561904d..6e5cf4b7157 100644 --- a/include/grpc/support/log.h +++ b/include/grpc/support/log.h @@ -102,7 +102,7 @@ GPRAPI void gpr_assertion_failed(const char* filename, int line, #ifndef NDEBUG #define GPR_DEBUG_ASSERT(x) GPR_ASSERT(x) #else -#define GPR_DEBUG_ASSERT(x) +#define GPR_DEBUG_ASSERT(x) GPR_ASSERT(true || (x)) #endif #ifdef __cplusplus diff --git a/include/grpcpp/support/callback_common.h b/include/grpcpp/support/callback_common.h index a99a47dbf4d..6ae8cfb946a 100644 --- a/include/grpcpp/support/callback_common.h +++ b/include/grpcpp/support/callback_common.h @@ -207,7 +207,9 @@ class CallbackWithSuccessTag : public grpc_completion_queue_functor { auto* ops = ops_; #endif bool do_callback = ops_->FinalizeResult(&ignored, &ok); +#ifndef NDEBUG GPR_DEBUG_ASSERT(ignored == ops); +#endif if (do_callback) { CatchingCallback(func_, ok); diff --git a/src/core/client_channel/client_channel_filter.cc b/src/core/client_channel/client_channel_filter.cc index 16f94347e4e..b7d4d6d4952 100644 --- a/src/core/client_channel/client_channel_filter.cc +++ b/src/core/client_channel/client_channel_filter.cc @@ -644,7 +644,9 @@ class ClientChannelFilter::SubchannelWrapper final chand, this, subchannel_.get()); } GRPC_CHANNEL_STACK_REF(chand_->owning_stack_, "SubchannelWrapper"); +#ifndef NDEBUG GPR_DEBUG_ASSERT(chand_->work_serializer_->RunningInWorkSerializer()); +#endif if (chand_->channelz_node_ != nullptr) { auto* subchannel_node = subchannel_->channelz_node(); if (subchannel_node != nullptr) { diff --git a/src/core/load_balancing/xds/xds_cluster_impl.cc b/src/core/load_balancing/xds/xds_cluster_impl.cc index ef766148021..acb1454a0b7 100644 --- a/src/core/load_balancing/xds/xds_cluster_impl.cc +++ b/src/core/load_balancing/xds/xds_cluster_impl.cc @@ -14,8 +14,6 @@ // limitations under the License. // -#include - #include #include @@ -36,6 +34,7 @@ #include #include +#include #include "src/core/client_channel/client_channel_internal.h" #include "src/core/ext/xds/xds_bootstrap.h" @@ -328,7 +327,9 @@ class XdsClusterImplLb::Picker::SubchannelCallTracker final ~SubchannelCallTracker() override { locality_stats_.reset(DEBUG_LOCATION, "SubchannelCallTracker"); call_counter_.reset(DEBUG_LOCATION, "SubchannelCallTracker"); +#ifndef NDEBUG GPR_DEBUG_ASSERT(!started_); +#endif } void Start() override {