From 52a88a8ea8aca0a5d75b27d0f2bc1e6c71c4d77f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Holz?= Date: Thu, 5 Feb 2026 12:39:19 +0100 Subject: [PATCH] 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. --- AK/StringBuilder.cpp | 2 +- Documentation/QtCreatorConfiguration.md | 2 +- Kernel/CMakeLists.txt | 1 - Kernel/Library/KBufferBuilder.cpp | 2 +- Meta/CMake/lagom_compile_options.cmake | 1 - Meta/CMake/serenity_compile_options.cmake | 1 - Meta/gn/build/BUILD.gn | 1 - Meta/gn/secondary/Kernel/BUILD.gn | 1 - Userland/Libraries/LibRegex/RegexMatch.h | 18 ++---------------- 9 files changed, 5 insertions(+), 24 deletions(-) diff --git a/AK/StringBuilder.cpp b/AK/StringBuilder.cpp index 8a02647657f..5702e93fbf5 100644 --- a/AK/StringBuilder.cpp +++ b/AK/StringBuilder.cpp @@ -307,7 +307,7 @@ ErrorOr StringBuilder::try_append_escaped_for_json(StringView string) TRY(try_append("\\\\"sv)); break; default: - if (ch >= 0 && ch <= 0x1f) + if (bit_cast(ch) <= 0x1f) TRY(try_appendff("\\u{:04x}", ch)); else TRY(try_append(ch)); diff --git a/Documentation/QtCreatorConfiguration.md b/Documentation/QtCreatorConfiguration.md index 687743d83e5..33168e0a775 100644 --- a/Documentation/QtCreatorConfiguration.md +++ b/Documentation/QtCreatorConfiguration.md @@ -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: ``` ./ diff --git a/Kernel/CMakeLists.txt b/Kernel/CMakeLists.txt index 052b033cdd0..34f0a866c86 100644 --- a/Kernel/CMakeLists.txt +++ b/Kernel/CMakeLists.txt @@ -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) diff --git a/Kernel/Library/KBufferBuilder.cpp b/Kernel/Library/KBufferBuilder.cpp index e772096aff3..9f855092c79 100644 --- a/Kernel/Library/KBufferBuilder.cpp +++ b/Kernel/Library/KBufferBuilder.cpp @@ -120,7 +120,7 @@ ErrorOr KBufferBuilder::append_escaped_for_json(StringView string) TRY(append("\\\\"sv)); break; default: - if (ch >= 0 && ch <= 0x1f) + if (bit_cast(ch) <= 0x1f) TRY(appendff("\\u{:04x}", ch)); else TRY(append(ch)); diff --git a/Meta/CMake/lagom_compile_options.cmake b/Meta/CMake/lagom_compile_options.cmake index e1b0fa8fc54..718214659e6 100644 --- a/Meta/CMake/lagom_compile_options.cmake +++ b/Meta/CMake/lagom_compile_options.cmake @@ -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) diff --git a/Meta/CMake/serenity_compile_options.cmake b/Meta/CMake/serenity_compile_options.cmake index e04d1120e9e..65d08a397f0 100644 --- a/Meta/CMake/serenity_compile_options.cmake +++ b/Meta/CMake/serenity_compile_options.cmake @@ -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) diff --git a/Meta/gn/build/BUILD.gn b/Meta/gn/build/BUILD.gn index 1704068305d..7d4e0786fb2 100644 --- a/Meta/gn/build/BUILD.gn +++ b/Meta/gn/build/BUILD.gn @@ -92,7 +92,6 @@ config("compiler_defaults") { cflags += [ "-fdiagnostics-color", "-ffp-contract=off", - "-fsigned-char", ] if (use_lld) { diff --git a/Meta/gn/secondary/Kernel/BUILD.gn b/Meta/gn/secondary/Kernel/BUILD.gn index 9d8a36adda8..167ace827f2 100644 --- a/Meta/gn/secondary/Kernel/BUILD.gn +++ b/Meta/gn/secondary/Kernel/BUILD.gn @@ -144,7 +144,6 @@ config("Kernel_config") { } cflags_cc += [ - "-fsigned-char", "-Wno-unknown-warning-option", "-fno-rtti", "-ffreestanding", diff --git a/Userland/Libraries/LibRegex/RegexMatch.h b/Userland/Libraries/LibRegex/RegexMatch.h index bdeb3baaaef..29ab1c774fb 100644 --- a/Userland/Libraries/LibRegex/RegexMatch.h +++ b/Userland/Libraries/LibRegex/RegexMatch.h @@ -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) { - if (ch < 0) - return 256u + ch; - return ch; - } - }, + [&](StringView view) -> u32 { return bit_cast(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) { - if (ch < 0) - return 256u + ch; - return ch; - } - }, + [&](StringView view) -> u32 { return bit_cast(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 {