-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[libc] Fix bugs found when testing with all headers #144049
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- math.yaml: float128 guard - wchar.yaml: __restrict keyword order - converter_test.cpp: add float test
@llvm/pr-subscribers-libc Author: William Huynh (saturn691) ChangesFixes a couple of bugs found when building, and adds a test, which fails on AArch32 baremetal.
Full diff: https://github.com/llvm/llvm-project/pull/144049.diff 3 Files Affected:
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<char *>("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<uint64_t>(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<uint64_t>(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);
+}
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for finding these! This change looks good, though I left a comment on why I don't think we should have float tests in converter_test.cpp
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<uint64_t>(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<uint64_t>(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); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having float conversion tests is useful, but currently they're all in sprintf_test.cpp
because there are flags to turn float conversions on and off. There's special cmake logic to ensure that the sprintf tests also get those flags so they don't fail on targets without floats.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for the cleanup! I'll merge this for you once the presubmits finish
Following discussion from https://discourse.llvm.org/t/missing-declarations-in-header-files/86678, we decided to add a flag to output all headers. Requires #144049. - Allows outputting all headers - Minor whitespace change for alignment --------- Co-authored-by: Michael Jones <[email protected]>
Fixes a couple of bugs found when building. The PR to enable the headers can be found here: llvm#144114. - math.yaml: float128 guard - wchar.yaml: __restrict keyword order
) Following discussion from https://discourse.llvm.org/t/missing-declarations-in-header-files/86678, we decided to add a flag to output all headers. Requires llvm#144049. - Allows outputting all headers - Minor whitespace change for alignment --------- Co-authored-by: Michael Jones <[email protected]>
Fixes a couple of bugs found when building. The PR to enable the headers can be found here: llvm#144114. - math.yaml: float128 guard - wchar.yaml: __restrict keyword order
) Following discussion from https://discourse.llvm.org/t/missing-declarations-in-header-files/86678, we decided to add a flag to output all headers. Requires llvm#144049. - Allows outputting all headers - Minor whitespace change for alignment --------- Co-authored-by: Michael Jones <[email protected]>
Fixes a couple of bugs found when building. The PR to enable the headers can be found here: #144114.