diff --git a/CMakeLists.txt b/CMakeLists.txt index 3fd0625..693b82a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -54,7 +54,7 @@ macro(warnings_high) add_compile_options(/WX /wd4127 /wd4324 /wd4201) else() if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") - add_compile_options(-Wsign-conversion) + add_compile_options(-Wsign-conversion -Wconversion) endif () add_compile_options(-Wall -Wextra -Werror -Wundef) endif() diff --git a/src/mem/alloc.h b/src/mem/alloc.h index 83398c1..8542bf5 100644 --- a/src/mem/alloc.h +++ b/src/mem/alloc.h @@ -369,7 +369,7 @@ namespace snmalloc error("Not allocated by this allocator"); } - large_dealloc(p, 1ULL << size); + large_dealloc(p, bits::one_at_bit(size)); #endif } @@ -429,9 +429,9 @@ namespace snmalloc if constexpr (location == Start) return ss; else if constexpr (location == End) - return pointer_offset(ss, (1ULL << size) - 1ULL); + return pointer_offset(ss, (bits::one_at_bit(size)) - 1); else - return pointer_offset(ss, 1ULL << size); + return pointer_offset(ss, bits::one_at_bit(size)); #endif } @@ -472,7 +472,7 @@ namespace snmalloc if (likely(size != 0)) { - return 1ULL << size; + return bits::one_at_bit(size); } return alloc_size_error(); diff --git a/src/mem/allocstats.h b/src/mem/allocstats.h index d6aae6a..488493f 100644 --- a/src/mem/allocstats.h +++ b/src/mem/allocstats.h @@ -94,7 +94,9 @@ namespace snmalloc if (ticks == 0) online_average = occupancy; else - online_average += ((occupancy - online_average) * duration) / ticks; + online_average += + ((occupancy - online_average) * static_cast(duration)) / + static_cast(ticks); ticks += duration; } @@ -109,7 +111,8 @@ namespace snmalloc // Keep in sync with header lower down count.print(csv, multiplier); slab_count.print(csv, slab_multiplier); - size_t average = static_cast(online_average * multiplier); + size_t average = + static_cast(online_average * static_cast(multiplier)); csv << average << (slab_multiplier - average) * slab_count.max << csv.endl; diff --git a/src/mem/chunkmap.h b/src/mem/chunkmap.h index 343e366..cd37822 100644 --- a/src/mem/chunkmap.h +++ b/src/mem/chunkmap.h @@ -230,7 +230,7 @@ namespace snmalloc auto ss = address_cast(p) + SUPERSLAB_SIZE; for (size_t i = 0; i < size_bits - SUPERSLAB_BITS; i++) { - size_t run = 1ULL << i; + size_t run = bits::one_at_bit(i); PagemapProvider::pagemap().set_range( ss, static_cast(CMLargeRangeMin + i), run); ss = ss + SUPERSLAB_SIZE * run; diff --git a/src/test/func/first_operation/first_operation.cc b/src/test/func/first_operation/first_operation.cc index 6387eef..05092f1 100644 --- a/src/test/func/first_operation/first_operation.cc +++ b/src/test/func/first_operation/first_operation.cc @@ -194,18 +194,20 @@ int main(int, char**) printf("\n"); for (size_t exp = 1; exp < snmalloc::SUPERSLAB_BITS; exp++) { - f(1ULL << exp); - f(3ULL << exp); - f(5ULL << exp); - f(7ULL << exp); - f((1ULL << exp) + 1); - f((3ULL << exp) + 1); - f((5ULL << exp) + 1); - f((7ULL << exp) + 1); - f((1ULL << exp) - 1); - f((3ULL << exp) - 1); - f((5ULL << exp) - 1); - f((7ULL << exp) - 1); + auto shifted = [exp](size_t v) { return v << exp; }; + + f(shifted(1)); + f(shifted(3)); + f(shifted(5)); + f(shifted(7)); + f(shifted(1) + 1); + f(shifted(3) + 1); + f(shifted(5) + 1); + f(shifted(7) + 1); + f(shifted(1) - 1); + f(shifted(3) - 1); + f(shifted(5) - 1); + f(shifted(7) - 1); printf("\n"); } } diff --git a/src/test/func/fixed_region/fixed_region.cc b/src/test/func/fixed_region/fixed_region.cc index 5fba76a..87b6479 100644 --- a/src/test/func/fixed_region/fixed_region.cc +++ b/src/test/func/fixed_region/fixed_region.cc @@ -30,7 +30,7 @@ int main() // It is also large enough for the example to run in. // For 1MiB superslabs, SUPERSLAB_BITS + 4 is not big enough for the example. size_t large_class = 28 - SUPERSLAB_BITS; - size_t size = 1ULL << (SUPERSLAB_BITS + large_class); + size_t size = bits::one_at_bit(SUPERSLAB_BITS + large_class); void* oe_base = mp.reserve(large_class); void* oe_end = (uint8_t*)oe_base + size; PALOpenEnclave::setup_initial_range(oe_base, oe_end); diff --git a/src/test/func/malloc/malloc.cc b/src/test/func/malloc/malloc.cc index b206cd5..a468ebb 100644 --- a/src/test/func/malloc/malloc.cc +++ b/src/test/func/malloc/malloc.cc @@ -129,7 +129,7 @@ int main(int argc, char** argv) for (sizeclass_t sc = 0; sc < (SUPERSLAB_BITS + 4); sc++) { - const size_t size = 1ULL << sc; + const size_t size = bits::one_at_bit(sc); printf("malloc: %zu\n", size); check_result(size, 1, our_malloc(size), SUCCESS, false); check_result(size + 1, 1, our_malloc(size + 1), SUCCESS, false); @@ -170,14 +170,14 @@ int main(int argc, char** argv) for (sizeclass_t sc = 0; sc < (SUPERSLAB_BITS + 4); sc++) { - const size_t size = 1ULL << sc; + const size_t size = bits::one_at_bit(sc); test_realloc(our_malloc(size), size, SUCCESS, false); test_realloc(our_malloc(size), 0, SUCCESS, true); test_realloc(nullptr, size, SUCCESS, false); test_realloc(our_malloc(size), (size_t)-1, ENOMEM, true); for (sizeclass_t sc2 = 0; sc2 < (SUPERSLAB_BITS + 4); sc2++) { - const size_t size2 = 1ULL << sc2; + const size_t size2 = bits::one_at_bit(sc2); printf("size1: %zu, size2:%zu\n", size, size2); test_realloc(our_malloc(size), size2, SUCCESS, false); test_realloc(our_malloc(size + 1), size2, SUCCESS, false); diff --git a/src/test/func/two_alloc_types/main.cc b/src/test/func/two_alloc_types/main.cc index 1ef9d1c..4ce2154 100644 --- a/src/test/func/two_alloc_types/main.cc +++ b/src/test/func/two_alloc_types/main.cc @@ -39,7 +39,7 @@ int main() // It is also large enough for the example to run in. // For 1MiB superslabs, SUPERSLAB_BITS + 2 is not big enough for the example. size_t large_class = 26 - SUPERSLAB_BITS; - size_t size = 1ULL << (SUPERSLAB_BITS + large_class); + size_t size = bits::one_at_bit(SUPERSLAB_BITS + large_class); void* oe_base = mp.reserve(large_class); void* oe_end = (uint8_t*)oe_base + size; oe_allocator_init(oe_base, oe_end);