Everywhere: Stop building with -fsigned-char

Ports aren't guaranteed to compile with `-fsigned-char`, resulting in
them using a different incompatible ABI when using serenity libraries.
I think we should rather follow the target architecture ABI than
assuming that `char` is signed.

Building without `-fsigned-char` only required a couple of small changes
to prevent -Wtype-limits warnings.
This commit is contained in:
Sönke Holz
2026-02-05 12:39:19 +01:00
committed by Tim Schumacher
parent 322e6575de
commit 52a88a8ea8
9 changed files with 5 additions and 24 deletions

View File

@@ -307,7 +307,7 @@ ErrorOr<void> StringBuilder::try_append_escaped_for_json(StringView string)
TRY(try_append("\\\\"sv));
break;
default:
if (ch >= 0 && ch <= 0x1f)
if (bit_cast<u8>(ch) <= 0x1f)
TRY(try_appendff("\\u{:04x}", ch));
else
TRY(try_append(ch));

View File

@@ -28,7 +28,7 @@ First, make sure you have a working toolchain and can build and run SerenityOS.
If you're working on the Kernel, just uncomment `#define KERNEL`.
- Edit the `serenity.cxxflags` file to say `-std=c++26 -fsigned-char -fconcepts -fno-exceptions -fno-semantic-interposition -fPIC`
- Edit the `serenity.cxxflags` file to say `-std=c++26 -fconcepts -fno-exceptions -fno-semantic-interposition -fPIC`
- Edit the `serenity.includes` file to list the following lines:
```
./

View File

@@ -682,7 +682,6 @@ set(PARTITION_SOURCES
../Userland/Libraries/LibPartition/PartitionTable.cpp
)
add_compile_options(-fsigned-char)
add_compile_options(-Wno-unknown-warning-option -Wvla -Wnull-dereference)
add_compile_options(-fno-rtti -ffreestanding -fbuiltin)

View File

@@ -120,7 +120,7 @@ ErrorOr<void> KBufferBuilder::append_escaped_for_json(StringView string)
TRY(append("\\\\"sv));
break;
default:
if (ch >= 0 && ch <= 0x1f)
if (bit_cast<u8>(ch) <= 0x1f)
TRY(appendff("\\u{:04x}", ch));
else
TRY(append(ch));

View File

@@ -2,7 +2,6 @@ include(${CMAKE_CURRENT_LIST_DIR}/common_compile_options.cmake)
add_compile_options(-Wno-maybe-uninitialized)
add_compile_options(-Wno-shorten-64-to-32)
add_compile_options(-fsigned-char)
add_compile_options(-ggnu-pubnames)
if (NOT WIN32)
add_compile_options(-fPIC)

View File

@@ -5,7 +5,6 @@ include(${CMAKE_CURRENT_LIST_DIR}/common_compile_options.cmake)
add_compile_options(-fno-delete-null-pointer-checks)
add_compile_options(-ffile-prefix-map=${SerenityOS_SOURCE_DIR}=.)
add_compile_options(-fno-omit-frame-pointer)
add_compile_options(-fsigned-char)
add_compile_options(-fsized-deallocation)
add_compile_options(-fstack-clash-protection)
add_compile_options(-fstack-protector-strong)

View File

@@ -92,7 +92,6 @@ config("compiler_defaults") {
cflags += [
"-fdiagnostics-color",
"-ffp-contract=off",
"-fsigned-char",
]
if (use_lld) {

View File

@@ -144,7 +144,6 @@ config("Kernel_config") {
}
cflags_cc += [
"-fsigned-char",
"-Wno-unknown-warning-option",
"-fno-rtti",
"-ffreestanding",

View File

@@ -294,14 +294,7 @@ public:
u32 operator[](size_t index) const
{
return m_view.visit(
[&](StringView view) -> u32 {
auto ch = view[index];
if constexpr (IsSigned<char>) {
if (ch < 0)
return 256u + ch;
return ch;
}
},
[&](StringView view) -> u32 { return bit_cast<u8>(view[index]); },
[&](Utf32View const& view) -> u32 { return view[index]; },
[&](Utf16View const& view) -> u32 { return view.code_point_at(index); },
[&](Utf8View const& view) -> u32 {
@@ -317,14 +310,7 @@ public:
return operator[](code_unit_index);
return m_view.visit(
[&](StringView view) -> u32 {
auto ch = view[code_unit_index];
if constexpr (IsSigned<char>) {
if (ch < 0)
return 256u + ch;
return ch;
}
},
[&](StringView view) -> u32 { return bit_cast<u8>(view[code_unit_index]); },
[&](Utf32View const& view) -> u32 { return view[code_unit_index]; },
[&](Utf16View const& view) -> u32 { return view.code_unit_at(code_unit_index); },
[&](Utf8View const& view) -> u32 {