Skip to content

Commit 70db174

Browse files
committed
[libc] Fix bugs found when testing with all headers
- math.yaml: float128 guard - wchar.yaml: __restrict keyword order - converter_test.cpp: add float test
1 parent b979311 commit 70db174

File tree

3 files changed

+42
-12
lines changed

3 files changed

+42
-12
lines changed

libc/include/math.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ functions:
734734
- type: float128
735735
- type: float128
736736
- type: float128
737-
guards: LIBC_TYPES_HAS_FLOAT128
737+
guard: LIBC_TYPES_HAS_FLOAT128
738738
- name: ffmal
739739
standards:
740740
- stdc

libc/include/wchar.yaml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -109,24 +109,24 @@ functions:
109109
- stdc
110110
return_type: wchar_t *
111111
arguments:
112-
- type: __restrict wchar_t *
113-
- type: const __restrict wchar_t *
112+
- type: wchar_t *__restrict
113+
- type: const wchar_t *__restrict
114114
- type: size_t
115115
- name: wcsncpy
116116
standards:
117117
- stdc
118118
return_type: wchar_t *
119119
arguments:
120-
- type: __restrict wchar_t *
121-
- type: const __restrict wchar_t *
120+
- type: wchar_t *__restrict
121+
- type: const wchar_t *__restrict
122122
- type: size_t
123123
- name: wcscat
124124
standards:
125125
- stdc
126126
return_type: wchar_t *
127127
arguments:
128-
- type: __restrict wchar_t *
129-
- type: const __restrict wchar_t *
128+
- type: wchar_t *__restrict
129+
- type: const wchar_t *__restrict
130130
- name: wcsstr
131131
standards:
132132
- stdc
@@ -139,13 +139,13 @@ functions:
139139
- stdc
140140
return_type: wchar_t *
141141
arguments:
142-
- type: __restrict wchar_t *
143-
- type: const __restrict wchar_t *
142+
- type: wchar_t *__restrict
143+
- type: const wchar_t *__restrict
144144
- type: size_t
145145
- name: wcscpy
146146
standards:
147147
- stdc
148148
return_type: wchar_t *
149149
arguments:
150-
- type: __restrict wchar_t *
151-
- type: const __restrict wchar_t *
150+
- type: wchar_t *__restrict
151+
- type: const wchar_t *__restrict

libc/test/src/stdio/printf_core/converter_test.cpp

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ TEST_F(LlvmLibcPrintfConverterTest, StringConversionSimple) {
124124
TEST_F(LlvmLibcPrintfConverterTest, StringConversionPrecisionHigh) {
125125
LIBC_NAMESPACE::printf_core::FormatSection high_precision_conv;
126126
high_precision_conv.has_conv = true;
127-
high_precision_conv.raw_string = "%4s";
127+
high_precision_conv.raw_string = "%.4s";
128128
high_precision_conv.conv_name = 's';
129129
high_precision_conv.precision = 4;
130130
high_precision_conv.conv_val_ptr = const_cast<char *>("456");
@@ -255,3 +255,33 @@ TEST_F(LlvmLibcPrintfConverterTest, OctConversion) {
255255
ASSERT_STREQ(str, "1234");
256256
ASSERT_EQ(writer.get_chars_written(), 4);
257257
}
258+
259+
TEST_F(LlvmLibcPrintfConverterTest, FloatConversionSimple) {
260+
261+
LIBC_NAMESPACE::printf_core::FormatSection section;
262+
section.has_conv = true;
263+
section.raw_string = "%f";
264+
section.conv_name = 'f';
265+
section.conv_val_raw = LIBC_NAMESPACE::cpp::bit_cast<uint64_t>(1.234567);
266+
LIBC_NAMESPACE::printf_core::convert(&writer, section);
267+
268+
wb.buff[wb.buff_cur] = '\0';
269+
ASSERT_STREQ(str, "1.234567");
270+
ASSERT_EQ(writer.get_chars_written(), 8);
271+
}
272+
273+
TEST_F(LlvmLibcPrintfConverterTest, FloatConversionPrecisionHigh) {
274+
275+
LIBC_NAMESPACE::printf_core::FormatSection section;
276+
section.has_conv = true;
277+
section.raw_string = "%12.3f";
278+
section.conv_name = 'f';
279+
section.min_width = 12;
280+
section.precision = 3;
281+
section.conv_val_raw = LIBC_NAMESPACE::cpp::bit_cast<uint64_t>(0.000123);
282+
LIBC_NAMESPACE::printf_core::convert(&writer, section);
283+
284+
wb.buff[wb.buff_cur] = '\0';
285+
ASSERT_STREQ(str, " 0.000");
286+
ASSERT_EQ(writer.get_chars_written(), 12);
287+
}

0 commit comments

Comments
 (0)