Skip to content

Commit

Permalink
Bug#21951420: FIX COMPILATION WARNINGS REPORTED BY -WUNDEF
Browse files Browse the repository at this point in the history
This patch fixes compilation warnings reported by the -Wundef
GCC/clang compilation warning option. -Wundef warns if an
undefined identifier is evaluated in an #if check.

This was a problem because we in several cases tried to
use symbols in #if checks that are not yet defined when
the preprocessor is executed. Such code is at best misleading.
  • Loading branch information
jhauglid committed Nov 4, 2015

Verified

This commit was signed with the committer’s verified signature.
swegener Sven Wegener
1 parent d0ebebc commit f7c2f37
Showing 33 changed files with 147 additions and 185 deletions.
26 changes: 17 additions & 9 deletions client/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -85,22 +85,30 @@ ENDIF()
# Do not build library unless it is needed by some other target.
SET_PROPERTY(TARGET boost_lib PROPERTY EXCLUDE_FROM_ALL TRUE)

# Files that use Boost sources that trigger compilation warnings
SET(MYSQLCLIENT_BOOST_SOURCES
${BOOST_SOURCES_DIR}/libs/thread/src/pthread/once.cpp
${BOOST_SOURCES_DIR}/libs/thread/src/pthread/thread.cpp
)

# Boost source has logical && with non-zero constant
MY_CHECK_CXX_COMPILER_FLAG("-Wlogical-op" HAVE_LOGICAL_OP)
IF(HAVE_LOGICAL_OP)
ADD_COMPILE_FLAGS(
${BOOST_SOURCES_DIR}/libs/thread/src/pthread/thread.cpp
COMPILE_FLAGS "-Wno-logical-op"
)
ADD_COMPILE_FLAGS(${MYSQLCLIENT_BOOST_SOURCES}
COMPILE_FLAGS "-Wno-logical-op")
ENDIF()

# Boost source has unused local typedefs.
MY_CHECK_CXX_COMPILER_FLAG("-Wunused-local-typedefs" HAVE_UNUSED_TYPEDEFS)
IF(HAVE_UNUSED_TYPEDEFS)
ADD_COMPILE_FLAGS(
${BOOST_SOURCES_DIR}/libs/thread/src/pthread/once.cpp
${BOOST_SOURCES_DIR}/libs/thread/src/pthread/thread.cpp
COMPILE_FLAGS "-Wno-unused-local-typedefs"
)
ADD_COMPILE_FLAGS(${MYSQLCLIENT_BOOST_SOURCES}
COMPILE_FLAGS "-Wno-unused-local-typedefs")
ENDIF()

# Boost source use undefined symbols in #if checks
MY_CHECK_CXX_COMPILER_FLAG("-Wundef" HAVE_UNDEF)
IF(HAVE_UNDEF)
ADD_COMPILE_FLAGS(${MYSQLCLIENT_BOOST_SOURCES} COMPILE_FLAGS "-Wno-undef")
ENDIF()

ADD_COMPILE_FLAGS(
2 changes: 1 addition & 1 deletion client/base/abstract_program.cc
Original file line number Diff line number Diff line change
@@ -110,7 +110,7 @@ Abstract_program::~Abstract_program()

void Abstract_program::init_name(char *name_from_cmd_line)
{
#if _WIN32
#ifdef _WIN32
char* name;

char name_buf[FN_REFLEN];
49 changes: 29 additions & 20 deletions client/dump/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -103,31 +103,40 @@ IF (NOT (CMAKE_CXX_COMPILER_ID STREQUAL "SunPro"))
TARGET_LINK_LIBRARIES(mysqlpump_lib
client_base ${LZ4_LIBRARY} boost_lib)

# Boost source has unused local typedefs.
MY_CHECK_CXX_COMPILER_FLAG("-Wunused-local-typedefs" HAVE_UNUSED_TYPEDEFS)
IF(HAVE_UNUSED_TYPEDEFS)
ADD_COMPILE_FLAGS(
abstract_crawler.cc
abstract_mysql_chain_element_extension.cc
abstract_progress_watcher.cc
mysql_chain_element_options.cc
mysqldump_tool_chain_maker.cc
mysqldump_tool_chain_maker_options.cc
object_filter.cc
object_queue.cc
program.cc
standard_progress_watcher.cc
sql_formatter.cc
table.cc
COMPILE_FLAGS "-Wno-unused-local-typedefs"
)
ENDIF()

ADD_COMPILE_FLAGS(
${MYSQLPUMP_LIB_SOURCES}
COMPILE_FLAGS -I${BOOST_PATCHES_DIR} -I${BOOST_INCLUDE_DIR}
)

# Files that use Boost sources that trigger compilation warnings
SET(MYSQLPUMP_BOOST_SOURCES
abstract_crawler.cc
abstract_mysql_chain_element_extension.cc
abstract_progress_watcher.cc
mysql_chain_element_options.cc
mysqldump_tool_chain_maker.cc
mysqldump_tool_chain_maker_options.cc
object_filter.cc
object_queue.cc
program.cc
standard_progress_watcher.cc
sql_formatter.cc
table.cc
)

# Boost source has unused local typedefs.
MY_CHECK_CXX_COMPILER_FLAG("-Wunused-local-typedefs" HAVE_UNUSED_TYPEDEFS)
IF(HAVE_UNUSED_TYPEDEFS)
ADD_COMPILE_FLAGS(${MYSQLPUMP_BOOST_SOURCES}
COMPILE_FLAGS "-Wno-unused-local-typedefs")
ENDIF()

# Boost source use undefined symbols in #if checks
MY_CHECK_CXX_COMPILER_FLAG("-Wundef" HAVE_UNDEF)
IF(HAVE_UNDEF)
ADD_COMPILE_FLAGS(${MYSQLPUMP_BOOST_SOURCES} COMPILE_FLAGS "-Wno-undef")
ENDIF()

ADD_COMPILE_FLAGS(
compression_writer.cc
mysqldump_tool_chain_maker.cc
4 changes: 2 additions & 2 deletions client/mysql_plugin.c
Original file line number Diff line number Diff line change
@@ -569,7 +569,7 @@ static int search_dir(const char * base_path, const char *tool_name,
{
char new_path[FN_REFLEN];
char source_path[FN_REFLEN];
#if _WIN32
#ifdef _WIN32
char win_abs_path[FN_REFLEN];
char self_name[FN_REFLEN];
const char *last_fn_libchar;
@@ -589,7 +589,7 @@ static int search_dir(const char * base_path, const char *tool_name,
return 0;
}

#if _WIN32
#ifdef _WIN32
/*
On Windows above code will not be able to find the file since
path names are not absolute and file_exists works only with
2 changes: 1 addition & 1 deletion client/mysqltest.cc
Original file line number Diff line number Diff line change
@@ -3063,7 +3063,7 @@ static void do_source(struct st_command *command)
static FILE* my_popen(DYNAMIC_STRING *ds_cmd, const char *mode,
struct st_command *command)
{
#if _WIN32
#ifdef _WIN32
/*
--execw is for tests executing commands containing non-ASCII characters.
6 changes: 4 additions & 2 deletions cmake/maintainer.cmake
Original file line number Diff line number Diff line change
@@ -44,6 +44,8 @@ MY_ADD_C_WARNING_FLAG("Wmissing-format-attribute")
MY_ADD_CXX_WARNING_FLAG("Wmissing-format-attribute")
# Only for C++ as C code has some macro usage that is difficult to avoid
MY_ADD_CXX_WARNING_FLAG("Wlogical-op")
MY_ADD_C_WARNING_FLAG("Wundef")
MY_ADD_CXX_WARNING_FLAG("Wundef")

# Turn on extra Clang warnings in maintainer mode
IF(CMAKE_C_COMPILER_ID MATCHES "Clang" AND MYSQL_MAINTAINER_MODE)
@@ -53,7 +55,7 @@ IF(CMAKE_C_COMPILER_ID MATCHES "Clang" AND MYSQL_MAINTAINER_MODE)
MY_ADD_C_WARNING_FLAG("Wunreachable-code-break")
MY_ADD_C_WARNING_FLAG("Wunreachable-code-return")
# Other possible options that give warnings:
# -Wcast-align -Wsign-conversion -Wcast-qual -Wreserved-id-macro -Wundef
# -Wcast-align -Wsign-conversion -Wcast-qual -Wreserved-id-macro
# -Wdocumentation-unknown-command -Wpadded -Wconversion -Wshorten-64-to-32
# -Wmissing-prototypes -Wused-but-marked-unused -Wmissing-variable-declarations
# -Wdocumentation -Wunreachable-code -Wunused-macros -Wformat-nonliteral
@@ -76,7 +78,7 @@ IF(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
MY_ADD_CXX_WARNING_FLAG("Wundefined-reinterpret-cast")
ENDIF()
# Other possible options that give warnings:
# -Wold-style-cast -Wundef -Wc++11-long-long -Wconversion -Wsign-conversion -Wcast-align
# -Wold-style-cast -Wc++11-long-long -Wconversion -Wsign-conversion -Wcast-align
# -Wmissing-prototypes -Wdocumentation -Wweak-vtables -Wdocumentation-unknown-command
# -Wreserved-id-macro -Wpadded -Wused-but-marked-unused -Wshadow -Wunreachable-code-return
# -Wunused-macros -Wmissing-variable-declarations -Wswitch-enum
2 changes: 1 addition & 1 deletion extra/comp_err.cc
Original file line number Diff line number Diff line change
@@ -203,7 +203,7 @@ int main(int argc, char *argv[])
/* Number of error messages in 5.5 - do not change this number! */
#define MYSQL_OLD_GA_ERROR_MESSAGE_COUNT 728
#endif
#if MYSQL_OLD_GA_ERROR_MESSAGE_COUNT
#ifdef MYSQL_OLD_GA_ERROR_MESSAGE_COUNT
if (row_count != MYSQL_OLD_GA_ERROR_MESSAGE_COUNT)
{
fprintf(stderr, "Can only add new error messages to latest GA. ");
2 changes: 1 addition & 1 deletion extra/yassl/taocrypt/include/misc.hpp
Original file line number Diff line number Diff line change
@@ -390,7 +390,7 @@ inline T RoundUpToMultipleOf(T n, T m)
template <class T>
inline unsigned int GetAlignment(T* dummy = 0) // VC60 workaround
{
#if (_MSC_VER >= 1300)
#if defined(_WIN32) && (_MSC_VER >= 1300)
return __alignof(T);
#elif defined(__GNUC__)
return __alignof__(T);
2 changes: 1 addition & 1 deletion include/my_dir.h
Original file line number Diff line number Diff line change
@@ -59,7 +59,7 @@ extern "C" {

/* typedefs for my_dir & my_stat */

#if(_MSC_VER)
#ifdef _WIN32
#define MY_STAT struct _stati64 /* 64 bit file size */
#else
#define MY_STAT struct stat /* Orginal struct have what we need */
4 changes: 2 additions & 2 deletions include/my_global.h
Original file line number Diff line number Diff line change
@@ -316,7 +316,7 @@ typedef socklen_t socket_len_t;

/* Some defines of functions for portability */

#if (_WIN32)
#ifdef _WIN32
#if !defined(_WIN64)
inline double my_ulonglong2double(unsigned long long value)
{
@@ -371,7 +371,7 @@ inline unsigned long long my_double2ulonglong(double d)
#include <ieeefp.h>
#endif

#if (__cplusplus >= 201103L)
#if defined(__cplusplus) && (__cplusplus >= 201103L)
/* For C++11 use the new std functions rather than C99 macros. */
#include <cmath>
#define my_isfinite(X) std::isfinite(X)
2 changes: 1 addition & 1 deletion include/my_stacktrace.h
Original file line number Diff line number Diff line change
@@ -35,7 +35,7 @@ C_MODE_START
void my_init_stacktrace();
void my_print_stacktrace(uchar* stack_bottom, ulong thread_stack);
void my_safe_puts_stderr(const char* val, size_t max_len);
#if HAVE_BACKTRACE && HAVE_ABI_CXA_DEMANGLE
#if defined(HAVE_BACKTRACE) && defined(HAVE_ABI_CXA_DEMANGLE)
char *my_demangle(const char *mangled_name, int *status);
#endif
#ifdef _WIN32
4 changes: 2 additions & 2 deletions include/my_timer.h
Original file line number Diff line number Diff line change
@@ -27,10 +27,10 @@
#ifdef HAVE_POSIX_TIMERS
# include <time.h> /* timer_t */
typedef timer_t os_timer_t;
#elif HAVE_KQUEUE_TIMERS
#elif defined(HAVE_KQUEUE_TIMERS)
# include <sys/types.h> /* uintptr_t */
typedef uintptr_t os_timer_t;
#elif _WIN32
#elif defined(_WIN32)
typedef struct st_os_timer
{
HANDLE timer_handle;
10 changes: 5 additions & 5 deletions libbinlogevents/include/byteorder.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
/* Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -51,7 +51,7 @@
*/
uint16_t inline le16toh(uint16_t x)
{
#if !(IS_BIG_ENDIAN)
#ifndef IS_BIG_ENDIAN
return x;
#else
return ((x >> 8) | (x << 8));
@@ -68,7 +68,7 @@ uint16_t inline le16toh(uint16_t x)
*/
uint32_t inline le32toh(uint32_t x)
{
#if !(IS_BIG_ENDIAN)
#ifndef IS_BIG_ENDIAN
return x;
#else
return (((x >> 24) & 0xff) |
@@ -88,7 +88,7 @@ uint32_t inline le32toh(uint32_t x)
*/
uint32_t inline be32toh(uint32_t x)
{
#if !(IS_BIG_ENDIAN)
#ifndef IS_BIG_ENDIAN
return (((x >> 24) & 0xff) |
((x << 8) & 0xff0000) |
((x >> 8) & 0xff00) |
@@ -108,7 +108,7 @@ uint32_t inline be32toh(uint32_t x)
*/
uint64_t inline le64toh(uint64_t x)
{
#if !(IS_BIG_ENDIAN)
#ifndef IS_BIG_ENDIAN
return x;
#else
x = ((x << 8) & 0xff00ff00ff00ff00ULL) |
12 changes: 6 additions & 6 deletions libbinlogevents/include/wrapper_functions.h
Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@
#define HAVE_MYSYS 1
#endif

#if HAVE_MYSYS
#ifdef HAVE_MYSYS
#include "my_sys.h"
#include "mysql/service_mysql_alloc.h"
extern "C" {
@@ -47,7 +47,7 @@ extern PSI_memory_key key_memory_log_event;
#endif

#if !defined(DBUG_OFF)
#if HAVE_MYSYS
#ifdef HAVE_MYSYS
#define BAPI_ASSERT(x) DBUG_ASSERT(x)
#else
#define BAPI_ASSERT(x) assert(x)
@@ -101,7 +101,7 @@ inline char *strndup (const char *s, size_t n)
*/
inline const char* bapi_strndup(const char *destination, size_t n)
{
#if HAVE_MYSYS
#ifdef HAVE_MYSYS
/* Call the function in mysys library, required for memory instrumentation */
return my_strndup(key_memory_log_event, destination, n, MYF(MY_WME));
#else
@@ -123,7 +123,7 @@ inline const char* bapi_strndup(const char *destination, size_t n)
inline void* bapi_memdup(const void* source, size_t len)
{
void* dest;
#if HAVE_MYSYS
#ifdef HAVE_MYSYS
/* Call the function in mysys library, required for memory instrumentation */
dest= my_memdup(key_memory_log_event, source, len, MYF(MY_WME));
#else
@@ -150,7 +150,7 @@ inline void* bapi_memdup(const void* source, size_t len)
inline void * bapi_malloc(size_t size, int flags)
{
void * dest= NULL;
#if HAVE_MYSYS
#ifdef HAVE_MYSYS
dest= my_malloc(key_memory_log_event, size, MYF(flags));
#else
dest= malloc(size);
@@ -171,7 +171,7 @@ inline void * bapi_malloc(size_t size, int flags)
*/
inline void bapi_free(void* ptr)
{
#if HAVE_MYSYS
#ifdef HAVE_MYSYS
return my_free(ptr);
#else
return free(ptr);
Loading

0 comments on commit f7c2f37

Please sign in to comment.