summaryrefslogtreecommitdiff
path: root/storage/innobase/page/page0cur.cc
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/page/page0cur.cc
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/page/page0cur.cc')
-rw-r--r--storage/innobase/page/page0cur.cc35
1 files changed, 18 insertions, 17 deletions
diff --git a/storage/innobase/page/page0cur.cc b/storage/innobase/page/page0cur.cc
index 607abb596c4..c1c389fed67 100644
--- a/storage/innobase/page/page0cur.cc
+++ b/storage/innobase/page/page0cur.cc
@@ -1404,20 +1404,20 @@ use_heap:
if (UNIV_UNLIKELY(!last_insert))
{
no_direction:
- *dir= (*dir & ~((1U << 3) - 1)) | PAGE_NO_DIRECTION;
+ *dir= static_cast<byte>((*dir & ~((1U << 3) - 1)) | PAGE_NO_DIRECTION);
memset(n, 0, 2);
}
else if (block->frame + last_insert == cur->rec &&
(*dir & ((1U << 3) - 1)) != PAGE_LEFT)
{
- *dir= (*dir & ~((1U << 3) - 1)) | PAGE_RIGHT;
+ *dir= static_cast<byte>((*dir & ~((1U << 3) - 1)) | PAGE_RIGHT);
inc_dir:
mach_write_to_2(n, mach_read_from_2(n) + 1);
}
else if (next_rec == block->frame + last_insert &&
(*dir & ((1U << 3) - 1)) != PAGE_RIGHT)
{
- *dir= (*dir & ~((1U << 3) - 1)) | PAGE_LEFT;
+ *dir= static_cast<byte>((*dir & ~((1U << 3) - 1)) | PAGE_LEFT);
goto inc_dir;
}
else
@@ -1866,7 +1866,7 @@ too_small:
static_assert(UNIV_ZIP_SIZE_SHIFT_MAX == 14, "compatibility");
if (next_rec)
{
- next_rec+= free_rec;
+ next_rec= static_cast<int16_t>(next_rec + free_rec);
ut_ad(int{PAGE_NEW_SUPREMUM_END + REC_N_NEW_EXTRA_BYTES} <= next_rec);
ut_ad(static_cast<uint16_t>(next_rec) < srv_page_size);
}
@@ -2041,7 +2041,8 @@ static void page_mem_free(const buf_block_t &block, rec_t *rec,
ut_ad(!block.page.zip.data);
const rec_t *free= page_header_get_ptr(block.frame, PAGE_FREE);
- const uint16_t n_heap= page_header_get_field(block.frame, PAGE_N_HEAP) - 1;
+ const uint16_t n_heap= uint16_t(page_header_get_field(block.frame,
+ PAGE_N_HEAP) - 1);
ut_ad(page_get_n_recs(block.frame) < (n_heap & 0x7fff));
const bool deleting_top= n_heap == ((n_heap & 0x8000)
? (rec_get_heap_no_new(rec) | 0x8000)
@@ -2480,20 +2481,20 @@ corrupted:
if (UNIV_UNLIKELY(!last_insert))
{
no_direction:
- *dir= (*dir & ~((1U << 3) - 1)) | PAGE_NO_DIRECTION;
+ *dir= static_cast<byte>((*dir & ~((1U << 3) - 1)) | PAGE_NO_DIRECTION);
memset(n_dir, 0, 2);
}
else if (block.frame + last_insert == prev_rec &&
(*dir & ((1U << 3) - 1)) != PAGE_LEFT)
{
- *dir= (*dir & ~((1U << 3) - 1)) | PAGE_RIGHT;
+ *dir= static_cast<byte>((*dir & ~((1U << 3) - 1)) | PAGE_RIGHT);
inc_dir:
mach_write_to_2(n_dir, mach_read_from_2(n_dir) + 1);
}
else if (next_rec == block.frame + last_insert &&
(*dir & ((1U << 3) - 1)) != PAGE_RIGHT)
{
- *dir= (*dir & ~((1U << 3) - 1)) | PAGE_LEFT;
+ *dir= static_cast<byte>((*dir & ~((1U << 3) - 1)) | PAGE_LEFT);
goto inc_dir;
}
else
@@ -2570,7 +2571,7 @@ corrupted:
uint16_t n= static_cast<uint16_t>(PAGE_NEW_INFIMUM + prev);
rec_t *prev_rec= block.frame + n;
- n+= mach_read_from_2(prev_rec - REC_NEXT);
+ n= static_cast<uint16_t>(n + mach_read_from_2(prev_rec - REC_NEXT));
if (!prev);
else if (UNIV_UNLIKELY(heap_bot + REC_N_NEW_EXTRA_BYTES > prev_rec ||
prev_rec > heap_top))
@@ -2589,7 +2590,7 @@ corrupted:
for (ulint ns= PAGE_DIR_SLOT_MAX_N_OWNED;
!(n_owned= rec_get_n_owned_new(owner_rec)); )
{
- n+= mach_read_from_2(owner_rec - REC_NEXT);
+ n= static_cast<uint16_t>(n + mach_read_from_2(owner_rec - REC_NEXT));
owner_rec= block.frame + n;
if (n == PAGE_NEW_SUPREMUM);
else if (UNIV_UNLIKELY(heap_bot + REC_N_NEW_EXTRA_BYTES > owner_rec ||
@@ -2643,7 +2644,7 @@ corrupted:
goto corrupted;
if ((n= mach_read_from_2(free_rec - REC_NEXT)) != 0)
{
- n+= static_cast<uint16_t>(free_rec - block.frame);
+ n= static_cast<uint16_t>(n + free_rec - block.frame);
if (UNIV_UNLIKELY(n < PAGE_NEW_SUPREMUM_END + REC_N_NEW_EXTRA_BYTES ||
heap_top < block.frame + n))
goto corrupted;
@@ -2708,20 +2709,20 @@ corrupted:
if (UNIV_UNLIKELY(!last_insert))
{
no_direction:
- *dir= (*dir & ~((1U << 3) - 1)) | PAGE_NO_DIRECTION;
+ *dir= static_cast<byte>((*dir & ~((1U << 3) - 1)) | PAGE_NO_DIRECTION);
memset(n_dir, 0, 2);
}
else if (block.frame + last_insert == prev_rec &&
(*dir & ((1U << 3) - 1)) != PAGE_LEFT)
{
- *dir= (*dir & ~((1U << 3) - 1)) | PAGE_RIGHT;
+ *dir= static_cast<byte>((*dir & ~((1U << 3) - 1)) | PAGE_RIGHT);
inc_dir:
mach_write_to_2(n_dir, mach_read_from_2(n_dir) + 1);
}
else if (next_rec == block.frame + last_insert &&
(*dir & ((1U << 3) - 1)) != PAGE_RIGHT)
{
- *dir= (*dir & ~((1U << 3) - 1)) | PAGE_LEFT;
+ *dir= static_cast<byte>((*dir & ~((1U << 3) - 1)) | PAGE_LEFT);
goto inc_dir;
}
else
@@ -2864,7 +2865,7 @@ corrupted:
rec_t *prev_rec= block.frame + n;
if (UNIV_UNLIKELY(prev_rec > slot))
goto corrupted;
- n+= mach_read_from_2(prev_rec - REC_NEXT);
+ n= static_cast<uint16_t>(n + mach_read_from_2(prev_rec - REC_NEXT));
rec_t *rec= block.frame + n;
if (UNIV_UNLIKELY(n < PAGE_NEW_SUPREMUM_END + REC_N_NEW_EXTRA_BYTES ||
slot < rec))
@@ -2873,7 +2874,7 @@ corrupted:
if (UNIV_UNLIKELY(n < PAGE_NEW_SUPREMUM_END + extra_size ||
slot < rec + data_size))
goto corrupted;
- n+= mach_read_from_2(rec - REC_NEXT);
+ n= static_cast<uint16_t>(n + mach_read_from_2(rec - REC_NEXT));
rec_t *next= block.frame + n;
if (n == PAGE_NEW_SUPREMUM);
else if (UNIV_UNLIKELY(n < PAGE_NEW_SUPREMUM_END + REC_N_NEW_EXTRA_BYTES ||
@@ -2885,7 +2886,7 @@ corrupted:
ulint slot_owned;
for (ulint i= n_recs; !(slot_owned= rec_get_n_owned_new(s)); )
{
- n+= mach_read_from_2(s - REC_NEXT);
+ n= static_cast<uint16_t>(n + mach_read_from_2(s - REC_NEXT));
s= block.frame + n;
if (n == PAGE_NEW_SUPREMUM);
else if (UNIV_UNLIKELY(n < PAGE_NEW_SUPREMUM_END + REC_N_NEW_EXTRA_BYTES ||