AK+Toolchain: Make char and wchar_t behave on AARCH64

By default char and wchar_t are unsigned on AARCH64. This fixes a
bunch of related compiler errors.
This commit is contained in:
Gunnar Beutner 2022-10-12 22:00:21 +02:00 committed by Linus Groh
parent 31bd5b1a02
commit a650c74b27
Notes: sideshowbarker 2024-07-17 18:49:10 +09:00
4 changed files with 29 additions and 10 deletions

View file

@ -274,6 +274,12 @@ template<>
struct __MakeUnsigned<bool> { struct __MakeUnsigned<bool> {
using Type = bool; using Type = bool;
}; };
#ifdef AK_ARCH_AARCH64
template<>
struct __MakeUnsigned<wchar_t> {
using Type = wchar_t;
};
#endif
template<typename T> template<typename T>
using MakeUnsigned = typename __MakeUnsigned<T>::Type; using MakeUnsigned = typename __MakeUnsigned<T>::Type;
@ -326,6 +332,12 @@ template<>
struct __MakeSigned<char> { struct __MakeSigned<char> {
using Type = char; using Type = char;
}; };
#ifdef AK_ARCH_AARCH64
template<>
struct __MakeSigned<wchar_t> {
using Type = void;
};
#endif
template<typename T> template<typename T>
using MakeSigned = typename __MakeSigned<T>::Type; using MakeSigned = typename __MakeSigned<T>::Type;

View file

@ -182,6 +182,11 @@ if (ENABLE_COMPILETIME_FORMAT_CHECK)
add_compile_definitions(ENABLE_COMPILETIME_FORMAT_CHECK) add_compile_definitions(ENABLE_COMPILETIME_FORMAT_CHECK)
endif() endif()
if("${SERENITY_ARCH}" STREQUAL "aarch64")
# FIXME: re-enable this warning
add_compile_options(-Wno-type-limits)
endif()
add_link_options(-Wno-unused-command-line-argument) add_link_options(-Wno-unused-command-line-argument)
include_directories(.) include_directories(.)

View file

@ -239,17 +239,17 @@ TEST_CASE(mbrtowc)
// Ensure that we can parse normal ASCII characters. // Ensure that we can parse normal ASCII characters.
ret = mbrtowc(&wc, "Hello", 5, &state); ret = mbrtowc(&wc, "Hello", 5, &state);
EXPECT_EQ(ret, 1ul); EXPECT_EQ(ret, 1ul);
EXPECT_EQ(wc, 'H'); EXPECT_EQ(wc, static_cast<wchar_t>('H'));
// Try two three-byte codepoints (™™), only one of which should be consumed. // Try two three-byte codepoints (™™), only one of which should be consumed.
ret = mbrtowc(&wc, "\xe2\x84\xa2\xe2\x84\xa2", 6, &state); ret = mbrtowc(&wc, "\xe2\x84\xa2\xe2\x84\xa2", 6, &state);
EXPECT_EQ(ret, 3ul); EXPECT_EQ(ret, 3ul);
EXPECT_EQ(wc, 0x2122); EXPECT_EQ(wc, static_cast<wchar_t>(0x2122));
// Try a null character, which should return 0 and reset the state to the initial state. // Try a null character, which should return 0 and reset the state to the initial state.
ret = mbrtowc(&wc, "\x00\x00", 2, &state); ret = mbrtowc(&wc, "\x00\x00", 2, &state);
EXPECT_EQ(ret, 0ul); EXPECT_EQ(ret, 0ul);
EXPECT_EQ(wc, 0); EXPECT_EQ(wc, static_cast<wchar_t>(0));
EXPECT_NE(mbsinit(&state), 0); EXPECT_NE(mbsinit(&state), 0);
// Try an incomplete multibyte character. // Try an incomplete multibyte character.
@ -262,7 +262,7 @@ TEST_CASE(mbrtowc)
// Finish the previous multibyte character. // Finish the previous multibyte character.
ret = mbrtowc(&wc, "\xa2", 1, &state); ret = mbrtowc(&wc, "\xa2", 1, &state);
EXPECT_EQ(ret, 1ul); EXPECT_EQ(ret, 1ul);
EXPECT_EQ(wc, 0x2122); EXPECT_EQ(wc, static_cast<wchar_t>(0x2122));
// Try an invalid multibyte sequence. // Try an invalid multibyte sequence.
// Reset the state afterwards because the effects are undefined. // Reset the state afterwards because the effects are undefined.
@ -550,17 +550,17 @@ TEST_CASE(mbtowc)
// Ensure that we can parse normal ASCII characters. // Ensure that we can parse normal ASCII characters.
ret = mbtowc(&wc, "Hello", 5); ret = mbtowc(&wc, "Hello", 5);
EXPECT_EQ(ret, 1); EXPECT_EQ(ret, 1);
EXPECT_EQ(wc, 'H'); EXPECT_EQ(wc, static_cast<wchar_t>('H'));
// Try two three-byte codepoints (™™), only one of which should be consumed. // Try two three-byte codepoints (™™), only one of which should be consumed.
ret = mbtowc(&wc, "\xe2\x84\xa2\xe2\x84\xa2", 6); ret = mbtowc(&wc, "\xe2\x84\xa2\xe2\x84\xa2", 6);
EXPECT_EQ(ret, 3); EXPECT_EQ(ret, 3);
EXPECT_EQ(wc, 0x2122); EXPECT_EQ(wc, static_cast<wchar_t>(0x2122));
// Try a null character, which should return 0. // Try a null character, which should return 0.
ret = mbtowc(&wc, "\x00\x00", 2); ret = mbtowc(&wc, "\x00\x00", 2);
EXPECT_EQ(ret, 0); EXPECT_EQ(ret, 0);
EXPECT_EQ(wc, 0); EXPECT_EQ(wc, static_cast<wchar_t>(0));
// Try an incomplete multibyte character. // Try an incomplete multibyte character.
ret = mbtowc(&wc, "\xe2\x84", 2); ret = mbtowc(&wc, "\xe2\x84", 2);

View file

@ -270,9 +270,11 @@ public:
return m_view.visit( return m_view.visit(
[&](StringView view) -> u32 { [&](StringView view) -> u32 {
auto ch = view[index]; auto ch = view[index];
if (ch < 0) if constexpr (IsSigned<char>) {
return 256u + ch; if (ch < 0)
return ch; return 256u + ch;
return ch;
}
}, },
[&](Utf32View const& view) -> u32 { return view[index]; }, [&](Utf32View const& view) -> u32 { return view[index]; },
[&](Utf16View const& view) -> u32 { return view.code_point_at(index); }, [&](Utf16View const& view) -> u32 { return view.code_point_at(index); },