summaryrefslogtreecommitdiff
path: root/storage/innobase/row
diff options
context:
space:
mode:
authorMarko Mäkelä <marko.makela@mariadb.com>2020-03-12 19:46:41 +0200
committerMarko Mäkelä <marko.makela@mariadb.com>2020-03-12 19:46:41 +0200
commitf224525204dcd5a4f907cf9eccbba82ee7ea9018 (patch)
treea27012713cbab24419c81ac5d1708e34d897b849 /storage/innobase/row
parentd82ac8d374241b100f9e019400b23a5d905f622c (diff)
downloadmariadb-git-f224525204dcd5a4f907cf9eccbba82ee7ea9018.tar.gz
MDEV-21907: InnoDB: Enable -Wconversion on clang and GCC
The -Wconversion in GCC seems to be stricter than in clang. GCC at least since version 4.4.7 issues truncation warnings for assignments to bitfields, while clang 10 appears to only issue warnings when the sizes in bytes rounded to the nearest integer powers of 2 are different. Before GCC 10.0.0, -Wconversion required more casts and would not allow some operations, such as x<<=1 or x+=1 on a data type that is narrower than int. GCC 5 (but not GCC 4, GCC 6, or any later version) is complaining about x|=y even when x and y are compatible types that are narrower than int. Hence, we must rewrite some x|=y as x=static_cast<byte>(x|y) or similar, or we must disable -Wconversion. In GCC 6 and later, the warning for assigning wider to bitfields that are narrower than 8, 16, or 32 bits can be suppressed by applying a bitwise & with the exact bitmask of the bitfield. For older GCC, we must disable -Wconversion for GCC 4 or 5 in such cases. The bitwise negation operator appears to promote short integers to a wider type, and hence we must add explicit truncation casts around them. Microsoft Visual C does not allow a static_cast to truncate a constant, such as static_cast<byte>(1) truncating int. Hence, we will use the constructor-style cast byte(~1) for such cases. This has been tested at least with GCC 4.8.5, 5.4.0, 7.4.0, 9.2.1, 10.0.0, clang 9.0.1, 10.0.0, and MSVC 14.22.27905 (Microsoft Visual Studio 2019) on 64-bit and 32-bit targets (IA-32, AMD64, POWER 8, POWER 9, ARMv8).
Diffstat (limited to 'storage/innobase/row')
-rw-r--r--storage/innobase/row/row0ftsort.cc8
-rw-r--r--storage/innobase/row/row0import.cc18
-rw-r--r--storage/innobase/row/row0ins.cc14
-rw-r--r--storage/innobase/row/row0log.cc5
-rw-r--r--storage/innobase/row/row0merge.cc5
-rw-r--r--storage/innobase/row/row0mysql.cc4
-rw-r--r--storage/innobase/row/row0purge.cc4
-rw-r--r--storage/innobase/row/row0row.cc2
-rw-r--r--storage/innobase/row/row0sel.cc7
-rw-r--r--storage/innobase/row/row0umod.cc5
-rw-r--r--storage/innobase/row/row0upd.cc33
11 files changed, 56 insertions, 49 deletions
diff --git a/storage/innobase/row/row0ftsort.cc b/storage/innobase/row/row0ftsort.cc
index e59b380029d..a8e4a06b8ea 100644
--- a/storage/innobase/row/row0ftsort.cc
+++ b/storage/innobase/row/row0ftsort.cc
@@ -103,7 +103,8 @@ row_merge_create_fts_sort_index(
? DATA_VARCHAR : DATA_VARMYSQL;
field->col->mbminlen = idx_field->col->mbminlen;
field->col->mbmaxlen = idx_field->col->mbmaxlen;
- field->col->len = HA_FT_MAXCHARLEN * unsigned(field->col->mbmaxlen);
+ field->col->len = static_cast<uint16_t>(
+ HA_FT_MAXCHARLEN * field->col->mbmaxlen);
field->fixed_len = 0;
@@ -635,7 +636,7 @@ row_merge_fts_doc_tokenize(
field->type.mtype = DATA_INT;
field->type.prtype = DATA_NOT_NULL | DATA_BINARY_TYPE;
- field->type.len = field->len;
+ field->type.len = static_cast<uint16_t>(field->len);
field->type.mbminlen = 0;
field->type.mbmaxlen = 0;
@@ -1619,7 +1620,8 @@ row_fts_merge_insert(
in order to get the correct aux table names. */
index->table->flags2 |= DICT_TF2_FTS_AUX_HEX_NAME;
DBUG_EXECUTE_IF("innodb_test_wrong_fts_aux_table_name",
- index->table->flags2 &= ~DICT_TF2_FTS_AUX_HEX_NAME;);
+ index->table->flags2 &= ~DICT_TF2_FTS_AUX_HEX_NAME
+ & ((1U << DICT_TF2_BITS) - 1););
fts_table.type = FTS_INDEX_TABLE;
fts_table.index_id = index->id;
fts_table.table_id = table->id;
diff --git a/storage/innobase/row/row0import.cc b/storage/innobase/row/row0import.cc
index dcf96179158..494a8b3b729 100644
--- a/storage/innobase/row/row0import.cc
+++ b/storage/innobase/row/row0import.cc
@@ -2510,10 +2510,10 @@ row_import_cfg_read_index_fields(
new (field) dict_field_t();
- field->prefix_len = mach_read_from_4(ptr);
+ field->prefix_len = mach_read_from_4(ptr) & ((1U << 12) - 1);
ptr += sizeof(ib_uint32_t);
- field->fixed_len = mach_read_from_4(ptr);
+ field->fixed_len = mach_read_from_4(ptr) & ((1U << 10) - 1);
ptr += sizeof(ib_uint32_t);
/* Include the NUL byte in the length. */
@@ -2818,24 +2818,24 @@ row_import_read_columns(
col->prtype = mach_read_from_4(ptr);
ptr += sizeof(ib_uint32_t);
- col->mtype = mach_read_from_4(ptr);
+ col->mtype = static_cast<byte>(mach_read_from_4(ptr));
ptr += sizeof(ib_uint32_t);
- col->len = mach_read_from_4(ptr);
+ col->len = static_cast<uint16_t>(mach_read_from_4(ptr));
ptr += sizeof(ib_uint32_t);
uint32_t mbminmaxlen = mach_read_from_4(ptr);
- col->mbmaxlen = mbminmaxlen / 5;
- col->mbminlen = mbminmaxlen % 5;
+ col->mbmaxlen = (mbminmaxlen / 5) & 7;
+ col->mbminlen = (mbminmaxlen % 5) & 7;
ptr += sizeof(ib_uint32_t);
col->ind = mach_read_from_4(ptr) & dict_index_t::MAX_N_FIELDS;
ptr += sizeof(ib_uint32_t);
- col->ord_part = mach_read_from_4(ptr);
+ col->ord_part = mach_read_from_4(ptr) & 1;
ptr += sizeof(ib_uint32_t);
- col->max_prefix = mach_read_from_4(ptr);
+ col->max_prefix = mach_read_from_4(ptr) & ((1U << 12) - 1);
ptr += sizeof(ib_uint32_t);
/* Read in the column name as [len, byte array]. The len
@@ -4214,7 +4214,7 @@ row_import_for_mysql(
}
table->file_unreadable = false;
- table->flags2 &= ~DICT_TF2_DISCARDED;
+ table->flags2 &= ~DICT_TF2_DISCARDED & ((1U << DICT_TF2_BITS) - 1);
/* Set autoinc value read from .cfg file, if one was specified.
Otherwise, keep the PAGE_ROOT_AUTO_INC as is. */
diff --git a/storage/innobase/row/row0ins.cc b/storage/innobase/row/row0ins.cc
index 16158032e19..cbe82cfcd9c 100644
--- a/storage/innobase/row/row0ins.cc
+++ b/storage/innobase/row/row0ins.cc
@@ -540,9 +540,10 @@ row_ins_cascade_calc_update_vec(
ufield = update->fields + n_fields_updated;
- ufield->field_no = dict_table_get_nth_col_pos(
- table, dict_col_get_no(col),
- &prefix_col);
+ ufield->field_no = static_cast<uint16_t>(
+ dict_table_get_nth_col_pos(
+ table, dict_col_get_no(col),
+ &prefix_col));
ufield->orig_len = 0;
ufield->exp = NULL;
@@ -972,7 +973,7 @@ row_ins_foreign_fill_virtual(
goto func_exit;
}
- for (ulint i = 0; i < n_v_fld; i++) {
+ for (uint16_t i = 0; i < n_v_fld; i++) {
dict_v_col_t* col = dict_table_get_nth_v_col(
index->table, i);
@@ -1297,8 +1298,9 @@ row_ins_foreign_check_on_constraint(
index, i);
ulint prefix_col;
- ufield->field_no = dict_table_get_nth_col_pos(
- table, col_no, &prefix_col);
+ ufield->field_no = static_cast<uint16_t>(
+ dict_table_get_nth_col_pos(
+ table, col_no, &prefix_col));
dict_col_t* col = dict_table_get_nth_col(
table, col_no);
dict_col_copy_type(col, dfield_get_type(&ufield->new_val));
diff --git a/storage/innobase/row/row0log.cc b/storage/innobase/row/row0log.cc
index 8559db3384b..f7e9cb18e5e 100644
--- a/storage/innobase/row/row0log.cc
+++ b/storage/innobase/row/row0log.cc
@@ -2067,9 +2067,8 @@ row_log_table_apply_update(
ut_ad(dtuple_get_n_fields_cmp(old_pk)
== dict_index_get_n_unique(index));
- ut_ad(dtuple_get_n_fields(old_pk)
- == dict_index_get_n_unique(index)
- + (log->same_pk ? 0 : 2));
+ ut_ad(dtuple_get_n_fields(old_pk) - (log->same_pk ? 0 : 2)
+ == dict_index_get_n_unique(index));
row = row_log_table_apply_convert_mrec(
mrec, dup->index, offsets, log, heap, &error);
diff --git a/storage/innobase/row/row0merge.cc b/storage/innobase/row/row0merge.cc
index 050d79abc21..ef9d8ee542c 100644
--- a/storage/innobase/row/row0merge.cc
+++ b/storage/innobase/row/row0merge.cc
@@ -656,7 +656,8 @@ row_merge_buf_add(
doc_item->field = field;
doc_item->doc_id = *doc_id;
- bucket = *doc_id % fts_sort_pll_degree;
+ bucket = static_cast<ulint>(
+ *doc_id % fts_sort_pll_degree);
/* Add doc item to fts_doc_list */
mutex_enter(&psort_info[bucket].mutex);
@@ -3287,7 +3288,7 @@ row_merge_sort(
num_runs = file->offset;
if (stage != NULL) {
- stage->begin_phase_sort(log2(num_runs));
+ stage->begin_phase_sort(log2(double(num_runs)));
}
/* If num_runs are less than 1, nothing to merge */
diff --git a/storage/innobase/row/row0mysql.cc b/storage/innobase/row/row0mysql.cc
index ce52b01d01e..a9bcd9463a2 100644
--- a/storage/innobase/row/row0mysql.cc
+++ b/storage/innobase/row/row0mysql.cc
@@ -2561,8 +2561,8 @@ row_create_index_for_mysql(
ut_ad((index == NULL) == (err != DB_SUCCESS));
if (UNIV_LIKELY(err == DB_SUCCESS)) {
ut_ad(!index->is_instant());
- index->n_core_null_bytes = UT_BITS_IN_BYTES(
- unsigned(index->n_nullable));
+ index->n_core_null_bytes = static_cast<uint8_t>(
+ UT_BITS_IN_BYTES(unsigned(index->n_nullable)));
err = dict_create_index_tree_in_mem(index, trx);
diff --git a/storage/innobase/row/row0purge.cc b/storage/innobase/row/row0purge.cc
index 58b84528949..20685398a81 100644
--- a/storage/innobase/row/row0purge.cc
+++ b/storage/innobase/row/row0purge.cc
@@ -704,7 +704,7 @@ static void row_purge_reset_trx_id(purge_node_t* node, mtr_t* mtr)
byte* ptr = rec_get_nth_field(
rec, offsets, trx_id_pos, &len);
ut_ad(len == DATA_TRX_ID_LEN);
- uint16_t offs = page_offset(ptr);
+ size_t offs = page_offset(ptr);
mtr->memset(block, offs, DATA_TRX_ID_LEN, 0);
offs += DATA_TRX_ID_LEN;
mtr->write<1,mtr_t::OPT>(*block, block->frame
@@ -882,7 +882,7 @@ row_purge_parse_undo_rec(
undo_no_t undo_no;
table_id_t table_id;
roll_ptr_t roll_ptr;
- ulint info_bits;
+ byte info_bits;
ulint type;
ut_ad(node != NULL);
diff --git a/storage/innobase/row/row0row.cc b/storage/innobase/row/row0row.cc
index 83add52dd88..1af9638412c 100644
--- a/storage/innobase/row/row0row.cc
+++ b/storage/innobase/row/row0row.cc
@@ -765,7 +765,7 @@ row_rec_to_index_entry_impl(
(missing merge_threshold column) is acceptable. */
|| (!index->table->is_temporary()
&& index->table->id == DICT_INDEXES_ID
- && rec_len == dict_index_get_n_fields(index) - 1));
+ && rec_len + 1 == dict_index_get_n_fields(index)));
ulint i;
for (i = 0; i < (mblob ? index->first_user_field() : rec_len);
diff --git a/storage/innobase/row/row0sel.cc b/storage/innobase/row/row0sel.cc
index 564858e6668..b8f89d53e69 100644
--- a/storage/innobase/row/row0sel.cc
+++ b/storage/innobase/row/row0sel.cc
@@ -2995,7 +2995,7 @@ row_sel_store_mysql_field(
/* It is a nullable column with a non-NULL
value */
mysql_rec[templ->mysql_null_byte_offset]
- &= ~(byte) templ->mysql_null_bit_mask;
+ &= static_cast<byte>(~templ->mysql_null_bit_mask);
}
DBUG_RETURN(TRUE);
@@ -3098,8 +3098,9 @@ static bool row_sel_store_mysql_rec(
(const byte*)dfield->data, dfield->len);
if (templ->mysql_null_bit_mask) {
mysql_rec[
- templ->mysql_null_byte_offset]
- &= ~(byte) templ->mysql_null_bit_mask;
+ templ->mysql_null_byte_offset]
+ &= static_cast<byte>
+ (~templ->mysql_null_bit_mask);
}
}
diff --git a/storage/innobase/row/row0umod.cc b/storage/innobase/row/row0umod.cc
index cc5ac98937f..6822c4a363d 100644
--- a/storage/innobase/row/row0umod.cc
+++ b/storage/innobase/row/row0umod.cc
@@ -478,8 +478,7 @@ row_undo_mod_clust(
0, 1ULL << ROLL_PTR_INSERT_FLAG_POS,
&mtr);
} else {
- uint16_t offs = page_offset(rec
- + trx_id_offset);
+ size_t offs = page_offset(rec + trx_id_offset);
mtr.memset(block, offs, DATA_TRX_ID_LEN, 0);
offs += DATA_TRX_ID_LEN;
mtr.write<1,mtr_t::OPT>(*block, block->frame
@@ -1204,7 +1203,7 @@ static bool row_undo_mod_parse_undo_rec(undo_node_t* node, bool dict_locked)
table_id_t table_id;
trx_id_t trx_id;
roll_ptr_t roll_ptr;
- ulint info_bits;
+ byte info_bits;
ulint type;
ulint cmpl_info;
bool dummy_extern;
diff --git a/storage/innobase/row/row0upd.cc b/storage/innobase/row/row0upd.cc
index 1bd14280c8b..e797d527969 100644
--- a/storage/innobase/row/row0upd.cc
+++ b/storage/innobase/row/row0upd.cc
@@ -605,7 +605,6 @@ row_upd_build_sec_rec_difference_binary(
ulint len;
upd_t* update;
ulint n_diff;
- ulint i;
/* This function is used only for a secondary index */
ut_a(!dict_index_is_clust(index));
@@ -619,7 +618,7 @@ row_upd_build_sec_rec_difference_binary(
n_diff = 0;
- for (i = 0; i < dtuple_get_n_fields(entry); i++) {
+ for (uint16_t i = 0; i < dtuple_get_n_fields(entry); i++) {
data = rec_get_nth_field(rec, offsets, i, &len);
@@ -707,7 +706,7 @@ row_upd_build_difference_binary(
ut_ad(rec_offs_validate(rec, index, offsets));
}
- for (ulint i = 0; i < entry->n_fields; i++) {
+ for (uint16_t i = 0; i < entry->n_fields; i++) {
const byte* data = rec_get_nth_cfield(rec, index, offsets, i,
&len);
const dfield_t* dfield = dtuple_get_nth_field(entry, i);
@@ -728,7 +727,8 @@ row_upd_build_difference_binary(
}
}
- for (ulint i = entry->n_fields; i < index->n_fields; i++) {
+ for (uint16_t i = static_cast<uint16_t>(entry->n_fields);
+ i < index->n_fields; i++) {
upd_field_t* uf = upd_get_nth_field(update, n_diff++);
const dict_col_t* col = dict_index_get_nth_col(index, i);
/* upd_create() zero-initialized uf */
@@ -762,7 +762,7 @@ row_upd_build_difference_binary(
&mysql_table,
&record, &vcol_storage);
- for (ulint i = 0; i < n_v_fld; i++) {
+ for (uint16_t i = 0; i < n_v_fld; i++) {
const dict_v_col_t* col
= dict_table_get_nth_v_col(index->table, i);
@@ -1021,7 +1021,7 @@ row_upd_index_replace_new_col_vals_index_pos(
dtuple_set_info_bits(entry, update->info_bits);
- for (unsigned i = index->n_fields; i--; ) {
+ for (uint16_t i = index->n_fields; i--; ) {
const dict_field_t* field;
const dict_col_t* col;
const upd_field_t* uf;
@@ -1091,8 +1091,9 @@ row_upd_index_replace_new_col_vals(
update, vcol->v_pos, true);
} else {
uf = upd_get_field_by_field_no(
- update,
- dict_col_get_clust_pos(col, clust_index),
+ update, static_cast<uint16_t>(
+ dict_col_get_clust_pos(
+ col, clust_index)),
false);
}
@@ -1392,8 +1393,9 @@ row_upd_changes_ord_field_binary_func(
update, vcol->v_pos, true);
} else {
upd_field = upd_get_field_by_field_no(
- update,
- dict_col_get_clust_pos(col, clust_index),
+ update, static_cast<uint16_t>(
+ dict_col_get_clust_pos(
+ col, clust_index)),
false);
}
@@ -2278,14 +2280,13 @@ row_upd_clust_rec_by_insert_inherit_func(
const upd_t* update) /*!< in: update vector */
{
bool inherit = false;
- ulint i;
ut_ad(!rec == !offsets);
ut_ad(!rec == !index);
ut_ad(!rec || rec_offs_validate(rec, index, offsets));
ut_ad(!rec || rec_offs_any_extern(offsets));
- for (i = 0; i < dtuple_get_n_fields(entry); i++) {
+ for (uint16_t i = 0; i < dtuple_get_n_fields(entry); i++) {
dfield_t* dfield = dtuple_get_nth_field(entry, i);
byte* data;
ulint len;
@@ -2336,7 +2337,7 @@ row_upd_clust_rec_by_insert_inherit_func(
a lock wait and we already had disowned the BLOB. */
ut_a(rec == NULL
|| !(data[BTR_EXTERN_LEN] & BTR_EXTERN_OWNER_FLAG));
- data[BTR_EXTERN_LEN] &= ~BTR_EXTERN_OWNER_FLAG;
+ data[BTR_EXTERN_LEN] &= byte(~BTR_EXTERN_OWNER_FLAG);
data[BTR_EXTERN_LEN] |= BTR_EXTERN_INHERITED_FLAG;
/* The BTR_EXTERN_INHERITED_FLAG only matters in
rollback of a fresh insert. Purge will always free
@@ -2972,7 +2973,7 @@ row_upd(
ut_ad(!thr_get_trx(thr)->in_rollback);
DBUG_PRINT("row_upd", ("table: %s", node->table->name.m_name));
- DBUG_PRINT("row_upd", ("info bits in update vector: 0x" ULINTPFx,
+ DBUG_PRINT("row_upd", ("info bits in update vector: 0x%x",
node->update ? node->update->info_bits: 0));
DBUG_PRINT("row_upd", ("foreign_id: %s",
node->foreign ? node->foreign->id: "NULL"));
@@ -3193,7 +3194,9 @@ void upd_node_t::make_versioned_helper(const trx_t* trx, ulint idx)
upd_field_t* ufield = upd_get_nth_field(update, update->n_fields - 1);
const dict_col_t* col = dict_table_get_nth_col(table, idx);
- upd_field_set_field_no(ufield, dict_col_get_clust_pos(col, clust_index),
+ upd_field_set_field_no(ufield, static_cast<uint16_t>(
+ dict_col_get_clust_pos(
+ col, clust_index)),
clust_index);
char* where = reinterpret_cast<char*>(update->vers_sys_value);