Skip to content
This repository was archived by the owner on Mar 1, 2026. It is now read-only.

Commit 29caef0

Browse files
author
Tor Didriksen
committed
Bug #34114909 Fix compiler warnings from clang on Windows [noclose]
There are lots of compiler warnings when building with clang on Windows. Fix the code, or silence the warnings. With this patch the targets mysqld, plugin_all and component_all build with no warnings with clang 12.0.1 in RelWithDebInfo mode. Silence warnings in 3rd party code: extra/libfido2 test/spb_test_mms.c SunRPC library and generated sources. Several source files (e.g. autorejoin.cc) have functions tagged with [[noreturn]], based on the last thing they do is my_thread_exit(). Ignore the warning in mysys/my_thread.cc rather than changing the signatures of all the [[noreturn]] functions. Fix warnings in our own code: poll.cc -Wsign-compare plugin.cc -Wunused-parameter -Wcast-qual -Wmissing-field-initializers user_map.cc -Wreorder-ctor sspi_authentication_client.cc -Wmissing-braces -Wcast-qual -Wunused-variable xcom_network_provider_native_lib.cc -Wunused-value sock_probe_win32.h -Wunused-parameter -Wshadow -Wunused-variable task.cc -Wunused-parameter -Wsign-compare xcom_base.cc -Wunused-parameter my_xp_mutex.cc -Wunused-parameter recovery_endpoints.cc -Wunused-variable Change-Id: I136d7138eb34e298690f535442d1ad073e45ebee
1 parent 0e65021 commit 29caef0

11 files changed

Lines changed: 52 additions & 30 deletions

File tree

‎extra/libfido2/libfido2-1.8.0/CMakeLists.txt‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,13 @@ if(CYGWIN OR MSYS)
5353
endif()
5454

5555
if(WIN32)
56+
IF(WIN32_CLANG)
57+
add_definitions(-DWIN32_LEAN_AND_MEAN)
58+
STRING_APPEND(CMAKE_C_FLAGS
59+
" -Wno-tautological-constant-out-of-range-compare")
60+
ELSE()
5661
add_definitions(-DWIN32_LEAN_AND_MEAN -D_WIN32_WINNT=0x0600)
62+
ENDIF()
5763
endif()
5864

5965
if(APPLE)

‎include/my_thread.h‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,7 @@ int my_thread_create(my_thread_handle *thread, const my_thread_attr_t *attr,
163163
int my_thread_join(my_thread_handle *thread, void **value_ptr);
164164
int my_thread_cancel(my_thread_handle *thread);
165165

166-
// _endthreadex(_ReturnCode) is not tagged with noreturn.
167-
#ifndef _WIN32
168-
[[noreturn]]
169-
#endif
170-
void my_thread_exit(void *value_ptr);
166+
[[noreturn]] void my_thread_exit(void *value_ptr);
171167

172168
/** Sets the name of the thread for system and debugger, if possible.
173169
@param name Name to set, must be shorter than SETNAME_MAX_LENGTH, including NULL

‎libmysql/authentication_kerberos/sspi_authentication_client.cc‎

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ Sspi_client::Sspi_client(const std::string &spn, MYSQL_PLUGIN_VIO *vio,
4646
m_kdc_host{kdc_host} {}
4747

4848
bool Sspi_client::obtain_store_credentials() {
49-
bool ret_val{false};
50-
TimeStamp ticket_validy_time{0, 0};
49+
TimeStamp ticket_validy_time{{0, 0}};
5150
SECURITY_STATUS sspi_status{0};
5251
/*
5352
Package name as described in:
@@ -72,24 +71,28 @@ bool Sspi_client::obtain_store_credentials() {
7271
"Sspi obtain and store TGT: Plug-in is trying to obtain tickets using "
7372
"user name and password.");
7473
if (!m_kdc_host.empty()) {
75-
identity.Domain = (unsigned char *)(m_kdc_host.c_str());
74+
identity.Domain = reinterpret_cast<unsigned char *>(
75+
const_cast<char *>(m_kdc_host.c_str()));
7676
identity.DomainLength = m_kdc_host.length();
7777
}
7878
if (!m_upn.empty()) {
79-
identity.User = (unsigned char *)(m_upn.c_str());
79+
identity.User =
80+
reinterpret_cast<unsigned char *>(const_cast<char *>(m_upn.c_str()));
8081
identity.UserLength = m_upn.length();
8182
}
8283
if (!m_password.empty()) {
83-
identity.Password = (unsigned char *)(m_password.c_str());
84+
identity.Password = reinterpret_cast<unsigned char *>(
85+
const_cast<char *>(m_password.c_str()));
8486
identity.PasswordLength = m_password.length();
8587
}
8688
identity.Flags = SEC_WINNT_AUTH_IDENTITY_ANSI;
8789
}
8890

8991
sspi_status = AcquireCredentialsHandle(
90-
m_password.empty() ? nullptr : (LPSTR)m_upn.c_str(), mechanism,
91-
SECPKG_CRED_BOTH, nullptr, m_password.empty() ? nullptr : &identity,
92-
nullptr, nullptr, &m_cred, &ticket_validy_time);
92+
m_password.empty() ? nullptr : const_cast<char *>(m_upn.c_str()),
93+
mechanism, SECPKG_CRED_BOTH, nullptr,
94+
m_password.empty() ? nullptr : &identity, nullptr, nullptr, &m_cred,
95+
&ticket_validy_time);
9396

9497
/*
9598
If the AcquireCredentialsHandle succeeds, the AcquireCredentialsHandle
@@ -134,7 +137,7 @@ bool Sspi_client::authenticate() {
134137
Kerberos_client_io client_io{m_vio};
135138
CtxtHandle context;
136139
ULONG attribs{0};
137-
TimeStamp ticket_validy_time{0, 0};
140+
TimeStamp ticket_validy_time{{0, 0}};
138141
SECURITY_STATUS sspi_status{SEC_E_LOGON_DENIED};
139142
SecBufferDesc input_buf_desc;
140143
SecBuffer input_buf;
@@ -171,9 +174,10 @@ bool Sspi_client::authenticate() {
171174
*/
172175
sspi_status = InitializeSecurityContext(
173176
&m_cred, SecIsValidHandle(&context) ? &context : nullptr,
174-
(SEC_CHAR *)m_service_principal.c_str(), ISC_REQ_ALLOCATE_MEMORY, 0,
175-
SECURITY_NATIVE_DREP, input_buf.cbBuffer ? &input_buf_desc : nullptr, 0,
176-
&context, &output_buf_desc, &attribs, &ticket_validy_time);
177+
const_cast<char *>(m_service_principal.c_str()),
178+
ISC_REQ_ALLOCATE_MEMORY, 0, SECURITY_NATIVE_DREP,
179+
input_buf.cbBuffer ? &input_buf_desc : nullptr, 0, &context,
180+
&output_buf_desc, &attribs, &ticket_validy_time);
177181

178182
if (!succeeded(sspi_status)) {
179183
log_client_sspi_error(sspi_status,
@@ -240,4 +244,4 @@ I_Kerberos_client *I_Kerberos_client::create(const std::string &spn,
240244
const std::string &kdc_host) {
241245
Sspi_client *client = new Sspi_client(spn, vio, upn, password, kdc_host);
242246
return static_cast<I_Kerberos_client *>(client);
243-
}
247+
}

‎mysys/my_thread.cc‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,13 +154,21 @@ int my_thread_cancel(my_thread_handle *thread) {
154154
#endif
155155
}
156156

157+
// _endthreadex(_ReturnCode) is not tagged with noreturn.
158+
#ifdef _WIN32
159+
MY_COMPILER_DIAGNOSTIC_PUSH()
160+
MY_COMPILER_CLANG_DIAGNOSTIC_IGNORE("-Winvalid-noreturn")
161+
#endif
157162
void my_thread_exit(void *value_ptr [[maybe_unused]]) {
158163
#ifndef _WIN32
159164
pthread_exit(value_ptr);
160165
#else
161166
_endthreadex(0);
162167
#endif
163168
}
169+
#ifdef _WIN32
170+
MY_COMPILER_DIAGNOSTIC_POP()
171+
#endif
164172

165173
/**
166174
Maximum name length used for my_thread_self_setname(),

‎plugin/group_replication/libmysqlgcs/CMakeLists.txt‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,19 @@ IF(MSVC)
161161
# Compiler warning C4018.
162162
IF(WIN32_CLANG)
163163
ADD_COMPILE_FLAGS(${XCOM_SUNRPC_SOURCES} ${XCOM_RPCGEN_SOURCES}
164-
COMPILE_FLAGS "-Wno-sign-compare")
164+
COMPILE_FLAGS
165+
"-Wno-int-to-void-pointer-cast"
166+
"-Wno-pointer-to-int-cast"
167+
"-Wno-sign-compare"
168+
"-Wno-unused-parameter"
169+
"-Wno-unused-variable"
170+
)
171+
ADD_COMPILE_FLAGS(
172+
src/bindings/xcom/xcom/xcom_base.cc
173+
src/bindings/xcom/xcom/sock_probe.cc
174+
COMPILE_FLAGS
175+
"-Wno-unused-function"
176+
)
165177
ELSE()
166178
ADD_COMPILE_FLAGS(${XCOM_SUNRPC_SOURCES} ${XCOM_RPCGEN_SOURCES}
167179
COMPILE_FLAGS "/wd4018")

‎plugin/group_replication/libmysqlgcs/src/bindings/xcom/xcom/network/xcom_network_provider_native_lib.cc‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -299,9 +299,7 @@ void Xcom_network_provider_library::gcs_shutdown_socket(int *sock) {
299299
&dwBytesReturned, nullptr, nullptr);
300300
}
301301
if (DisconnectEx != nullptr) {
302-
(DisconnectEx(*sock, (LPOVERLAPPED) nullptr, (DWORD)0, (DWORD)0) == TRUE)
303-
? 0
304-
: -1;
302+
DisconnectEx(*sock, (LPOVERLAPPED) nullptr, (DWORD)0, (DWORD)0);
305303
} else {
306304
shutdown(*sock, SOCK_SHUT_RDWR);
307305
}

‎plugin/group_replication/libmysqlgcs/src/bindings/xcom/xcom/sock_probe_win32.h‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ static int number_of_interfaces(sock_probe *s) {
135135
}
136136

137137
/* Return TRUE if interface #count is running. */
138-
static bool_t is_if_running(sock_probe *s, int count) {
138+
static bool_t is_if_running(sock_probe *s, int /* count */) {
139139
if (s == NULL) {
140140
return 0;
141141
}
@@ -194,7 +194,6 @@ static interface_info get_interface(sock_probe *s, int count) {
194194
*/
195195
static void get_sockaddr(sock_probe *s, int count, struct sockaddr **out,
196196
SockaddrOp addr_operation) {
197-
int i = 0;
198197
interface_info interface_info;
199198

200199
if (s == NULL) {

‎plugin/group_replication/libmysqlgcs/src/bindings/xcom/xcom/task.cc‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ double task_now() {
322322
}
323323

324324
#ifdef _WIN32
325-
int gettimeofday(struct timeval *tp, struct timezone *tzp) {
325+
int gettimeofday(struct timeval *tp, struct timezone *) {
326326
static uint64_t const EPOCH = ((uint64_t)116444736000000000ULL);
327327

328328
SYSTEMTIME system_time;
@@ -864,7 +864,7 @@ void remove_and_wakeup(int fd) {
864864
u_int i = 0;
865865
IFDBG(D_NONE, FN; NDBG(fd, d));
866866
while (i < iot.nwait) {
867-
if (get_pollfd(&iot.fd, i).fd == fd) {
867+
if (static_cast<int>(get_pollfd(&iot.fd, i).fd) == fd) {
868868
poll_wakeup(i);
869869
} else {
870870
i++;

‎plugin/group_replication/libmysqlgcs/src/bindings/xcom/xcom/xcom_base.cc‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ static int ignoresig(int signum) {
714714
}
715715
#else
716716
#define SIGPIPE 0
717-
static int ignoresig(int signum) { return 0; }
717+
static int ignoresig(int) { return 0; }
718718
#endif
719719

720720
static int recently_active(pax_machine *p) {

‎plugin/group_replication/libmysqlgcs/src/interface/xplatform/my_xp_mutex.cc‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ int My_xp_mutex_server::trylock() { return mysql_mutex_trylock(m_mutex); }
4646
int My_xp_mutex_server::unlock() { return mysql_mutex_unlock(m_mutex); }
4747
#endif
4848

49-
int My_xp_mutex_util::attr_init(native_mutexattr_t *attr) {
49+
int My_xp_mutex_util::attr_init(native_mutexattr_t *attr [[maybe_unused]]) {
5050
/*
5151
On Windows there is no initialization of mutex attributes.
5252
Therefore, we simply return 0.
@@ -58,7 +58,7 @@ int My_xp_mutex_util::attr_init(native_mutexattr_t *attr) {
5858
#endif
5959
}
6060

61-
int My_xp_mutex_util::attr_destroy(native_mutexattr_t *attr) {
61+
int My_xp_mutex_util::attr_destroy(native_mutexattr_t *attr [[maybe_unused]]) {
6262
/*
6363
On Windows there is no destruction of mutex attributes.
6464
Therefore, we simply return 0.

0 commit comments

Comments
 (0)