Skip to content

Commit da61b0d

Browse files
committed
Revert "[libc] Enable -Wconversion for tests. (#127523)"
This reverts commit 1e6e845 because it changed the 1st parameter of adjust() to be unsigned, but libc itself calls adjust() with a negative argument in align_backward() in op_generic.h.
1 parent 46236f4 commit da61b0d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+183
-245
lines changed

libc/cmake/modules/LLVMLibCTestRules.cmake

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ function(_get_common_test_compile_options output_var c_test flags)
3636
if(NOT LIBC_WNO_ERROR)
3737
# list(APPEND compile_options "-Werror")
3838
endif()
39-
list(APPEND compile_options "-Wconversion")
39+
# list(APPEND compile_options "-Wconversion")
40+
# list(APPEND compile_options "-Wno-sign-conversion")
4041
list(APPEND compile_options "-Wimplicit-fallthrough")
4142
list(APPEND compile_options "-Wwrite-strings")
4243
# Silence this warning because _Complex is a part of C99.

libc/src/__support/CPP/bit.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ countr_zero(T value) {
101101
shift >>= 1;
102102
mask >>= shift;
103103
}
104-
return static_cast<int>(zero_bits);
104+
return zero_bits;
105105
}
106106
#if __has_builtin(__builtin_ctzs)
107107
ADD_SPECIALIZATION(countr_zero, unsigned short, __builtin_ctzs)
@@ -140,7 +140,7 @@ countl_zero(T value) {
140140
else
141141
zero_bits |= shift;
142142
}
143-
return static_cast<int>(zero_bits);
143+
return zero_bits;
144144
}
145145
#if __has_builtin(__builtin_clzs)
146146
ADD_SPECIALIZATION(countl_zero, unsigned short, __builtin_clzs)
@@ -226,7 +226,7 @@ rotr(T value, int rotate);
226226
template <typename T>
227227
[[nodiscard]] LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_unsigned_v<T>, T>
228228
rotl(T value, int rotate) {
229-
constexpr int N = cpp::numeric_limits<T>::digits;
229+
constexpr unsigned N = cpp::numeric_limits<T>::digits;
230230
rotate = rotate % N;
231231
if (!rotate)
232232
return value;
@@ -238,7 +238,7 @@ rotl(T value, int rotate) {
238238
template <typename T>
239239
[[nodiscard]] LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_unsigned_v<T>, T>
240240
rotr(T value, int rotate) {
241-
constexpr int N = cpp::numeric_limits<T>::digits;
241+
constexpr unsigned N = cpp::numeric_limits<T>::digits;
242242
rotate = rotate % N;
243243
if (!rotate)
244244
return value;

libc/src/__support/CPP/span.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include <stddef.h> // For size_t
1212

1313
#include "array.h" // For array
14-
#include "limits.h"
1514
#include "src/__support/macros/config.h"
1615
#include "type_traits.h" // For remove_cv_t, enable_if_t, is_same_v, is_const_v
1716

@@ -49,8 +48,7 @@ template <typename T> class span {
4948
using const_reference = const T &;
5049
using iterator = T *;
5150

52-
LIBC_INLINE_VAR static constexpr size_type dynamic_extent =
53-
cpp::numeric_limits<size_type>::max();
51+
LIBC_INLINE_VAR static constexpr size_type dynamic_extent = -1;
5452

5553
LIBC_INLINE constexpr span() : span_data(nullptr), span_size(0) {}
5654

@@ -60,7 +58,7 @@ template <typename T> class span {
6058
: span_data(first), span_size(count) {}
6159

6260
LIBC_INLINE constexpr span(pointer first, pointer end)
63-
: span_data(first), span_size(static_cast<size_t>(end - first)) {}
61+
: span_data(first), span_size(end - first) {}
6462

6563
template <typename U, size_t N,
6664
cpp::enable_if_t<is_compatible_v<U>, bool> = true>

libc/src/__support/CPP/string.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ class string {
6767
: string(cstr, ::LIBC_NAMESPACE::internal::string_length(cstr)) {}
6868
LIBC_INLINE string(size_t size_, char value) {
6969
resize(size_);
70-
static_assert(sizeof(char) == sizeof(uint8_t));
71-
inline_memset((void *)buffer_, static_cast<uint8_t>(value), size_);
70+
inline_memset((void *)buffer_, value, size_);
7271
}
7372

7473
LIBC_INLINE string &operator=(const string &other) {

libc/src/__support/CPP/string_view.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_STRING_VIEW_H
1010
#define LLVM_LIBC_SRC___SUPPORT_CPP_STRING_VIEW_H
1111

12-
#include "limits.h"
1312
#include "src/__support/common.h"
1413
#include "src/__support/macros/config.h"
1514

@@ -41,7 +40,7 @@ class string_view {
4140
LIBC_INLINE static constexpr size_t length(const char *Str) {
4241
for (const char *End = Str;; ++End)
4342
if (*End == '\0')
44-
return static_cast<size_t>(End - Str);
43+
return End - Str;
4544
}
4645

4746
LIBC_INLINE bool equals(string_view Other) const {
@@ -62,8 +61,7 @@ class string_view {
6261

6362
// special value equal to the maximum value representable by the type
6463
// size_type.
65-
LIBC_INLINE_VAR static constexpr size_t npos =
66-
cpp::numeric_limits<size_t>::max();
64+
LIBC_INLINE_VAR static constexpr size_t npos = -1;
6765

6866
LIBC_INLINE constexpr string_view() : Data(nullptr), Len(0) {}
6967

libc/src/__support/FPUtil/FPBits.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,11 +247,11 @@ template <FPType fp_type> struct FPStorage : public FPLayout<fp_type> {
247247
using UP::UP;
248248

249249
LIBC_INLINE constexpr BiasedExponent(Exponent exp)
250-
: UP(static_cast<uint32_t>(static_cast<int32_t>(exp) + EXP_BIAS)) {}
250+
: UP(static_cast<int32_t>(exp) + EXP_BIAS) {}
251251

252252
// Cast operator to get convert from BiasedExponent to Exponent.
253253
LIBC_INLINE constexpr operator Exponent() const {
254-
return Exponent(static_cast<int32_t>(UP::value - EXP_BIAS));
254+
return Exponent(UP::value - EXP_BIAS);
255255
}
256256

257257
LIBC_INLINE constexpr BiasedExponent &operator++() {
@@ -686,7 +686,7 @@ struct FPRepImpl : public FPRepSem<fp_type, RetT> {
686686
}
687687

688688
LIBC_INLINE constexpr void set_biased_exponent(StorageType biased) {
689-
UP::set_biased_exponent(BiasedExponent(static_cast<uint32_t>(biased)));
689+
UP::set_biased_exponent(BiasedExponent((int32_t)biased));
690690
}
691691

692692
LIBC_INLINE constexpr int get_exponent() const {

libc/src/__support/FPUtil/NormalFloat.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ template <typename T> struct NormalFloat {
105105

106106
constexpr int SUBNORMAL_EXPONENT = -FPBits<T>::EXP_BIAS + 1;
107107
if (exponent < SUBNORMAL_EXPONENT) {
108-
unsigned shift = static_cast<unsigned>(SUBNORMAL_EXPONENT - exponent);
108+
unsigned shift = SUBNORMAL_EXPONENT - exponent;
109109
// Since exponent > subnormalExponent, shift is strictly greater than
110110
// zero.
111111
if (shift <= FPBits<T>::FRACTION_LEN + 1) {
@@ -160,7 +160,7 @@ template <typename T> struct NormalFloat {
160160
if (bits.is_subnormal()) {
161161
unsigned shift = evaluate_normalization_shift(bits.get_mantissa());
162162
mantissa = static_cast<StorageType>(bits.get_mantissa() << shift);
163-
exponent = 1 - FPBits<T>::EXP_BIAS - static_cast<int32_t>(shift);
163+
exponent = 1 - FPBits<T>::EXP_BIAS - shift;
164164
} else {
165165
exponent = bits.get_biased_exponent() - FPBits<T>::EXP_BIAS;
166166
mantissa = ONE | bits.get_mantissa();

libc/src/__support/FPUtil/aarch64/FEnvImpl.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ LIBC_INLINE int enable_except(int excepts) {
110110
(controlWord >> FEnv::ExceptionControlFlagsBitPosition) & 0x1F;
111111
controlWord |= (newExcepts << FEnv::ExceptionControlFlagsBitPosition);
112112
FEnv::writeControlWord(controlWord);
113-
return FEnv::exceptionStatusToMacro(static_cast<uint32_t>(oldExcepts));
113+
return FEnv::exceptionStatusToMacro(oldExcepts);
114114
}
115115

116116
LIBC_INLINE int disable_except(int excepts) {
@@ -120,12 +120,12 @@ LIBC_INLINE int disable_except(int excepts) {
120120
(controlWord >> FEnv::ExceptionControlFlagsBitPosition) & 0x1F;
121121
controlWord &= ~(disabledExcepts << FEnv::ExceptionControlFlagsBitPosition);
122122
FEnv::writeControlWord(controlWord);
123-
return FEnv::exceptionStatusToMacro(static_cast<uint32_t>(oldExcepts));
123+
return FEnv::exceptionStatusToMacro(oldExcepts);
124124
}
125125

126126
LIBC_INLINE int get_except() {
127127
uint32_t controlWord = FEnv::getControlWord();
128-
uint32_t enabledExcepts =
128+
int enabledExcepts =
129129
(controlWord >> FEnv::ExceptionControlFlagsBitPosition) & 0x1F;
130130
return FEnv::exceptionStatusToMacro(enabledExcepts);
131131
}
@@ -250,10 +250,8 @@ LIBC_INLINE int set_round(int mode) {
250250
}
251251

252252
uint32_t controlWord = FEnv::getControlWord();
253-
controlWord &=
254-
static_cast<uint32_t>(~(0x3 << FEnv::RoundingControlBitPosition));
255-
controlWord |=
256-
static_cast<uint32_t>(bitValue << FEnv::RoundingControlBitPosition);
253+
controlWord &= ~(0x3 << FEnv::RoundingControlBitPosition);
254+
controlWord |= (bitValue << FEnv::RoundingControlBitPosition);
257255
FEnv::writeControlWord(controlWord);
258256

259257
return 0;

libc/src/__support/FPUtil/aarch64/fenv_darwin_impl.h

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ struct FEnv {
6363
// __fpcr_flush_to_zero bit in the FPCR register. This control bit is
6464
// located in a different place from FE_FLUSHTOZERO status bit relative to
6565
// the other exceptions.
66-
LIBC_INLINE static uint32_t exception_value_from_status(uint32_t status) {
66+
LIBC_INLINE static uint32_t exception_value_from_status(int status) {
6767
return ((status & FE_INVALID) ? EX_INVALID : 0) |
6868
((status & FE_DIVBYZERO) ? EX_DIVBYZERO : 0) |
6969
((status & FE_OVERFLOW) ? EX_OVERFLOW : 0) |
@@ -72,7 +72,7 @@ struct FEnv {
7272
((status & FE_FLUSHTOZERO) ? EX_FLUSHTOZERO : 0);
7373
}
7474

75-
LIBC_INLINE static uint32_t exception_value_from_control(uint32_t control) {
75+
LIBC_INLINE static uint32_t exception_value_from_control(int control) {
7676
return ((control & __fpcr_trap_invalid) ? EX_INVALID : 0) |
7777
((control & __fpcr_trap_divbyzero) ? EX_DIVBYZERO : 0) |
7878
((control & __fpcr_trap_overflow) ? EX_OVERFLOW : 0) |
@@ -81,7 +81,7 @@ struct FEnv {
8181
((control & __fpcr_flush_to_zero) ? EX_FLUSHTOZERO : 0);
8282
}
8383

84-
LIBC_INLINE static uint32_t exception_value_to_status(uint32_t excepts) {
84+
LIBC_INLINE static int exception_value_to_status(uint32_t excepts) {
8585
return ((excepts & EX_INVALID) ? FE_INVALID : 0) |
8686
((excepts & EX_DIVBYZERO) ? FE_DIVBYZERO : 0) |
8787
((excepts & EX_OVERFLOW) ? FE_OVERFLOW : 0) |
@@ -90,7 +90,7 @@ struct FEnv {
9090
((excepts & EX_FLUSHTOZERO) ? FE_FLUSHTOZERO : 0);
9191
}
9292

93-
LIBC_INLINE static uint32_t exception_value_to_control(uint32_t excepts) {
93+
LIBC_INLINE static int exception_value_to_control(uint32_t excepts) {
9494
return ((excepts & EX_INVALID) ? __fpcr_trap_invalid : 0) |
9595
((excepts & EX_DIVBYZERO) ? __fpcr_trap_divbyzero : 0) |
9696
((excepts & EX_OVERFLOW) ? __fpcr_trap_overflow : 0) |
@@ -113,54 +113,48 @@ struct FEnv {
113113
};
114114

115115
LIBC_INLINE int enable_except(int excepts) {
116-
uint32_t new_excepts =
117-
FEnv::exception_value_from_status(static_cast<uint32_t>(excepts));
116+
uint32_t new_excepts = FEnv::exception_value_from_status(excepts);
118117
uint32_t control_word = FEnv::get_control_word();
119118
uint32_t old_excepts = FEnv::exception_value_from_control(control_word);
120119
if (new_excepts != old_excepts) {
121120
control_word |= FEnv::exception_value_to_control(new_excepts);
122121
FEnv::set_control_word(control_word);
123122
}
124-
return static_cast<int>(FEnv::exception_value_to_status(old_excepts));
123+
return FEnv::exception_value_to_status(old_excepts);
125124
}
126125

127126
LIBC_INLINE int disable_except(int excepts) {
128-
uint32_t disabled_excepts =
129-
FEnv::exception_value_from_status(static_cast<uint32_t>(excepts));
127+
uint32_t disabled_excepts = FEnv::exception_value_from_status(excepts);
130128
uint32_t control_word = FEnv::get_control_word();
131129
uint32_t old_excepts = FEnv::exception_value_from_control(control_word);
132130
control_word &= ~FEnv::exception_value_to_control(disabled_excepts);
133131
FEnv::set_control_word(control_word);
134-
return static_cast<int>(FEnv::exception_value_to_status(old_excepts));
132+
return FEnv::exception_value_to_status(old_excepts);
135133
}
136134

137135
LIBC_INLINE int get_except() {
138136
uint32_t control_word = FEnv::get_control_word();
139137
uint32_t enabled_excepts = FEnv::exception_value_from_control(control_word);
140-
return static_cast<int>(FEnv::exception_value_to_status(enabled_excepts));
138+
return FEnv::exception_value_to_status(enabled_excepts);
141139
}
142140

143141
LIBC_INLINE int clear_except(int excepts) {
144142
uint32_t status_word = FEnv::get_status_word();
145-
uint32_t except_value =
146-
FEnv::exception_value_from_status(static_cast<uint32_t>(excepts));
143+
uint32_t except_value = FEnv::exception_value_from_status(excepts);
147144
status_word &= ~FEnv::exception_value_to_status(except_value);
148145
FEnv::set_status_word(status_word);
149146
return 0;
150147
}
151148

152149
LIBC_INLINE int test_except(int excepts) {
153150
uint32_t statusWord = FEnv::get_status_word();
154-
uint32_t ex_value =
155-
FEnv::exception_value_from_status(static_cast<uint32_t>(excepts));
156-
return static_cast<int>(statusWord &
157-
FEnv::exception_value_to_status(ex_value));
151+
uint32_t ex_value = FEnv::exception_value_from_status(excepts);
152+
return statusWord & FEnv::exception_value_to_status(ex_value);
158153
}
159154

160155
LIBC_INLINE int set_except(int excepts) {
161156
uint32_t status_word = FEnv::get_status_word();
162-
uint32_t new_exceptions =
163-
FEnv::exception_value_from_status(static_cast<uint32_t>(excepts));
157+
uint32_t new_exceptions = FEnv::exception_value_from_status(excepts);
164158
status_word |= FEnv::exception_value_to_status(new_exceptions);
165159
FEnv::set_status_word(status_word);
166160
return 0;
@@ -180,8 +174,7 @@ LIBC_INLINE int raise_except(int excepts) {
180174
: "s0", "s1" /* s0 and s1 are clobbered */);
181175
};
182176

183-
uint32_t to_raise =
184-
FEnv::exception_value_from_status(static_cast<uint32_t>(excepts));
177+
uint32_t to_raise = FEnv::exception_value_from_status(excepts);
185178
int result = 0;
186179

187180
if (to_raise & FEnv::EX_INVALID) {
@@ -244,7 +237,7 @@ LIBC_INLINE int get_round() {
244237
}
245238

246239
LIBC_INLINE int set_round(int mode) {
247-
uint32_t bit_value;
240+
uint16_t bit_value;
248241
switch (mode) {
249242
case FE_TONEAREST:
250243
bit_value = FEnv::TONEAREST;
@@ -263,7 +256,7 @@ LIBC_INLINE int set_round(int mode) {
263256
}
264257

265258
uint32_t control_word = FEnv::get_control_word();
266-
control_word &= ~(0x3u << FEnv::ROUNDING_CONTROL_BIT_POSITION);
259+
control_word &= ~(0x3 << FEnv::ROUNDING_CONTROL_BIT_POSITION);
267260
control_word |= (bit_value << FEnv::ROUNDING_CONTROL_BIT_POSITION);
268261
FEnv::set_control_word(control_word);
269262

libc/src/__support/FPUtil/generic/sqrt_80_bit_long_double.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ namespace x86 {
2424
LIBC_INLINE void normalize(int &exponent,
2525
FPBits<long double>::StorageType &mantissa) {
2626
const unsigned int shift = static_cast<unsigned int>(
27-
static_cast<size_t>(cpp::countl_zero(static_cast<uint64_t>(mantissa))) -
27+
cpp::countl_zero(static_cast<uint64_t>(mantissa)) -
2828
(8 * sizeof(uint64_t) - 1 - FPBits<long double>::FRACTION_LEN));
2929
exponent -= shift;
3030
mantissa <<= shift;

libc/src/__support/OSUtil/darwin/io.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ namespace LIBC_NAMESPACE_DECL {
1717

1818
LIBC_INLINE void write_to_stderr(cpp::string_view msg) {
1919
LIBC_NAMESPACE::syscall_impl(4 /*SYS_write*/, 2 /* stderr */,
20-
reinterpret_cast<long>(msg.data()),
21-
static_cast<long>(msg.size()));
20+
reinterpret_cast<long>(msg.data()), msg.size());
2221
}
2322

2423
} // namespace LIBC_NAMESPACE_DECL

0 commit comments

Comments
 (0)