Skip to content

Commit 321eb98

Browse files
author
Tor Didriksen
committed
Bug#35599871 Compile MySQL with clang 16
Fix Clang 16 warnings, most of them windows specific: Silence -Wno-microsoft-template warning. Silence -Wno-deprecated-non-prototype for SunRPC code. Fix a couple of -Wunused-but-set-variable warnings. These are also visible with Clang 16 in RelWithDebInfo mode on Linux. mysql_routing.h fix -Wdeprecated-copy-with-user-provided-dtor Work around pragma push/pop error. Use __has_trivial_constructor for Visual studio only, not for clang. Silence some more warnings in 3rd party libevent code. Change-Id: Ie56452e183633df403d5f3cadf3cc458d849b2f3
1 parent 6629e54 commit 321eb98

File tree

12 files changed

+53
-12
lines changed

12 files changed

+53
-12
lines changed

client/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,13 @@ SET(MYSQLBINLOG_SOURCES
240240
${CMAKE_SOURCE_DIR}/sql/rpl_log_encryption.cc
241241
)
242242

243+
# duplicate explicit instantiation of 'net_field_length_checked'
244+
# ignored as a Microsoft extension
245+
IF(WIN32_CLANG)
246+
ADD_COMPILE_FLAGS(${CMAKE_SOURCE_DIR}/sql/log_event.cc
247+
COMPILE_FLAGS " -Wno-microsoft-template")
248+
ENDIF()
249+
243250
SET(MYSQLBINLOG_LIBRARIES
244251
mysql_binlog_event
245252
client_base

extra/libevent/libevent-2.1.11-stable/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ ENDIF()
4343
IF(WIN32_CLANG)
4444
STRING_APPEND(CMAKE_C_FLAGS " -Wno-assign-enum")
4545
STRING_APPEND(CMAKE_C_FLAGS " -Wno-cast-align")
46+
STRING_APPEND(CMAKE_C_FLAGS " -Wno-cast-function-type")
47+
STRING_APPEND(CMAKE_C_FLAGS " -Wno-cast-function-type-strict")
4648
STRING_APPEND(CMAKE_C_FLAGS " -Wno-cast-qual")
4749
STRING_APPEND(CMAKE_C_FLAGS " -Wno-covered-switch-default")
4850
STRING_APPEND(CMAKE_C_FLAGS " -Wno-disabled-macro-expansion")
@@ -64,8 +66,12 @@ IF(WIN32_CLANG)
6466
STRING_APPEND(CMAKE_C_FLAGS " -Wno-shadow")
6567
STRING_APPEND(CMAKE_C_FLAGS " -Wno-sign-conversion")
6668
STRING_APPEND(CMAKE_C_FLAGS " -Wno-shorten-64-to-32")
69+
STRING_APPEND(CMAKE_C_FLAGS " -Wno-strict-prototypes")
6770
STRING_APPEND(CMAKE_C_FLAGS " -Wno-switch-enum")
71+
STRING_APPEND(CMAKE_C_FLAGS " -Wno-unreachable-code-fallthrough")
6872
STRING_APPEND(CMAKE_C_FLAGS " -Wno-unreachable-code-return")
73+
STRING_APPEND(CMAKE_C_FLAGS " -Wno-unsafe-buffer-usage")
74+
STRING_APPEND(CMAKE_C_FLAGS " -Wno-unused-but-set-variable")
6975
STRING_APPEND(CMAKE_C_FLAGS " -Wno-unused-macros")
7076
ENDIF()
7177

plugin/group_replication/libmysqlgcs/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,13 @@ IF(MSVC)
173173
COMPILE_FLAGS
174174
"-Wno-unused-function"
175175
)
176+
# clang has this, but clang++ does not.
177+
MY_CHECK_C_COMPILER_FLAG("-Wdeprecated-non-prototype"
178+
HAS_DEPRECATED_NON_PROTOTYPE)
179+
IF(HAS_DEPRECATED_NON_PROTOTYPE)
180+
ADD_COMPILE_FLAGS(${XCOM_SUNRPC_SOURCES} ${XCOM_RPCGEN_SOURCES}
181+
COMPILE_FLAGS "-Wno-deprecated-non-prototype")
182+
ENDIF()
176183
ELSE()
177184
ADD_COMPILE_FLAGS(${XCOM_SUNRPC_SOURCES} ${XCOM_RPCGEN_SOURCES}
178185
COMPILE_FLAGS "/wd4018")

plugin/group_replication/libmysqlgcs/cmake/rpcgen.cmake

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,16 @@ IF(WIN32)
4141
${XCOM_BASEDIR}/windeps/sunrpc/xdr.c
4242
)
4343

44+
IF(WIN32_CLANG)
45+
# clang has this, but clang++ does not.
46+
MY_CHECK_C_COMPILER_FLAG("-Wdeprecated-non-prototype"
47+
HAS_DEPRECATED_NON_PROTOTYPE)
48+
IF(HAS_DEPRECATED_NON_PROTOTYPE)
49+
ADD_COMPILE_FLAGS(${SUNRPC_SRCS}
50+
COMPILE_FLAGS "-Wno-deprecated-non-prototype")
51+
ENDIF()
52+
ENDIF()
53+
4454
# /wd4311 'type cast': pointer truncation from 'const caddr_t' to 'u_long'
4555
# /wd4312 'type cast': conversion from 'long' to 'void *' of greater size
4656
ADD_COMPILE_FLAGS(

plugin/group_replication/src/plugin_variables/recovery_endpoints.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ int Recovery_endpoints::local_interfaces_ips(std::set<std::string> &local_ips) {
122122
DBUG_TRACE;
123123

124124
ULONG flags = GAA_FLAG_INCLUDE_PREFIX, family = AF_UNSPEC, out_buflen = 0;
125-
DWORD retval = 0;
126125
PIP_ADAPTER_ADDRESSES addresses;
127126
PIP_ADAPTER_ADDRESSES curr_addresses;
128127

@@ -133,7 +132,7 @@ int Recovery_endpoints::local_interfaces_ips(std::set<std::string> &local_ips) {
133132
return 1;
134133
}
135134

136-
retval = GetAdaptersAddresses(family, flags, nullptr, addresses, &out_buflen);
135+
GetAdaptersAddresses(family, flags, nullptr, addresses, &out_buflen);
137136

138137
curr_addresses = addresses;
139138

router/src/mock_server/src/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ SET(MOCK_SERVER_HTTP_CLIENT_SRCS
6161
mock_server_rest_client.cc)
6262

6363
# disable compiler warnings in duktape
64+
MY_CHECK_CXX_COMPILER_WARNING("-Wunused-but-set-variable" HAS_WARN_FLAG)
65+
IF(HAS_WARN_FLAG)
66+
ADD_COMPILE_FLAGS(${DUKTAPE_SRCS} COMPILE_FLAGS "${HAS_WARN_FLAG}")
67+
ENDIF()
68+
6469
MY_CHECK_CXX_COMPILER_WARNING("-Wunused-function" HAS_WARN_FLAG)
6570
IF(HAS_WARN_FLAG)
6671
ADD_COMPILE_FLAGS(${DUKTAPE_SRCS} COMPILE_FLAGS "${HAS_WARN_FLAG}")

router/src/routing/src/mysql_routing.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ class ROUTING_EXPORT AcceptingEndpoint {
9595
const std::string &parent_routing_name)
9696
: io_ctx_(io_ctx), parent_routing_name_(parent_routing_name) {}
9797

98+
AcceptingEndpoint(const AcceptingEndpoint &) = delete;
99+
98100
virtual stdx::expected<void, std::error_code> setup() = 0;
99101
virtual stdx::expected<void, std::error_code> cancel() = 0;
100102
virtual bool is_open() const = 0;

sql-common/client.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ static HANDLE create_shared_memory(MYSQL *mysql, NET *net,
514514
HANDLE handle_file_map = NULL;
515515
HANDLE connect_named_mutex = NULL;
516516
ulong connect_number;
517-
char connect_number_char[22], *p;
517+
char connect_number_char[22];
518518
char *tmp = NULL;
519519
char *suffix_pos = NULL;
520520
DWORD error_allow = 0;
@@ -612,7 +612,7 @@ static HANDLE create_shared_memory(MYSQL *mysql, NET *net,
612612
CloseHandle(connect_named_mutex);
613613
connect_named_mutex = NULL;
614614

615-
p = longlong10_to_str(connect_number, connect_number_char, 10);
615+
longlong10_to_str(connect_number, connect_number_char, 10);
616616

617617
/*
618618
The name of event and file-mapping events create agree next rule:

sql/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,6 +1107,7 @@ IF(WIN32)
11071107
ADD_COMPILE_FLAGS(mysqld.cc COMPILE_FLAGS "/wd4251")
11081108
IF(WIN32_CLANG)
11091109
ADD_COMPILE_FLAGS(mysqld.cc COMPILE_FLAGS " -Wno-microsoft-cast")
1110+
ADD_COMPILE_FLAGS(log_event.cc COMPILE_FLAGS " -Wno-microsoft-template")
11101111
ENDIF()
11111112
ENDIF()
11121113

sql/gis/transform_functor.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,20 @@
3737

3838
#include "my_compiler.h"
3939

40+
// Clang 16 on windows gives warning:
41+
// pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
42+
// So there must be some mismatching push/pop in boost
43+
#if !defined(__clang__) || !defined(_WIN32)
4044
MY_COMPILER_DIAGNOSTIC_PUSH()
4145
MY_COMPILER_GCC_DIAGNOSTIC_IGNORE("-Wmaybe-uninitialized")
46+
#endif
47+
4248
#include <boost/geometry.hpp>
4349
#include <boost/geometry/srs/transformation.hpp>
50+
51+
#if !defined(__clang__) || !defined(_WIN32)
4452
MY_COMPILER_DIAGNOSTIC_POP()
53+
#endif
4554

4655
#include "sql/gis/functor.h"
4756
#include "sql/gis/geometries.h"

sql/iterators/composite_iterators.cc

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2315,9 +2315,7 @@ bool materialize_iterator::SpillState::initialize_first_HF_chunk_files() {
23152315
/// later retrieve all rows belonging to each file set by scanning only a
23162316
/// section of each chunk file.
23172317
bool materialize_iterator::SpillState::spread_hash_map_to_HF_chunk_files() {
2318-
size_t total = 0;
23192318
for (size_t set = 0; set < m_no_of_chunk_file_sets; set++) {
2320-
size_t rows_visited = 0;
23212319
for (auto f = m_hash_map->begin(); f != m_hash_map->end(); f++) {
23222320
LinkedImmutableString row_with_same_hash = f->second;
23232321
while (row_with_same_hash != nullptr) {
@@ -2326,7 +2324,6 @@ bool materialize_iterator::SpillState::spread_hash_map_to_HF_chunk_files() {
23262324
if (StoreFromTableBuffers(m_table_collection, &m_row_buffer)) {
23272325
return true;
23282326
}
2329-
rows_visited++;
23302327
// Hash row's content with tertiary hash to determine its chunk index,
23312328
// and write it if its set index equals the current set. This way,
23322329
// all rows belonging to a set are stored consecutively, and sets in
@@ -2346,8 +2343,6 @@ bool materialize_iterator::SpillState::spread_hash_map_to_HF_chunk_files() {
23462343
my_error(ER_TEMP_FILE_WRITE_FAILURE, MYF(0));
23472344
return true;
23482345
}
2349-
2350-
total++;
23512346
}
23522347
row_with_same_hash = row_with_same_hash.Decode().next;
23532348
}
@@ -2520,10 +2515,8 @@ bool materialize_iterator::SpillState::save_operand_to_IF_chunk_files(
25202515
}
25212516

25222517
/// Rewind all IF chunk files and possibly REMAININGINPUT.
2523-
size_t offset = 0;
25242518
for (auto &chunk : m_chunk_files) {
25252519
if (chunk.probe_chunk.Rewind()) return true;
2526-
offset++;
25272520
}
25282521

25292522
return m_no_of_chunk_file_sets > 1 && m_remaining_input.Rewind();

storage/ndb/include/ndb_global.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,9 @@ extern "C" {
182182

183183
#define NDB_ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
184184

185-
#if defined(_WIN32) && (_MSC_VER > 1500)
185+
// clang fails with -Wdeprecated-builtins
186+
// __has_trivial_constructor is deprecated, use __is_trivially_constructible
187+
#if defined(_WIN32) && (_MSC_VER > 1500) && !defined(__clang__)
186188
#define HAVE___HAS_TRIVIAL_CONSTRUCTOR
187189
#define HAVE___IS_POD
188190
#endif

0 commit comments

Comments
 (0)