[build] Fix clang warnings in Windows code (#32448)

This fixes the problems identified while building with clang-cl on
Windows, with build arguments `/std:c++14 /W4`

Passes internal checks: cl/511562057

----

We can't yet enable a clang-cl build as part of our continuous
integration tests due to a few issues:

protobuf fails an `unused-parameter` warning check in v4.21 (the current
pinned version) on Windows. The upgrade to v4.22 is evidently painful
and in progress. Without maintaining a patch against protobuf, or
disabling warnings-as-errors somehow for the protobuf code alone, we'll
need to upgrade our dependency before we can automate the clang-cl build
for Windows.

Next, our Windows CI environment does not have clang installed. There
has been some work over the past year to create custom kokoro images,
but that work has apparently stalled after trading hands a few times.
Using our current images, installing clang every time we run the job may
be our best bet (likely from precompiled binaries that we host
ourselves), but it will eat up more CI resources.

Finally, some of the default build configurations are incorrect for
clang-cl. For example `-Wall` in clang-cl translates roughly to
`-Weverything` in clang linux, whereas `-W4` in clang-cl translates more
closely to `-Wall -Wextra`. This configuration in the gRPC bazel build
is not currently platform-specific, it will need to be updated.
Similarly, `-std=c++14` is an unknown argument on Windows (should be
`/std:c++14`), and should not be in the bazelrc. This will likely need
the same platform-specific support.
pull/32467/head
AJ Heller 2 years ago committed by GitHub
parent 3a0632136d
commit 1910986819
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      include/grpc/support/port_platform.h
  2. 8
      src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc
  3. 4
      src/core/lib/gprpp/windows/thd.cc
  4. 2
      src/core/lib/iomgr/endpoint_pair_windows.cc
  5. 2
      src/core/lib/iomgr/iomgr_windows.cc
  6. 18
      src/core/lib/iomgr/pollset_set_windows.cc
  7. 2
      src/core/lib/iomgr/pollset_windows.cc
  8. 4
      src/core/lib/iomgr/tcp_client_windows.cc
  9. 24
      src/core/lib/iomgr/tcp_server_windows.cc
  10. 14
      src/core/lib/iomgr/tcp_windows.cc

@ -625,7 +625,7 @@ typedef unsigned __int64 uint64_t;
#define GPR_ATTRIBUTE_NORETURN
#endif
#if GPR_FORBID_UNREACHABLE_CODE
#if defined(GPR_FORBID_UNREACHABLE_CODE) && GPR_FORBID_UNREACHABLE_CODE
#define GPR_UNREACHABLE_CODE(STATEMENT)
#else
#ifdef __cplusplus

@ -252,7 +252,7 @@ class GrpcPolledFdWindows {
bool IsFdStillReadableLocked() { return read_buf_has_data_; }
void ShutdownLocked(grpc_error_handle error) {
void ShutdownLocked(grpc_error_handle /* error */) {
grpc_winsocket_shutdown(winsocket_);
}
@ -263,7 +263,7 @@ class GrpcPolledFdWindows {
const char* GetName() const { return name_.c_str(); }
ares_ssize_t RecvFrom(WSAErrorContext* wsa_error_ctx, void* data,
ares_socket_t data_len, int flags,
ares_socket_t data_len, int /* flags */,
struct sockaddr* from, ares_socklen_t* from_len) {
GRPC_CARES_TRACE_LOG(
"fd:|%s| RecvFrom called read_buf_has_data:%d Current read buf "
@ -301,7 +301,7 @@ class GrpcPolledFdWindows {
grpc_slice out = GRPC_SLICE_MALLOC(total);
size_t cur = 0;
for (int i = 0; i < iov_count; i++) {
for (int k = 0; k < iov[i].iov_len; k++) {
for (size_t k = 0; k < iov[i].iov_len; k++) {
GRPC_SLICE_START_PTR(out)[cur++] = ((char*)iov[i].iov_base)[k];
}
}
@ -862,7 +862,7 @@ class GrpcPolledFdFactoryWindows : public GrpcPolledFdFactory {
explicit GrpcPolledFdFactoryWindows(Mutex* mu) : sock_to_polled_fd_map_(mu) {}
GrpcPolledFd* NewGrpcPolledFdLocked(
ares_socket_t as, grpc_pollset_set* driver_pollset_set) override {
ares_socket_t as, grpc_pollset_set* /* driver_pollset_set */) override {
GrpcPolledFdWindows* polled_fd = sock_to_polled_fd_map_.LookupPolledFd(as);
// Set a flag so that the virtual socket "close" method knows it
// doesn't need to call ShutdownLocked, since now the driver will.

@ -146,8 +146,8 @@ class ThreadInternalsWindows
namespace grpc_core {
Thread::Thread(const char* thd_name, void (*thd_body)(void* arg), void* arg,
bool* success, const Options& options)
Thread::Thread(const char* /* thd_name */, void (*thd_body)(void* arg),
void* arg, bool* success, const Options& options)
: options_(options) {
bool outcome = false;
impl_ = new ThreadInternalsWindows(thd_body, arg, &outcome, options);

@ -80,7 +80,7 @@ static void create_sockets(SOCKET sv[2]) {
}
grpc_endpoint_pair grpc_iomgr_create_endpoint_pair(
const char*, grpc_channel_args* channel_args) {
const char*, grpc_channel_args* /* channel_args */) {
SOCKET sv[2];
grpc_endpoint_pair p;
create_sockets(sv);

@ -81,7 +81,7 @@ static bool iomgr_platform_is_any_background_poller_thread(void) {
}
static bool iomgr_platform_add_closure_to_background_poller(
grpc_closure* closure, grpc_error_handle error) {
grpc_closure* /* closure */, grpc_error_handle /* error */) {
return false;
}

@ -30,19 +30,19 @@ static grpc_pollset_set* pollset_set_create(void) {
return (grpc_pollset_set*)((intptr_t)0xdeafbeef);
}
static void pollset_set_destroy(grpc_pollset_set* pollset_set) {}
static void pollset_set_destroy(grpc_pollset_set* /* pollset_set */) {}
static void pollset_set_add_pollset(grpc_pollset_set* pollset_set,
grpc_pollset* pollset) {}
static void pollset_set_add_pollset(grpc_pollset_set* /* pollset_set */,
grpc_pollset* /* pollset */) {}
static void pollset_set_del_pollset(grpc_pollset_set* pollset_set,
grpc_pollset* pollset) {}
static void pollset_set_del_pollset(grpc_pollset_set* /* pollset_set */,
grpc_pollset* /* pollset */) {}
static void pollset_set_add_pollset_set(grpc_pollset_set* bag,
grpc_pollset_set* item) {}
static void pollset_set_add_pollset_set(grpc_pollset_set* /* bag */,
grpc_pollset_set* /* item */) {}
static void pollset_set_del_pollset_set(grpc_pollset_set* bag,
grpc_pollset_set* item) {}
static void pollset_set_del_pollset_set(grpc_pollset_set* /* bag */,
grpc_pollset_set* /* item */) {}
grpc_pollset_set_vtable grpc_windows_pollset_set_vtable = {
pollset_set_create, pollset_set_destroy,

@ -105,7 +105,7 @@ static void pollset_shutdown(grpc_pollset* pollset, grpc_closure* closure) {
}
}
static void pollset_destroy(grpc_pollset* pollset) {}
static void pollset_destroy(grpc_pollset* /* pollset */) {}
static grpc_error_handle pollset_work(grpc_pollset* pollset,
grpc_pollset_worker** worker_hdl,

@ -69,7 +69,7 @@ static void async_connect_unlock_and_cleanup(async_connect* ac,
if (socket != NULL) grpc_winsocket_destroy(socket);
}
static void on_alarm(void* acp, grpc_error_handle error) {
static void on_alarm(void* acp, grpc_error_handle /* error */) {
async_connect* ac = (async_connect*)acp;
gpr_mu_lock(&ac->mu);
grpc_winsocket* socket = ac->socket;
@ -124,7 +124,7 @@ static void on_connect(void* acp, grpc_error_handle error) {
// Tries to issue one async connection, then schedules both an IOCP
// notification request for the connection, and one timeout alert.
static int64_t tcp_connect(grpc_closure* on_done, grpc_endpoint** endpoint,
grpc_pollset_set* interested_parties,
grpc_pollset_set* /* interested_parties */,
const EndpointConfig& config,
const grpc_resolved_address* addr,
grpc_core::Timestamp deadline) {

@ -103,7 +103,7 @@ struct grpc_tcp_server {
// Public function. Allocates the proper data structures to hold a
// grpc_tcp_server.
static grpc_error_handle tcp_server_create(grpc_closure* shutdown_complete,
const EndpointConfig& config,
const EndpointConfig& /* config */,
grpc_tcp_server_cb on_accept_cb,
void* on_accept_cb_arg,
grpc_tcp_server** server) {
@ -122,7 +122,7 @@ static grpc_error_handle tcp_server_create(grpc_closure* shutdown_complete,
return absl::OkStatus();
}
static void destroy_server(void* arg, grpc_error_handle error) {
static void destroy_server(void* arg, grpc_error_handle /* error */) {
grpc_tcp_server* s = (grpc_tcp_server*)arg;
// Now that the accepts have been aborted, we can destroy the sockets.
@ -533,27 +533,33 @@ static void tcp_server_start(grpc_tcp_server* s,
gpr_mu_unlock(&s->mu);
}
static unsigned tcp_server_port_fd_count(grpc_tcp_server* s,
unsigned port_index) {
static unsigned tcp_server_port_fd_count(grpc_tcp_server* /* s */,
unsigned /* port_index */) {
return 0;
}
static int tcp_server_port_fd(grpc_tcp_server* s, unsigned port_index,
unsigned fd_index) {
static int tcp_server_port_fd(grpc_tcp_server* /* s */,
unsigned /* port_index */,
unsigned /* fd_index */) {
return -1;
}
static grpc_core::TcpServerFdHandler* tcp_server_create_fd_handler(
grpc_tcp_server* s) {
grpc_tcp_server* /* s */) {
return nullptr;
}
static void tcp_server_shutdown_listeners(grpc_tcp_server* s) {}
static void tcp_server_shutdown_listeners(grpc_tcp_server* /* s */) {}
static int tcp_pre_allocated_fd(grpc_tcp_server* /* s */) { return -1; }
static void tcp_set_pre_allocated_fd(grpc_tcp_server* /* s */, int /* fd */) {}
grpc_tcp_server_vtable grpc_windows_tcp_server_vtable = {
tcp_server_create, tcp_server_start,
tcp_server_add_port, tcp_server_create_fd_handler,
tcp_server_port_fd_count, tcp_server_port_fd,
tcp_server_ref, tcp_server_shutdown_starting_add,
tcp_server_unref, tcp_server_shutdown_listeners};
tcp_server_unref, tcp_server_shutdown_listeners,
tcp_pre_allocated_fd, tcp_set_pre_allocated_fd};
#endif // GRPC_WINSOCK_SOCKET

@ -237,7 +237,8 @@ static void on_read(void* tcpp, grpc_error_handle error) {
#define DEFAULT_TARGET_READ_SIZE 8192
#define MAX_WSABUF_COUNT 16
static void win_read(grpc_endpoint* ep, grpc_slice_buffer* read_slices,
grpc_closure* cb, bool urgent, int /*min_progress_size*/) {
grpc_closure* cb, bool /* urgent */,
int /* min_progress_size */) {
grpc_tcp* tcp = (grpc_tcp*)ep;
grpc_winsocket* handle = tcp->socket;
grpc_winsocket_callback_info* info = &handle->read_info;
@ -342,7 +343,8 @@ static void on_write(void* tcpp, grpc_error_handle error) {
// Initiates a write.
static void win_write(grpc_endpoint* ep, grpc_slice_buffer* slices,
grpc_closure* cb, void* arg, int /*max_frame_size*/) {
grpc_closure* cb, void* /* arg */,
int /* max_frame_size */) {
grpc_tcp* tcp = (grpc_tcp*)ep;
grpc_winsocket* socket = tcp->socket;
grpc_winsocket_callback_info* info = &socket->write_info;
@ -468,8 +470,8 @@ static void win_add_to_pollset_set(grpc_endpoint* ep, grpc_pollset_set* pss) {
grpc_iocp_add_socket(tcp->socket);
}
static void win_delete_from_pollset_set(grpc_endpoint* ep,
grpc_pollset_set* pss) {}
static void win_delete_from_pollset_set(grpc_endpoint* /* ep */,
grpc_pollset_set* /* pss */) {}
// Initiates a shutdown of the TCP endpoint. This will queue abort callbacks
// for the potential read and write operations. It is up to the caller to
@ -506,9 +508,9 @@ static absl::string_view win_get_local_address(grpc_endpoint* ep) {
return tcp->local_address;
}
static int win_get_fd(grpc_endpoint* ep) { return -1; }
static int win_get_fd(grpc_endpoint* /* ep */) { return -1; }
static bool win_can_track_err(grpc_endpoint* ep) { return false; }
static bool win_can_track_err(grpc_endpoint* /* ep */) { return false; }
static grpc_endpoint_vtable vtable = {win_read,
win_write,

Loading…
Cancel
Save