Skip to content

Commit

Permalink
Make possible to use clang on Windows (clang-cl)
Browse files Browse the repository at this point in the history
-DWITH_ASAN can be used as well now, on x64

Fix many clang-cl warnings.
  • Loading branch information
vaintroub committed Feb 20, 2018
1 parent 9d97e60 commit 56e7b7e
Show file tree
Hide file tree
Showing 75 changed files with 215 additions and 232 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ OPTION(NOT_FOR_DISTRIBUTION "Allow linking with GPLv2-incompatible system librar
INCLUDE(check_compiler_flag)

OPTION(WITH_ASAN "Enable address sanitizer" OFF)
IF (WITH_ASAN)

IF (WITH_ASAN AND NOT MSVC)
# gcc 4.8.1 and new versions of clang
MY_CHECK_AND_SET_COMPILER_FLAG("-fsanitize=address -fPIC"
DEBUG RELWITHDEBINFO)
Expand Down
3 changes: 1 addition & 2 deletions client/mysql.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1709,13 +1709,12 @@ static struct my_option my_long_options[] =

static void usage(int version)
{
#ifdef HAVE_READLINE
#if defined(USE_LIBEDIT_INTERFACE)
const char* readline= "";
#else
const char* readline= "readline";
#endif

#ifdef HAVE_READLINE
printf("%s Ver %s Distrib %s, for %s (%s) using %s %s\n",
my_progname, VER, MYSQL_SERVER_VERSION, SYSTEM_TYPE, MACHINE_TYPE,
readline, rl_library_version);
Expand Down
4 changes: 4 additions & 0 deletions cmake/maintainer.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

IF(MSVC)
RETURN()
ENDIF()

# Common warning flags for GCC, G++, Clang and Clang++
SET(MY_WARNING_FLAGS
-Wall
Expand Down
50 changes: 46 additions & 4 deletions cmake/os/Windows.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,41 @@ IF(MINGW AND CMAKE_SIZEOF_VOID_P EQUAL 4)
ADD_DEFINITIONS(-march=i486)
ENDIF()

FUNCTION(ENABLE_ASAN)
IF(NOT (MSVC AND CMAKE_CXX_COMPILER_ID MATCHES Clang))
MESSAGE(FATAL_ERROR "clang-cl is necessary to enable asan")
ENDIF()
# currently, asan is broken with static CRT.
IF(NOT(MSVC_CRT_TYPE STREQUAL "/MD"))
MESSAGE(FATAL_ERROR "-DWITH_ASAN cmake parameter also requires -DMSVC_CRT_TYPE=/MD")
ENDIF()
IF(CMAKE_SIZEOF_VOID_P EQUAL 4)
MESSAGE(FATAL_ERROR "-DWITH_ASAN on Windows requires 64bit build")
ENDIF()
# After installation, clang lib directory should be added to PATH
# (e.g C:/Program Files/LLVM/lib/clang/5.0.1/lib/windows)
FIND_LIBRARY(CLANG_RT_ASAN_DYNAMIC clang_rt.asan_dynamic-x86_64.lib)
IF(NOT CLANG_RT_ASAN_DYNAMIC)
MESSAGE(FATAL_ERROR "Can't enable ASAN : missing clang_rt.asan_dynamic-x86_64.lib")
ENDIF()

FIND_LIBRARY(CLANG_RT_ASAN_DYNAMIC_THUNK clang_rt.asan_dynamic_runtime_thunk-x86_64.lib)
IF(NOT CLANG_RT_ASAN_DYNAMIC_THUNK)
MESSAGE(FATAL_ERROR "Can't enable ASAN : missing clang_rt.asan_dynamic_runtime_thunk-x86_64.lib")
ENDIF()

STRING(APPEND CMAKE_C_FLAGS " -fsanitize=address")
STRING(APPEND CMAKE_CXX_FLAGS " -fsanitize=address")

LINK_LIBRARIES(${CLANG_RT_ASAN_DYNAMIC} ${CLANG_RT_ASAN_DYNAMIC_THUNK})
ENDFUNCTION()


IF(MSVC)
IF(WITH_ASAN)
ENABLE_ASAN()
ENDIF()

# Disable mingw based pkg-config found in Strawberry perl
SET(PKG_CONFIG_EXECUTABLE 0 CACHE INTERNAL "")
SET(MSVC_CRT_TYPE /MT CACHE STRING
Expand Down Expand Up @@ -119,8 +153,16 @@ IF(MSVC)
STRING(APPEND ${flag} " /Z7")
ENDIF()
ENDFOREACH()



IF(CMAKE_CXX_COMPILER_ID MATCHES Clang)
SET(CLANG_CL_FLAGS
"-Wno-unused-parameter -Wno-unused-command-line-argument -Wno-pointer-sign -Wno-deprecated-register \
-Wno-missing-braces -Wno-unused-function -msse4.2 "
)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CLANG_CL_FLAGS}")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CLANG_CL_FLAGS}")
ENDIF()

# Fix CMake's predefined huge stack size
FOREACH(type EXE SHARED MODULE)
STRING(REGEX REPLACE "/STACK:([^ ]+)" "" CMAKE_${type}_LINKER_FLAGS "${CMAKE_${type}_LINKER_FLAGS}")
Expand All @@ -139,15 +181,15 @@ IF(MSVC)
ENDIF()

# Speed up multiprocessor build
IF (MSVC_VERSION GREATER 1400)
IF (MSVC_VERSION GREATER 1400 AND (NOT CMAKE_CXX_COMPILER_ID MATCHES Clang))
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /MP")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
ENDIF()

#TODO: update the code and remove the disabled warnings
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /we4700 /we4311 /we4477 /we4302 /we4090")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /we4099 /we4700 /we4311 /we4477 /we4302 /we4090")
IF(MSVC_VERSION GREATER 1910)
IF(MSVC_VERSION GREATER 1910 AND (NOT CMAKE_CXX_COMPILER_ID MATCHES Clang))
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /permissive-")
ENDIF()
ADD_DEFINITIONS(-D_CRT_NONSTDC_NO_WARNINGS)
Expand Down
2 changes: 1 addition & 1 deletion configure.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ IF(NOT SYSTEM_TYPE)
ENDIF()
ENDIF()

IF(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
IF(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang" AND (NOT MSVC))
# MySQL "canonical" GCC flags. At least -fno-rtti flag affects
# ABI and cannot be simply removed.
SET(CMAKE_CXX_FLAGS
Expand Down
2 changes: 1 addition & 1 deletion extra/mariabackup/backup_mysql.cc
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ wait_for_no_updates(MYSQL *connection, uint timeout, uint threshold)

static
os_thread_ret_t
kill_query_thread(
DECLARE_THREAD(kill_query_thread)(
/*===============*/
void *arg __attribute__((unused)))
{
Expand Down
9 changes: 5 additions & 4 deletions extra/mariabackup/xtrabackup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,9 @@ it every INNOBASE_WAKE_INTERVAL'th step. */
#define INNOBASE_WAKE_INTERVAL 32
ulong innobase_active_counter = 0;


#ifndef _WIN32
static char *xtrabackup_debug_sync = NULL;
#endif

my_bool xtrabackup_incremental_force_scan = FALSE;

Expand Down Expand Up @@ -2455,7 +2456,7 @@ xtrabackup_copy_logfile(copy_logfile copy)
return(false);
}

static os_thread_ret_t log_copying_thread(void*)
static os_thread_ret_t DECLARE_THREAD(log_copying_thread)(void*)
{
/*
Initialize mysys thread-specific memory so we can
Expand All @@ -2478,7 +2479,7 @@ static os_thread_ret_t log_copying_thread(void*)
}

/* io throttle watching (rough) */
static os_thread_ret_t io_watching_thread(void*)
static os_thread_ret_t DECLARE_THREAD(io_watching_thread)(void*)
{
/* currently, for --backup only */
ut_a(xtrabackup_backup);
Expand All @@ -2504,7 +2505,7 @@ static os_thread_ret_t io_watching_thread(void*)
Datafiles copying thread.*/
static
os_thread_ret_t
data_copy_thread_func(
DECLARE_THREAD(data_copy_thread_func)(
/*==================*/
void *arg) /* thread context */
{
Expand Down
2 changes: 1 addition & 1 deletion extra/perror.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ static my_bool print_win_error_msg(DWORD error, my_bool verbose)
NULL))
{
if (verbose)
printf("Win32 error code %d: %s", error, s);
printf("Win32 error code %lu: %s", error, s);
else
puts(s);
LocalFree(s);
Expand Down
1 change: 0 additions & 1 deletion extra/yassl/src/socket_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
#endif

#ifdef _WIN32
const int SOCKET_EINVAL = WSAEINVAL;
const int SOCKET_EWOULDBLOCK = WSAEWOULDBLOCK;
const int SOCKET_EAGAIN = WSAEWOULDBLOCK;
#else
Expand Down
4 changes: 0 additions & 4 deletions extra/yassl/src/yassl_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -921,10 +921,6 @@ static bool setPrefix(opaque* sha_input, int i)
return true;
}


const char handshake_order[] = "Out of order HandShake Message!";


} // namespcae for locals


Expand Down
4 changes: 2 additions & 2 deletions include/my_attribute.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
compilation warnings.
*/
#ifndef __attribute__
# if !defined(__GNUC__)
# if !defined(__GNUC__) && !defined(__clang__)
# define __attribute__(A)
# else
# elif defined(__GNUC__)
# ifndef GCC_VERSION
# define GCC_VERSION (__GNUC__ * 1000 + __GNUC_MINOR__)
# endif
Expand Down
20 changes: 10 additions & 10 deletions mysql-test/lib/My/SafeProcess/safe_kill_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@ void dump_single_process(DWORD pid)
process= OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pid);
if (!process)
{
fprintf(stderr, "safe_kill : cannot open process pid=%u to create dump, last error %u\n",
fprintf(stderr, "safe_kill : cannot open process pid=%lu to create dump, last error %lu\n",
pid, GetLastError());
goto exit;
}

if (QueryFullProcessImageName(process, 0, path, &size) == 0)
{
fprintf(stderr, "safe_kill : cannot read process path for pid %u, last error %u\n",
fprintf(stderr, "safe_kill : cannot read process path for pid %lu, last error %lu\n",
pid, GetLastError());
goto exit;
}
Expand Down Expand Up @@ -116,17 +116,17 @@ void dump_single_process(DWORD pid)
{
if (!GetTempFileName(".", filename, 0, tmpname))
{
fprintf(stderr, "GetTempFileName failed, last error %u", GetLastError());
fprintf(stderr, "GetTempFileName failed, last error %lu", GetLastError());
goto exit;
}
strncat(tmpname, ".dmp", sizeof(tmpname));
strncat_s(tmpname, ".dmp", sizeof(tmpname));
filename= tmpname;
}


if (!GetCurrentDirectory(MAX_PATH, working_dir))
{
fprintf(stderr, "GetCurrentDirectory failed, last error %u", GetLastError());
fprintf(stderr, "GetCurrentDirectory failed, last error %lu", GetLastError());
goto exit;
}

Expand All @@ -135,14 +135,14 @@ void dump_single_process(DWORD pid)

if (file == INVALID_HANDLE_VALUE)
{
fprintf(stderr, "safe_kill : CreateFile() failed for file %s, working dir %s, last error = %u\n",
fprintf(stderr, "safe_kill : CreateFile() failed for file %s, working dir %s, last error = %lu\n",
filename, working_dir, GetLastError());
goto exit;
}

if (!MiniDumpWriteDump(process, pid, file, MiniDumpNormal, 0, 0, 0))
{
fprintf(stderr, "Failed to write minidump to %s, working dir %s, last error %u\n",
fprintf(stderr, "Failed to write minidump to %s, working dir %s, last error %lu\n",
filename, working_dir, GetLastError());
goto exit;
}
Expand Down Expand Up @@ -214,7 +214,7 @@ int main(int argc, const char** argv )

if (!GetExitCodeProcess(process,&exit_code))
{
fprintf(stderr, "GetExitCodeProcess failed, pid= %d, err= %d\n",
fprintf(stderr, "GetExitCodeProcess failed, pid= %lu, err= %lu\n",
pid, GetLastError());
exit(1);
}
Expand All @@ -232,15 +232,15 @@ int main(int argc, const char** argv )
Sleep(100);
else
{
fprintf(stderr, "Failed to open shutdown_event '%s', error: %d\n",
fprintf(stderr, "Failed to open shutdown_event '%s', error: %lu\n",
safe_process_name, GetLastError());
exit(3);
}
}

if(SetEvent(shutdown_event) == 0)
{
fprintf(stderr, "Failed to signal shutdown_event '%s', error: %d\n",
fprintf(stderr, "Failed to signal shutdown_event '%s', error: %lu\n",
safe_process_name, GetLastError());
CloseHandle(shutdown_event);
exit(4);
Expand Down
10 changes: 5 additions & 5 deletions mysql-test/lib/My/SafeProcess/safe_process_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ static void message(const char* fmt, ...)

static void die(const char* fmt, ...)
{
DWORD last_err= GetLastError();
int last_err= GetLastError();
va_list args;
fprintf(stderr, "%s: FATAL ERROR, ", safe_process_name);
va_start(args, fmt);
Expand Down Expand Up @@ -106,7 +106,7 @@ static void die(const char* fmt, ...)
DWORD get_parent_pid(DWORD pid)
{
HANDLE snapshot;
DWORD parent_pid= -1;
DWORD parent_pid= 0;
PROCESSENTRY32 pe32;
pe32.dwSize= sizeof(PROCESSENTRY32);

Expand All @@ -127,7 +127,7 @@ DWORD get_parent_pid(DWORD pid)
} while(Process32Next( snapshot, &pe32));
CloseHandle(snapshot);

if (parent_pid == -1)
if (parent_pid == 0)
die("Could not find parent pid");

return parent_pid;
Expand Down Expand Up @@ -163,7 +163,7 @@ int main(int argc, const char** argv )
PROCESS_INFORMATION process_info= {0};
BOOL nocore= FALSE;

sprintf(safe_process_name, "safe_process[%d]", pid);
sprintf(safe_process_name, "safe_process[%lu]", pid);

/* Create an event for the signal handler */
if ((shutdown_event=
Expand Down Expand Up @@ -298,7 +298,7 @@ int main(int argc, const char** argv )
BOOL process_created= FALSE;
BOOL jobobject_assigned= FALSE;

for (int i=0; i < sizeof(create_flags)/sizeof(create_flags[0]); i++)
for (size_t i=0; i < sizeof(create_flags)/sizeof(create_flags[0]); i++)
{
process_created= CreateProcess(NULL, (LPSTR)child_args,
NULL,
Expand Down
1 change: 0 additions & 1 deletion mysys/get_password.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ char *get_tty_password(const char *opt_message)
{
char to[80];
char *pos=to,*end=to+sizeof(to)-1;
int i=0;
DBUG_ENTER("get_tty_password");
_cputs(opt_message ? opt_message : "Enter password: ");
for (;;)
Expand Down
2 changes: 1 addition & 1 deletion mysys/my_access.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ int my_access(const char *path, int amode)

attributes = GetFileAttributes(path);
if (attributes == INVALID_FILE_ATTRIBUTES ||
(attributes & FILE_ATTRIBUTE_READONLY) && (amode & W_OK))
((attributes & FILE_ATTRIBUTE_READONLY) && (amode & W_OK)))
{
my_errno= errno= EACCES;
return -1;
Expand Down
4 changes: 2 additions & 2 deletions mysys/my_conio.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ static HANDLE my_coninpfh= 0; /* console input */
static
int my_pthread_auto_mutex_lock(HANDLE* ph, const char* name, int id, int time)
{
int res;
DWORD res;
char tname[FN_REFLEN];

sprintf(tname, "%s-%08X", name, id);
Expand Down Expand Up @@ -203,7 +203,7 @@ char* my_cgets(char *buffer, size_t clen, size_t* plen)
if (*plen > 0 && buffer[*plen - 1] == '\r')
{
char tmp[3];
int tmplen= sizeof(tmp);
DWORD tmplen= (DWORD)sizeof(tmp);

*plen= *plen - 1;
/* read /n left in the buffer */
Expand Down
2 changes: 1 addition & 1 deletion mysys/my_default.c
Original file line number Diff line number Diff line change
Expand Up @@ -1184,7 +1184,7 @@ static const char **init_default_directories(MEM_ROOT *alloc)
{
errors += add_directory(alloc, fname_buffer, dirs);

strncat(fname_buffer, "/data", sizeof(fname_buffer));
strcat_s(fname_buffer, sizeof(fname_buffer), "/data");
errors += add_directory(alloc, fname_buffer, dirs);
}
}
Expand Down
4 changes: 2 additions & 2 deletions mysys/my_delete.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ static int my_win_unlink(const char *name)
{
HANDLE handle= INVALID_HANDLE_VALUE;
DWORD attributes;
DWORD last_error;
uint last_error;
char unique_filename[MAX_PATH + 35];
unsigned long long tsc; /* time stamp counter, for unique filename*/

Expand Down Expand Up @@ -148,7 +148,7 @@ static int my_win_unlink(const char *name)
name, tsc);
if (!MoveFile(name, unique_filename))
{
DBUG_PRINT("warning", ("moving %s to unique filename failed, error %u\n",
DBUG_PRINT("warning", ("moving %s to unique filename failed, error %lu\n",
name,GetLastError()));
}

Expand Down
Loading

0 comments on commit 56e7b7e

Please sign in to comment.