Add -Wconversion to clang builds

MSVC has strong opinions on implicit conversions as used in CI, while Clang both
locally and in CI has weaker opinions.  In an effort to avoid subsequent
roundtrips through CI, make clang more strict.  Adding -Wconversion definitely
increases the strength of clang's opinions, apparently to include frowning on
some that even MSVC considers OK, so go make explicit the current implicit
behavior.
This commit is contained in:
Nathaniel Filardo
2021-02-24 12:54:14 +00:00
committed by Matthew Parkinson
parent 8840b386bc
commit 6259457790
8 changed files with 30 additions and 25 deletions

View File

@@ -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()

View File

@@ -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();

View File

@@ -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<double>(duration)) /
static_cast<double>(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<size_t>(online_average * multiplier);
size_t average =
static_cast<size_t>(online_average * static_cast<double>(multiplier));
csv << average << (slab_multiplier - average) * slab_count.max
<< csv.endl;

View File

@@ -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<uint8_t>(CMLargeRangeMin + i), run);
ss = ss + SUPERSLAB_SIZE * run;

View File

@@ -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");
}
}

View File

@@ -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<true>(large_class);
void* oe_end = (uint8_t*)oe_base + size;
PALOpenEnclave::setup_initial_range(oe_base, oe_end);

View File

@@ -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);

View File

@@ -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<true>(large_class);
void* oe_end = (uint8_t*)oe_base + size;
oe_allocator_init(oe_base, oe_end);