# At a local mysql-5.1-bugteam repository of davi
3543 Davi Arnaut 2010-10-20
Bug#45288: pb2 returns a lot of compilation warnings
Fix assorted warnings that are generated in optimized builds. Most
of it is silencing variables that are set but unused.
This patch also introduces the MY_UNREACHABLE macro which helps
the compiler to deduce that a certain piece of code is unreachable.
@ include/my_compiler.h
Use GCC's __builtin_unreachable if available. It allows the GCC
to deduce the unreachability of certain code paths, thus avoiding
warnings that, for example, accused that a variable could be used
without being initialized.
modified:
client/mysqltest.cc
cmd-line-utils/readline/complete.c
cmd-line-utils/readline/histexpand.c
cmd-line-utils/readline/histfile.c
cmd-line-utils/readline/isearch.c
cmd-line-utils/readline/parens.c
cmd-line-utils/readline/readline.c
cmd-line-utils/readline/text.c
include/my_compiler.h
sql/lock.cc
sql/log.cc
sql/set_var.cc
sql/sql_acl.cc
sql/sql_help.cc
sql/sql_partition.cc
sql/sql_union.cc
storage/myisam/myisamchk.c
storage/myisammrg/ha_myisammrg.cc
=== modified file 'client/mysqltest.cc'
--- a/client/mysqltest.cc 2010-10-03 17:37:58 +0000
+++ b/client/mysqltest.cc 2010-10-20 17:32:34 +0000
@@ -5163,6 +5163,11 @@ void do_connect(struct st_command *comma
DBUG_ENTER("do_connect");
DBUG_PRINT("enter",("connect: %s", command->first_argument));
+ /* Silence warnings due to the variables not being used in some platforms. */
+ (void) con_ssl;
+ (void) con_pipe;
+ (void) con_shm;
+
strip_parentheses(command);
check_command_args(command, command->first_argument, connect_args,
sizeof(connect_args)/sizeof(struct command_arg),
=== modified file 'cmd-line-utils/readline/complete.c'
--- a/cmd-line-utils/readline/complete.c 2009-06-29 14:00:47 +0000
+++ b/cmd-line-utils/readline/complete.c 2010-10-20 17:32:34 +0000
@@ -1839,8 +1839,11 @@ rl_username_completion_function (text, s
#else /* !__WIN32__ && !__OPENNT) */
static char *username = (char *)NULL;
static struct passwd *entry;
- static int namelen, first_char, first_char_loc;
+ static int first_char, first_char_loc;
char *value;
+#if defined (HAVE_GETPWENT)
+ static int namelen;
+#endif
if (state == 0)
{
@@ -1850,7 +1853,9 @@ rl_username_completion_function (text, s
first_char_loc = first_char == '~';
username = savestring (&text[first_char_loc]);
+#if defined (HAVE_GETPWENT)
namelen = strlen (username);
+#endif
setpwent ();
}
=== modified file 'cmd-line-utils/readline/histexpand.c'
--- a/cmd-line-utils/readline/histexpand.c 2009-06-29 13:17:01 +0000
+++ b/cmd-line-utils/readline/histexpand.c 2010-10-20 17:32:34 +0000
@@ -693,7 +693,7 @@ history_expand_internal (string, start,
case 's':
{
char *new_event;
- int delimiter, failed, si, l_temp, ws, we;
+ int delimiter, failed, si, l_temp, we;
if (c == 's')
{
@@ -792,7 +792,6 @@ history_expand_internal (string, start,
{
for (; temp[si] && whitespace (temp[si]); si++)
;
- ws = si;
we = history_tokenize_word (temp, si);
}
=== modified file 'cmd-line-utils/readline/histfile.c'
--- a/cmd-line-utils/readline/histfile.c 2009-08-28 16:21:54 +0000
+++ b/cmd-line-utils/readline/histfile.c 2010-10-20 17:32:34 +0000
@@ -402,6 +402,7 @@ history_truncate_file (fname, lines)
if (bp > buffer && ((file = open (filename, O_WRONLY|O_TRUNC|O_BINARY, 0600)) != -1))
{
bytes_written= write (file, bp, chars_read - (bp - buffer));
+ (void) bytes_written;
#if defined (__BEOS__)
/* BeOS ignores O_TRUNC. */
=== modified file 'cmd-line-utils/readline/isearch.c'
--- a/cmd-line-utils/readline/isearch.c 2009-06-29 13:17:01 +0000
+++ b/cmd-line-utils/readline/isearch.c 2010-10-20 17:32:34 +0000
@@ -617,7 +617,7 @@ rl_search_history (direction, invoking_k
int direction, invoking_key __attribute__((unused));
{
_rl_search_cxt *cxt; /* local for now, but saved globally */
- int c, r;
+ int r;
RL_SETSTATE(RL_STATE_ISEARCH);
cxt = _rl_isearch_init (direction);
@@ -632,7 +632,7 @@ rl_search_history (direction, invoking_k
r = -1;
for (;;)
{
- c = _rl_search_getchar (cxt);
+ _rl_search_getchar (cxt);
/* We might want to handle EOF here (c == 0) */
r = _rl_isearch_dispatch (cxt, cxt->lastc);
if (r <= 0)
@@ -655,9 +655,9 @@ int
_rl_isearch_callback (cxt)
_rl_search_cxt *cxt;
{
- int c, r;
+ int r;
- c = _rl_search_getchar (cxt);
+ _rl_search_getchar (cxt);
/* We might want to handle EOF here */
r = _rl_isearch_dispatch (cxt, cxt->lastc);
=== modified file 'cmd-line-utils/readline/parens.c'
--- a/cmd-line-utils/readline/parens.c 2008-01-03 13:26:41 +0000
+++ b/cmd-line-utils/readline/parens.c 2010-10-20 17:32:34 +0000
@@ -115,7 +115,7 @@ rl_insert_close (count, invoking_key)
else
{
#if defined (HAVE_SELECT)
- int orig_point, match_point, ready;
+ int orig_point, match_point;
struct timeval timer;
fd_set readfds;
@@ -136,7 +136,7 @@ rl_insert_close (count, invoking_key)
orig_point = rl_point;
rl_point = match_point;
(*rl_redisplay_function) ();
- ready = select (1, &readfds, (fd_set *)NULL, (fd_set *)NULL, &timer);
+ select (1, &readfds, (fd_set *)NULL, (fd_set *)NULL, &timer);
rl_point = orig_point;
#else /* !HAVE_SELECT */
_rl_insert_char (count, invoking_key);
=== modified file 'cmd-line-utils/readline/readline.c'
--- a/cmd-line-utils/readline/readline.c 2009-06-29 13:17:01 +0000
+++ b/cmd-line-utils/readline/readline.c 2010-10-20 17:32:34 +0000
@@ -447,11 +447,10 @@ readline_internal_char ()
readline_internal_charloop ()
#endif
{
- static int lastc, eof_found;
+ static int lastc;
int c, code, lk;
lastc = -1;
- eof_found = 0;
#if !defined (READLINE_CALLBACKS)
while (rl_done == 0)
=== modified file 'cmd-line-utils/readline/text.c'
--- a/cmd-line-utils/readline/text.c 2010-02-22 13:23:47 +0000
+++ b/cmd-line-utils/readline/text.c 2010-10-20 17:32:34 +0000
@@ -811,11 +811,10 @@ _rl_overwrite_char (count, c)
int i;
#if defined (HANDLE_MULTIBYTE)
char mbkey[MB_LEN_MAX];
- int k;
/* Read an entire multibyte character sequence to insert COUNT times. */
if (count > 0 && MB_CUR_MAX > 1 && rl_byte_oriented == 0)
- k = _rl_read_mbstring (c, mbkey, MB_LEN_MAX);
+ _rl_read_mbstring (c, mbkey, MB_LEN_MAX);
#endif
rl_begin_undo_group ();
=== modified file 'include/my_compiler.h'
--- a/include/my_compiler.h 2010-07-14 19:39:40 +0000
+++ b/include/my_compiler.h 2010-10-20 17:32:34 +0000
@@ -32,8 +32,15 @@
/* GNU C/C++ */
#if defined __GNUC__
+/* Convenience macro to test the minimum required GCC version. */
+# define MY_GNUC_PREREQ(maj, min) \
+ ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
/* Any after 2.95... */
# define MY_ALIGN_EXT
+/* Comunicate to the compiler the unreachability of the code. */
+# if MY_GNUC_PREREQ(4,5)
+# define MY_UNREACHABLE() __builtin_unreachable()
+# endif
/* Microsoft Visual C++ */
#elif defined _MSC_VER
@@ -67,7 +74,7 @@
#endif
/**
- Generic compiler-dependent features.
+ Generic (compiler-independent) features.
*/
#ifndef MY_ALIGNOF
# ifdef __cplusplus
@@ -79,6 +86,10 @@
# endif
#endif
+#ifndef MY_UNREACHABLE
+# define MY_UNREACHABLE() do { assert(0); } while (0)
+#endif
+
/**
C++ Type Traits
*/
=== modified file 'sql/lock.cc'
--- a/sql/lock.cc 2009-08-28 16:21:54 +0000
+++ b/sql/lock.cc 2010-10-20 17:32:34 +0000
@@ -693,7 +693,6 @@ TABLE_LIST *mysql_lock_have_duplicate(TH
TABLE_LIST *haystack)
{
MYSQL_LOCK *mylock;
- TABLE **lock_tables;
TABLE *table;
TABLE *table2;
THR_LOCK_DATA **lock_locks;
@@ -722,12 +721,11 @@ TABLE_LIST *mysql_lock_have_duplicate(TH
if (mylock->table_count < 2)
goto end;
- lock_locks= mylock->locks;
- lock_tables= mylock->table;
+ lock_locks= mylock->locks;
/* Prepare table related variables that don't change in loop. */
DBUG_ASSERT((table->lock_position < mylock->table_count) &&
- (table == lock_tables[table->lock_position]));
+ (table == mylock->table[table->lock_position]));
table_lock_data= lock_locks + table->lock_data_start;
end_data= table_lock_data + table->lock_count;
@@ -741,7 +739,7 @@ TABLE_LIST *mysql_lock_have_duplicate(TH
/* All tables in list must be in lock. */
DBUG_ASSERT((table2->lock_position < mylock->table_count) &&
- (table2 == lock_tables[table2->lock_position]));
+ (table2 == mylock->table[table2->lock_position]));
for (lock_data2= lock_locks + table2->lock_data_start,
end_data2= lock_data2 + table2->lock_count;
=== modified file 'sql/log.cc'
--- a/sql/log.cc 2010-10-18 11:24:34 +0000
+++ b/sql/log.cc 2010-10-20 17:32:34 +0000
@@ -1217,7 +1217,7 @@ void LOGGER::deactivate_log_handler(THD
file_log= file_log_handler->get_mysql_log();
break;
default:
- assert(0); // Impossible
+ MY_UNREACHABLE();
}
if (!(*tmp_opt))
=== modified file 'sql/set_var.cc'
--- a/sql/set_var.cc 2010-07-02 18:30:47 +0000
+++ b/sql/set_var.cc 2010-10-20 17:32:34 +0000
@@ -2559,7 +2559,7 @@ bool update_sys_var_str_path(THD *thd, s
file_log= logger.get_log_file_handler();
break;
default:
- assert(0); // Impossible
+ MY_UNREACHABLE();
}
if (!old_value)
=== modified file 'sql/sql_acl.cc'
--- a/sql/sql_acl.cc 2010-10-06 10:19:51 +0000
+++ b/sql/sql_acl.cc 2010-10-20 17:32:34 +0000
@@ -5479,7 +5479,7 @@ static int handle_grant_struct(uint stru
host= grant_name->host.hostname;
break;
default:
- assert(0);
+ MY_UNREACHABLE();
}
if (! user)
user= "";
=== modified file 'sql/sql_help.cc'
--- a/sql/sql_help.cc 2009-06-17 14:56:44 +0000
+++ b/sql/sql_help.cc 2010-10-20 17:32:34 +0000
@@ -686,7 +686,7 @@ bool mysqld_help(THD *thd, const char *m
if (count_topics == 0)
{
- int key_id;
+ int UNINIT_VAR(key_id);
if (!(select=
prepare_select_for_name(thd,mask,mlen,tables,tables[3].table,
used_fields[help_keyword_name].field,
=== modified file 'sql/sql_partition.cc'
--- a/sql/sql_partition.cc 2010-07-29 03:00:57 +0000
+++ b/sql/sql_partition.cc 2010-10-20 17:32:34 +0000
@@ -6786,8 +6786,8 @@ int get_part_iter_for_interval_via_mappi
}
}
else
- assert(0);
-
+ MY_UNREACHABLE();
+
can_match_multiple_values= (flags || !min_value || !max_value ||
memcmp(min_value, max_value, field_len));
if (can_match_multiple_values &&
=== modified file 'sql/sql_union.cc'
--- a/sql/sql_union.cc 2010-06-10 20:45:22 +0000
+++ b/sql/sql_union.cc 2010-10-20 17:32:34 +0000
@@ -173,7 +173,6 @@ bool st_select_lex_unit::prepare(THD *th
SELECT_LEX *sl, *first_sl= first_select();
select_result *tmp_result;
bool is_union_select;
- TABLE *empty_table= 0;
DBUG_ENTER("st_select_lex_unit::prepare");
describe= test(additional_options & SELECT_DESCRIBE);
@@ -275,14 +274,6 @@ bool st_select_lex_unit::prepare(THD *th
types= first_sl->item_list;
else if (sl == first_sl)
{
- /*
- We need to create an empty table object. It is used
- to create tmp_table fields in Item_type_holder.
- The main reason of this is that we can't create
- field object without table.
- */
- DBUG_ASSERT(!empty_table);
- empty_table= (TABLE*) thd->calloc(sizeof(TABLE));
types.empty();
List_iterator_fast<Item> it(sl->item_list);
Item *item_tmp;
=== modified file 'storage/myisam/myisamchk.c'
--- a/storage/myisam/myisamchk.c 2010-06-10 20:16:43 +0000
+++ b/storage/myisam/myisamchk.c 2010-10-20 17:32:34 +0000
@@ -697,8 +697,7 @@ get_one_option(int optid,
case OPT_STATS_METHOD:
{
int method;
- enum_mi_stats_method method_conv;
- LINT_INIT(method_conv);
+ enum_mi_stats_method UNINIT_VAR(method_conv);
myisam_stats_method_str= argument;
if ((method=find_type(argument, &myisam_stats_method_typelib, 2)) <= 0)
{
=== modified file 'storage/myisammrg/ha_myisammrg.cc'
--- a/storage/myisammrg/ha_myisammrg.cc 2010-07-02 18:30:47 +0000
+++ b/storage/myisammrg/ha_myisammrg.cc 2010-10-20 17:32:34 +0000
@@ -415,7 +415,7 @@ static MI_INFO *myisammrg_attach_childre
my_errno= HA_ERR_WRONG_MRG_TABLE_DEF;
}
DBUG_PRINT("myrg", ("MyISAM handle: 0x%lx my_errno: %d",
- my_errno ? NULL : (long) myisam, my_errno));
+ my_errno ? 0L : (long) myisam, my_errno));
err:
DBUG_RETURN(my_errno ? NULL : myisam);
Attachment: [text/bzr-bundle] bzr/davi.arnaut@oracle.com-20101020173234-30c0nvbh3061gxp1.bundle
| Thread |
|---|
| • bzr commit into mysql-5.1-bugteam branch (davi:3543) Bug#45288 | Davi Arnaut | 20 Oct |