Skip to content

Commit badca59

Browse files
-Wimplicit-int-conversion
1 parent 3c023ed commit badca59

File tree

13 files changed

+46
-46
lines changed

13 files changed

+46
-46
lines changed

libc/src/__support/CPP/bit.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ rotl(T value, int rotate) {
232232
return value;
233233
if (rotate < 0)
234234
return cpp::rotr<T>(value, -rotate);
235-
return (value << rotate) | (value >> (N - rotate));
235+
return static_cast<T>((value << rotate) | (value >> (N - rotate)));
236236
}
237237

238238
template <typename T>
@@ -244,7 +244,7 @@ rotr(T value, int rotate) {
244244
return value;
245245
if (rotate < 0)
246246
return cpp::rotl<T>(value, -rotate);
247-
return (value >> rotate) | (value << (N - rotate));
247+
return static_cast<T>((value >> rotate) | (value << (N - rotate)));
248248
}
249249

250250
// TODO: Do we need this function at all? How is it different from

libc/src/string/memory_utils/utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ LIBC_INLINE void store_aligned(ValueType value, Ptr dst) {
263263
static_assert(sizeof(ValueType) >= (sizeof(T) + ... + sizeof(TS)));
264264
constexpr size_t SHIFT = sizeof(T) * 8;
265265
if constexpr (Endian::IS_LITTLE) {
266-
store<T>(assume_aligned<sizeof(T)>(dst), value & ~T(0));
266+
store<T>(assume_aligned<sizeof(T)>(dst), static_cast<T>(value & ~T(0)));
267267
if constexpr (sizeof...(TS) > 0)
268268
store_aligned<ValueType, TS...>(value >> SHIFT, dst + sizeof(T));
269269
} else if constexpr (Endian::IS_BIG) {

libc/test/include/stdbit_stub.h

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
#include <stdbool.h> // bool in C
1818

1919
#define STDBIT_STUB_FUNCTION(FUNC_NAME, LEADING_VAL) \
20-
unsigned FUNC_NAME##_uc(unsigned char x) { return LEADING_VAL##AU; } \
21-
unsigned FUNC_NAME##_us(unsigned short x) { return LEADING_VAL##BU; } \
22-
unsigned FUNC_NAME##_ui(unsigned int x) { return LEADING_VAL##CU; } \
23-
unsigned FUNC_NAME##_ul(unsigned long x) { return LEADING_VAL##DU; } \
24-
unsigned FUNC_NAME##_ull(unsigned long long x) { return LEADING_VAL##EU; }
20+
unsigned FUNC_NAME##_uc(unsigned char) { return LEADING_VAL##AU; } \
21+
unsigned FUNC_NAME##_us(unsigned short) { return LEADING_VAL##BU; } \
22+
unsigned FUNC_NAME##_ui(unsigned int) { return LEADING_VAL##CU; } \
23+
unsigned FUNC_NAME##_ul(unsigned long) { return LEADING_VAL##DU; } \
24+
unsigned FUNC_NAME##_ull(unsigned long long) { return LEADING_VAL##EU; }
2525

2626
__BEGIN_C_DECLS
2727

@@ -36,24 +36,24 @@ STDBIT_STUB_FUNCTION(stdc_first_trailing_one, 0x1)
3636
STDBIT_STUB_FUNCTION(stdc_count_zeros, 0x2)
3737
STDBIT_STUB_FUNCTION(stdc_count_ones, 0x3)
3838

39-
bool stdc_has_single_bit_uc(unsigned char x) { return false; }
40-
bool stdc_has_single_bit_us(unsigned short x) { return false; }
41-
bool stdc_has_single_bit_ui(unsigned x) { return false; }
42-
bool stdc_has_single_bit_ul(unsigned long x) { return false; }
43-
bool stdc_has_single_bit_ull(unsigned long long x) { return false; }
39+
bool stdc_has_single_bit_uc(unsigned char) { return false; }
40+
bool stdc_has_single_bit_us(unsigned short) { return false; }
41+
bool stdc_has_single_bit_ui(unsigned) { return false; }
42+
bool stdc_has_single_bit_ul(unsigned long) { return false; }
43+
bool stdc_has_single_bit_ull(unsigned long long) { return false; }
4444

4545
STDBIT_STUB_FUNCTION(stdc_bit_width, 0x4)
4646

47-
unsigned char stdc_bit_floor_uc(unsigned char x) { return 0x5AU; }
48-
unsigned short stdc_bit_floor_us(unsigned short x) { return 0x5BU; }
49-
unsigned stdc_bit_floor_ui(unsigned x) { return 0x5CU; }
50-
unsigned long stdc_bit_floor_ul(unsigned long x) { return 0x5DUL; }
51-
unsigned long long stdc_bit_floor_ull(unsigned long long x) { return 0x5EULL; }
52-
53-
unsigned char stdc_bit_ceil_uc(unsigned char x) { return 0x6AU; }
54-
unsigned short stdc_bit_ceil_us(unsigned short x) { return 0x6BU; }
55-
unsigned stdc_bit_ceil_ui(unsigned x) { return 0x6CU; }
56-
unsigned long stdc_bit_ceil_ul(unsigned long x) { return 0x6DUL; }
57-
unsigned long long stdc_bit_ceil_ull(unsigned long long x) { return 0x6EULL; }
47+
unsigned char stdc_bit_floor_uc(unsigned char) { return 0x5AU; }
48+
unsigned short stdc_bit_floor_us(unsigned short) { return 0x5BU; }
49+
unsigned stdc_bit_floor_ui(unsigned) { return 0x5CU; }
50+
unsigned long stdc_bit_floor_ul(unsigned long) { return 0x5DUL; }
51+
unsigned long long stdc_bit_floor_ull(unsigned long long) { return 0x5EULL; }
52+
53+
unsigned char stdc_bit_ceil_uc(unsigned char) { return 0x6AU; }
54+
unsigned short stdc_bit_ceil_us(unsigned short) { return 0x6BU; }
55+
unsigned stdc_bit_ceil_ui(unsigned) { return 0x6CU; }
56+
unsigned long stdc_bit_ceil_ul(unsigned long) { return 0x6DUL; }
57+
unsigned long long stdc_bit_ceil_ull(unsigned long long) { return 0x6EULL; }
5858

5959
__END_C_DECLS

libc/test/src/__support/CPP/bit_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ TYPED_TEST(LlvmLibcBitTest, HasSingleBit, UnsignedTypes) {
4141
constexpr auto LSB = T(1);
4242
constexpr auto MSB = T(~(ALL_ONES >> 1));
4343
for (T value = 1; value; value <<= 1) {
44-
auto two_bits_value = value | ((value <= MIDPOINT) ? MSB : LSB);
44+
T two_bits_value = value | ((value <= MIDPOINT) ? MSB : LSB);
4545
EXPECT_FALSE(has_single_bit<T>(two_bits_value));
4646
}
4747
}

libc/test/src/__support/CPP/integer_sequence_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ TEST(LlvmLibcIntegerSequencetTest, Basic) {
2323
(is_same_v<ULLSeq, make_integer_sequence<unsigned long long, 4>>));
2424
}
2525

26-
template <typename T, T... Ts> bool checkArray(integer_sequence<T, Ts...> seq) {
26+
template <typename T, T... Ts> bool checkArray(integer_sequence<T, Ts...> /*seq*/) {
2727
T arr[sizeof...(Ts)]{Ts...};
2828

2929
for (T i = 0; i < static_cast<T>(sizeof...(Ts)); i++)

libc/test/src/__support/arg_list_test.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ long int check_primitives(int first, ...) {
7272
count += args.next_var<unsigned long>();
7373
count += args.next_var<long long>();
7474
count += args.next_var<unsigned long long>();
75-
count += args.next_var<double>();
76-
count += args.next_var<double>();
77-
count += args.next_var<long double>();
75+
count += static_cast<long>(args.next_var<double>());
76+
count += static_cast<long>(args.next_var<double>());
77+
count += static_cast<long>(args.next_var<long double>());
7878
count += *args.next_var<int *>();
7979
return count;
8080
}
@@ -112,7 +112,7 @@ long int check_struct_type(int first, ...) {
112112

113113
S s = args.next_var<S>();
114114
int last = args.next_var<int>();
115-
return s.c + s.s + s.i + s.l + s.f + s.d + last;
115+
return s.c + s.s + s.i + s.l + static_cast<long>(s.f) + static_cast<long>(s.d) + last;
116116
}
117117

118118
TEST(LlvmLibcArgListTest, TestStructTypes) {

libc/test/src/__support/big_int_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ TYPED_TEST(LlvmLibcUIntClassTest, CountBits, Types) {
197197
for (size_t i = 0; i < T::BITS; ++i) {
198198
const auto l_one = T::all_ones() << i; // 0b111...000
199199
const auto r_one = T::all_ones() >> i; // 0b000...111
200-
const int zeros = i;
200+
const int zeros = static_cast<int>(i);
201201
const int ones = T::BITS - zeros;
202202
ASSERT_EQ(cpp::countr_one(r_one), ones);
203203
ASSERT_EQ(cpp::countl_one(l_one), ones);

libc/test/src/__support/hash_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ TEST(LlvmLibcHashTest, Avalanche) {
7878
}
7979
for (size_t i = 0; i < sz; ++i) {
8080
for (size_t j = 0; j < 8; ++j) {
81-
uint8_t mask = 1 << j;
81+
uint8_t mask = static_cast<uint8_t>(1 << j);
8282
mem.data[i] ^= mask;
8383
{
8484
LIBC_NAMESPACE::internal::HashState state{0xabcdef1234567890};

libc/test/src/__support/math_extras_test.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,27 +73,27 @@ TEST(LlvmLibcBlockMathExtrasTest, mask_trailing_ones) {
7373
TYPED_TEST(LlvmLibcBitTest, FirstLeadingZero, UnsignedTypesNoBigInt) {
7474
EXPECT_EQ(first_leading_zero<T>(cpp::numeric_limits<T>::max()), 0);
7575
for (int i = 0U; i != cpp::numeric_limits<T>::digits; ++i)
76-
EXPECT_EQ(first_leading_zero<T>(~(T(1) << i)),
76+
EXPECT_EQ(first_leading_zero<T>(static_cast<T>(~(T(1) << i))),
7777
cpp::numeric_limits<T>::digits - i);
7878
}
7979

8080
TYPED_TEST(LlvmLibcBitTest, FirstLeadingOne, UnsignedTypesNoBigInt) {
8181
EXPECT_EQ(first_leading_one<T>(static_cast<T>(0)), 0);
8282
for (int i = 0U; i != cpp::numeric_limits<T>::digits; ++i)
83-
EXPECT_EQ(first_leading_one<T>(T(1) << i),
83+
EXPECT_EQ(first_leading_one<T>(static_cast<T>(T(1) << i)),
8484
cpp::numeric_limits<T>::digits - i);
8585
}
8686

8787
TYPED_TEST(LlvmLibcBitTest, FirstTrailingZero, UnsignedTypesNoBigInt) {
8888
EXPECT_EQ(first_trailing_zero<T>(cpp::numeric_limits<T>::max()), 0);
8989
for (int i = 0U; i != cpp::numeric_limits<T>::digits; ++i)
90-
EXPECT_EQ(first_trailing_zero<T>(~(T(1) << i)), i + 1);
90+
EXPECT_EQ(first_trailing_zero<T>(static_cast<T>(~(T(1) << i))), i + 1);
9191
}
9292

9393
TYPED_TEST(LlvmLibcBitTest, FirstTrailingOne, UnsignedTypesNoBigInt) {
9494
EXPECT_EQ(first_trailing_one<T>(cpp::numeric_limits<T>::max()), 0);
9595
for (int i = 0U; i != cpp::numeric_limits<T>::digits; ++i)
96-
EXPECT_EQ(first_trailing_one<T>(T(1) << i), i + 1);
96+
EXPECT_EQ(first_trailing_one<T>(static_cast<T>(T(1) << i)), i + 1);
9797
}
9898

9999
TYPED_TEST(LlvmLibcBitTest, CountZeros, UnsignedTypesNoBigInt) {

libc/test/src/math/FModTest.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class FmodTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
5454

5555
// fmod (+inf, y) == aNaN plus invalid exception.
5656
TEST_SPECIAL(inf, 3.0, aNaN, true, FE_INVALID);
57-
TEST_SPECIAL(inf, -1.1L, aNaN, true, FE_INVALID);
57+
TEST_SPECIAL(inf, static_cast<T>(-1.1L), aNaN, true, FE_INVALID);
5858
TEST_SPECIAL(inf, 0.0, aNaN, true, FE_INVALID);
5959
TEST_SPECIAL(inf, neg_zero, aNaN, true, FE_INVALID);
6060
TEST_SPECIAL(inf, min_denormal, aNaN, true, FE_INVALID);
@@ -65,7 +65,7 @@ class FmodTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
6565

6666
// fmod (-inf, y) == aNaN plus invalid exception.
6767
TEST_SPECIAL(neg_inf, 3.0, aNaN, true, FE_INVALID);
68-
TEST_SPECIAL(neg_inf, -1.1L, aNaN, true, FE_INVALID);
68+
TEST_SPECIAL(neg_inf, static_cast<T>(-1.1L), aNaN, true, FE_INVALID);
6969
TEST_SPECIAL(neg_inf, 0.0, aNaN, true, FE_INVALID);
7070
TEST_SPECIAL(neg_inf, neg_zero, aNaN, true, FE_INVALID);
7171
TEST_SPECIAL(neg_inf, min_denormal, aNaN, true, FE_INVALID);
@@ -76,7 +76,7 @@ class FmodTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
7676

7777
// fmod (x, +0) == aNaN plus invalid exception.
7878
TEST_SPECIAL(3.0, 0.0, aNaN, true, FE_INVALID);
79-
TEST_SPECIAL(-1.1L, 0.0, aNaN, true, FE_INVALID);
79+
TEST_SPECIAL(static_cast<T>(-1.1L), 0.0, aNaN, true, FE_INVALID);
8080
TEST_SPECIAL(0.0, 0.0, aNaN, true, FE_INVALID);
8181
TEST_SPECIAL(neg_zero, 0.0, aNaN, true, FE_INVALID);
8282
TEST_SPECIAL(min_denormal, 0.0, aNaN, true, FE_INVALID);
@@ -85,7 +85,7 @@ class FmodTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
8585

8686
// fmod (x, -0) == aNaN plus invalid exception.
8787
TEST_SPECIAL(3.0, neg_zero, aNaN, true, FE_INVALID);
88-
TEST_SPECIAL(-1.1L, neg_zero, aNaN, true, FE_INVALID);
88+
TEST_SPECIAL(static_cast<T>(-1.1L), neg_zero, aNaN, true, FE_INVALID);
8989
TEST_SPECIAL(0.0, neg_zero, aNaN, true, FE_INVALID);
9090
TEST_SPECIAL(neg_zero, neg_zero, aNaN, true, FE_INVALID);
9191
TEST_SPECIAL(min_denormal, neg_zero, aNaN, true, FE_INVALID);

0 commit comments

Comments
 (0)