From 70db174e29a6f9180ca655ff054d875912b50939 Mon Sep 17 00:00:00 2001 From: William Huynh Date: Fri, 13 Jun 2025 10:59:45 +0100 Subject: [PATCH 1/3] [libc] Fix bugs found when testing with all headers - math.yaml: float128 guard - wchar.yaml: __restrict keyword order - converter_test.cpp: add float test --- libc/include/math.yaml | 2 +- libc/include/wchar.yaml | 20 ++++++------ .../src/stdio/printf_core/converter_test.cpp | 32 ++++++++++++++++++- 3 files changed, 42 insertions(+), 12 deletions(-) diff --git a/libc/include/math.yaml b/libc/include/math.yaml index 466c08ade6fc4..11bead0745954 100644 --- a/libc/include/math.yaml +++ b/libc/include/math.yaml @@ -734,7 +734,7 @@ functions: - type: float128 - type: float128 - type: float128 - guards: LIBC_TYPES_HAS_FLOAT128 + guard: LIBC_TYPES_HAS_FLOAT128 - name: ffmal standards: - stdc diff --git a/libc/include/wchar.yaml b/libc/include/wchar.yaml index 57f4f6660827e..39c3a05848dfc 100644 --- a/libc/include/wchar.yaml +++ b/libc/include/wchar.yaml @@ -109,24 +109,24 @@ functions: - stdc return_type: wchar_t * arguments: - - type: __restrict wchar_t * - - type: const __restrict wchar_t * + - type: wchar_t *__restrict + - type: const wchar_t *__restrict - type: size_t - name: wcsncpy standards: - stdc return_type: wchar_t * arguments: - - type: __restrict wchar_t * - - type: const __restrict wchar_t * + - type: wchar_t *__restrict + - type: const wchar_t *__restrict - type: size_t - name: wcscat standards: - stdc return_type: wchar_t * arguments: - - type: __restrict wchar_t * - - type: const __restrict wchar_t * + - type: wchar_t *__restrict + - type: const wchar_t *__restrict - name: wcsstr standards: - stdc @@ -139,13 +139,13 @@ functions: - stdc return_type: wchar_t * arguments: - - type: __restrict wchar_t * - - type: const __restrict wchar_t * + - type: wchar_t *__restrict + - type: const wchar_t *__restrict - type: size_t - name: wcscpy standards: - stdc return_type: wchar_t * arguments: - - type: __restrict wchar_t * - - type: const __restrict wchar_t * + - type: wchar_t *__restrict + - type: const wchar_t *__restrict diff --git a/libc/test/src/stdio/printf_core/converter_test.cpp b/libc/test/src/stdio/printf_core/converter_test.cpp index 96a00ae598ec2..b95328398c104 100644 --- a/libc/test/src/stdio/printf_core/converter_test.cpp +++ b/libc/test/src/stdio/printf_core/converter_test.cpp @@ -124,7 +124,7 @@ TEST_F(LlvmLibcPrintfConverterTest, StringConversionSimple) { TEST_F(LlvmLibcPrintfConverterTest, StringConversionPrecisionHigh) { LIBC_NAMESPACE::printf_core::FormatSection high_precision_conv; high_precision_conv.has_conv = true; - high_precision_conv.raw_string = "%4s"; + high_precision_conv.raw_string = "%.4s"; high_precision_conv.conv_name = 's'; high_precision_conv.precision = 4; high_precision_conv.conv_val_ptr = const_cast("456"); @@ -255,3 +255,33 @@ TEST_F(LlvmLibcPrintfConverterTest, OctConversion) { ASSERT_STREQ(str, "1234"); ASSERT_EQ(writer.get_chars_written(), 4); } + +TEST_F(LlvmLibcPrintfConverterTest, FloatConversionSimple) { + + LIBC_NAMESPACE::printf_core::FormatSection section; + section.has_conv = true; + section.raw_string = "%f"; + section.conv_name = 'f'; + section.conv_val_raw = LIBC_NAMESPACE::cpp::bit_cast(1.234567); + LIBC_NAMESPACE::printf_core::convert(&writer, section); + + wb.buff[wb.buff_cur] = '\0'; + ASSERT_STREQ(str, "1.234567"); + ASSERT_EQ(writer.get_chars_written(), 8); +} + +TEST_F(LlvmLibcPrintfConverterTest, FloatConversionPrecisionHigh) { + + LIBC_NAMESPACE::printf_core::FormatSection section; + section.has_conv = true; + section.raw_string = "%12.3f"; + section.conv_name = 'f'; + section.min_width = 12; + section.precision = 3; + section.conv_val_raw = LIBC_NAMESPACE::cpp::bit_cast(0.000123); + LIBC_NAMESPACE::printf_core::convert(&writer, section); + + wb.buff[wb.buff_cur] = '\0'; + ASSERT_STREQ(str, " 0.000"); + ASSERT_EQ(writer.get_chars_written(), 12); +} From 888461f80ee88214092702fe8a87eab21df08de0 Mon Sep 17 00:00:00 2001 From: William Huynh Date: Fri, 13 Jun 2025 18:09:07 +0100 Subject: [PATCH 2/3] fixup! [libc] Fix bugs found when testing with all headers --- .../src/stdio/printf_core/converter_test.cpp | 29 ------------------- 1 file changed, 29 deletions(-) diff --git a/libc/test/src/stdio/printf_core/converter_test.cpp b/libc/test/src/stdio/printf_core/converter_test.cpp index b95328398c104..808b229b05d79 100644 --- a/libc/test/src/stdio/printf_core/converter_test.cpp +++ b/libc/test/src/stdio/printf_core/converter_test.cpp @@ -256,32 +256,3 @@ TEST_F(LlvmLibcPrintfConverterTest, OctConversion) { ASSERT_EQ(writer.get_chars_written(), 4); } -TEST_F(LlvmLibcPrintfConverterTest, FloatConversionSimple) { - - LIBC_NAMESPACE::printf_core::FormatSection section; - section.has_conv = true; - section.raw_string = "%f"; - section.conv_name = 'f'; - section.conv_val_raw = LIBC_NAMESPACE::cpp::bit_cast(1.234567); - LIBC_NAMESPACE::printf_core::convert(&writer, section); - - wb.buff[wb.buff_cur] = '\0'; - ASSERT_STREQ(str, "1.234567"); - ASSERT_EQ(writer.get_chars_written(), 8); -} - -TEST_F(LlvmLibcPrintfConverterTest, FloatConversionPrecisionHigh) { - - LIBC_NAMESPACE::printf_core::FormatSection section; - section.has_conv = true; - section.raw_string = "%12.3f"; - section.conv_name = 'f'; - section.min_width = 12; - section.precision = 3; - section.conv_val_raw = LIBC_NAMESPACE::cpp::bit_cast(0.000123); - LIBC_NAMESPACE::printf_core::convert(&writer, section); - - wb.buff[wb.buff_cur] = '\0'; - ASSERT_STREQ(str, " 0.000"); - ASSERT_EQ(writer.get_chars_written(), 12); -} From 64ccce1cd489d037bc9634bfd4ac74a31e3a8b51 Mon Sep 17 00:00:00 2001 From: William Huynh Date: Fri, 13 Jun 2025 18:09:26 +0100 Subject: [PATCH 3/3] fixup! fixup! [libc] Fix bugs found when testing with all headers --- libc/test/src/stdio/printf_core/converter_test.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/libc/test/src/stdio/printf_core/converter_test.cpp b/libc/test/src/stdio/printf_core/converter_test.cpp index 808b229b05d79..bf088937e4104 100644 --- a/libc/test/src/stdio/printf_core/converter_test.cpp +++ b/libc/test/src/stdio/printf_core/converter_test.cpp @@ -255,4 +255,3 @@ TEST_F(LlvmLibcPrintfConverterTest, OctConversion) { ASSERT_STREQ(str, "1234"); ASSERT_EQ(writer.get_chars_written(), 4); } -