2018-08-01 10:38:30 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2019-01-19 18:56:40 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2018-08-01 10:38:30 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2020-06-01 22:38:23 +08:00
|
|
|
// UNSUPPORTED: c++03
|
2019-03-21 03:43:22 +08:00
|
|
|
// UNSUPPORTED: !libc++ && c++11
|
|
|
|
// UNSUPPORTED: !libc++ && c++14
|
2018-08-11 01:03:47 +08:00
|
|
|
|
2020-02-14 22:19:47 +08:00
|
|
|
// to_chars requires functions in the dylib that were introduced in Mac OS 10.15.
|
|
|
|
//
|
2021-05-07 22:15:36 +08:00
|
|
|
// XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.14
|
|
|
|
// XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.13
|
|
|
|
// XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.12
|
|
|
|
// XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.11
|
|
|
|
// XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.10
|
|
|
|
// XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.9
|
2018-08-11 01:03:47 +08:00
|
|
|
|
2018-08-01 10:38:30 +08:00
|
|
|
// <charconv>
|
|
|
|
|
|
|
|
// to_chars_result to_chars(char* first, char* last, Integral value,
|
|
|
|
// int base = 10)
|
|
|
|
|
2020-02-14 22:19:47 +08:00
|
|
|
#include <charconv>
|
2019-06-01 02:35:30 +08:00
|
|
|
#include "test_macros.h"
|
2018-08-01 10:38:30 +08:00
|
|
|
#include "charconv_test_helpers.h"
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
struct test_basics : to_chars_test_base<T>
|
|
|
|
{
|
|
|
|
using to_chars_test_base<T>::test;
|
|
|
|
using to_chars_test_base<T>::test_value;
|
|
|
|
|
|
|
|
void operator()()
|
|
|
|
{
|
|
|
|
test(0, "0");
|
|
|
|
test(42, "42");
|
|
|
|
test(32768, "32768");
|
|
|
|
test(0, "0", 10);
|
|
|
|
test(42, "42", 10);
|
|
|
|
test(32768, "32768", 10);
|
|
|
|
test(0xf, "f", 16);
|
|
|
|
test(0xdeadbeaf, "deadbeaf", 16);
|
|
|
|
test(0755, "755", 8);
|
|
|
|
|
2019-06-11 01:11:46 +08:00
|
|
|
// Test each len till len of UINT64_MAX = 20 because to_chars algorithm
|
|
|
|
// makes branches based on decimal digits count in the value string
|
|
|
|
// representation.
|
|
|
|
// Test driver automatically skips values not fitting into source type.
|
|
|
|
test(1UL, "1");
|
|
|
|
test(12UL, "12");
|
|
|
|
test(123UL, "123");
|
|
|
|
test(1234UL, "1234");
|
|
|
|
test(12345UL, "12345");
|
|
|
|
test(123456UL, "123456");
|
|
|
|
test(1234567UL, "1234567");
|
|
|
|
test(12345678UL, "12345678");
|
|
|
|
test(123456789UL, "123456789");
|
|
|
|
test(1234567890UL, "1234567890");
|
|
|
|
test(12345678901UL, "12345678901");
|
|
|
|
test(123456789012UL, "123456789012");
|
|
|
|
test(1234567890123UL, "1234567890123");
|
|
|
|
test(12345678901234UL, "12345678901234");
|
|
|
|
test(123456789012345UL, "123456789012345");
|
|
|
|
test(1234567890123456UL, "1234567890123456");
|
|
|
|
test(12345678901234567UL, "12345678901234567");
|
|
|
|
test(123456789012345678UL, "123456789012345678");
|
|
|
|
test(1234567890123456789UL, "1234567890123456789");
|
|
|
|
test(12345678901234567890UL, "12345678901234567890");
|
|
|
|
|
|
|
|
// Test special cases with zeros inside a value string representation,
|
|
|
|
// to_chars algorithm processes them in a special way and should not
|
|
|
|
// skip trailing zeros
|
|
|
|
// Test driver automatically skips values not fitting into source type.
|
|
|
|
test(0UL, "0");
|
|
|
|
test(10UL, "10");
|
|
|
|
test(100UL, "100");
|
|
|
|
test(1000UL, "1000");
|
|
|
|
test(10000UL, "10000");
|
|
|
|
test(100000UL, "100000");
|
|
|
|
test(1000000UL, "1000000");
|
|
|
|
test(10000000UL, "10000000");
|
|
|
|
test(100000000UL, "100000000");
|
|
|
|
test(1000000000UL, "1000000000");
|
|
|
|
test(10000000000UL, "10000000000");
|
|
|
|
test(100000000000UL, "100000000000");
|
|
|
|
test(1000000000000UL, "1000000000000");
|
|
|
|
test(10000000000000UL, "10000000000000");
|
|
|
|
test(100000000000000UL, "100000000000000");
|
|
|
|
test(1000000000000000UL, "1000000000000000");
|
|
|
|
test(10000000000000000UL, "10000000000000000");
|
|
|
|
test(100000000000000000UL, "100000000000000000");
|
|
|
|
test(1000000000000000000UL, "1000000000000000000");
|
|
|
|
test(10000000000000000000UL, "10000000000000000000");
|
|
|
|
|
2018-08-01 10:38:30 +08:00
|
|
|
for (int b = 2; b < 37; ++b)
|
|
|
|
{
|
|
|
|
using xl = std::numeric_limits<T>;
|
|
|
|
|
|
|
|
test_value(1, b);
|
|
|
|
test_value(xl::lowest(), b);
|
|
|
|
test_value((xl::max)(), b);
|
|
|
|
test_value((xl::max)() / 2, b);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
struct test_signed : to_chars_test_base<T>
|
|
|
|
{
|
|
|
|
using to_chars_test_base<T>::test;
|
|
|
|
using to_chars_test_base<T>::test_value;
|
|
|
|
|
|
|
|
void operator()()
|
|
|
|
{
|
|
|
|
test(-1, "-1");
|
|
|
|
test(-12, "-12");
|
|
|
|
test(-1, "-1", 10);
|
|
|
|
test(-12, "-12", 10);
|
|
|
|
test(-21734634, "-21734634", 10);
|
|
|
|
test(-2647, "-101001010111", 2);
|
|
|
|
test(-0xcc1, "-cc1", 16);
|
|
|
|
|
2019-06-11 01:11:46 +08:00
|
|
|
// Test each len till len of INT64_MAX = 19 because to_chars algorithm
|
|
|
|
// makes branches based on decimal digits count in the value string
|
|
|
|
// representation.
|
|
|
|
// Test driver automatically skips values not fitting into source type.
|
|
|
|
test(-1L, "-1");
|
|
|
|
test(-12L, "-12");
|
|
|
|
test(-123L, "-123");
|
|
|
|
test(-1234L, "-1234");
|
|
|
|
test(-12345L, "-12345");
|
|
|
|
test(-123456L, "-123456");
|
|
|
|
test(-1234567L, "-1234567");
|
|
|
|
test(-12345678L, "-12345678");
|
|
|
|
test(-123456789L, "-123456789");
|
|
|
|
test(-1234567890L, "-1234567890");
|
|
|
|
test(-12345678901L, "-12345678901");
|
|
|
|
test(-123456789012L, "-123456789012");
|
|
|
|
test(-1234567890123L, "-1234567890123");
|
|
|
|
test(-12345678901234L, "-12345678901234");
|
|
|
|
test(-123456789012345L, "-123456789012345");
|
|
|
|
test(-1234567890123456L, "-1234567890123456");
|
|
|
|
test(-12345678901234567L, "-12345678901234567");
|
|
|
|
test(-123456789012345678L, "-123456789012345678");
|
|
|
|
test(-1234567890123456789L, "-1234567890123456789");
|
|
|
|
|
|
|
|
// Test special cases with zeros inside a value string representation,
|
|
|
|
// to_chars algorithm processes them in a special way and should not
|
|
|
|
// skip trailing zeros
|
|
|
|
// Test driver automatically skips values not fitting into source type.
|
|
|
|
test(-10L, "-10");
|
|
|
|
test(-100L, "-100");
|
|
|
|
test(-1000L, "-1000");
|
|
|
|
test(-10000L, "-10000");
|
|
|
|
test(-100000L, "-100000");
|
|
|
|
test(-1000000L, "-1000000");
|
|
|
|
test(-10000000L, "-10000000");
|
|
|
|
test(-100000000L, "-100000000");
|
|
|
|
test(-1000000000L, "-1000000000");
|
|
|
|
test(-10000000000L, "-10000000000");
|
|
|
|
test(-100000000000L, "-100000000000");
|
|
|
|
test(-1000000000000L, "-1000000000000");
|
|
|
|
test(-10000000000000L, "-10000000000000");
|
|
|
|
test(-100000000000000L, "-100000000000000");
|
|
|
|
test(-1000000000000000L, "-1000000000000000");
|
|
|
|
test(-10000000000000000L, "-10000000000000000");
|
|
|
|
test(-100000000000000000L, "-100000000000000000");
|
|
|
|
test(-1000000000000000000L, "-1000000000000000000");
|
|
|
|
|
2018-08-01 10:38:30 +08:00
|
|
|
for (int b = 2; b < 37; ++b)
|
|
|
|
{
|
|
|
|
using xl = std::numeric_limits<T>;
|
|
|
|
|
|
|
|
test_value(0, b);
|
|
|
|
test_value(xl::lowest(), b);
|
|
|
|
test_value((xl::max)(), b);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
Support tests in freestanding
Summary:
Freestanding is *weird*. The standard allows it to differ in a bunch of odd
manners from regular C++, and the committee would like to improve that
situation. I'd like to make libc++ behave better with what freestanding should
be, so that it can be a tool we use in improving the standard. To do that we
need to try stuff out, both with "freestanding the language mode" and
"freestanding the library subset".
Let's start with the super basic: run the libc++ tests in freestanding, using
clang as the compiler, and see what works. The easiest hack to do this:
In utils/libcxx/test/config.py add:
self.cxx.compile_flags += ['-ffreestanding']
Run the tests and they all fail.
Why? Because in freestanding `main` isn't special. This "not special" property
has two effects: main doesn't get mangled, and main isn't allowed to omit its
`return` statement. The first means main gets mangled and the linker can't
create a valid executable for us to test. The second means we spew out warnings
(ew) and the compiler doesn't insert the `return` we omitted, and main just
falls of the end and does whatever undefined behavior (if you're luck, ud2
leading to non-zero return code).
Let's start my work with the basics. This patch changes all libc++ tests to
declare `main` as `int main(int, char**` so it mangles consistently (enabling us
to declare another `extern "C"` main for freestanding which calls the mangled
one), and adds `return 0;` to all places where it was missing. This touches 6124
files, and I apologize.
The former was done with The Magic Of Sed.
The later was done with a (not quite correct but decent) clang tool:
https://gist.github.com/jfbastien/793819ff360baa845483dde81170feed
This works for most tests, though I did have to adjust a few places when e.g.
the test runs with `-x c`, macros are used for main (such as for the filesystem
tests), etc.
Once this is in we can create a freestanding bot which will prevent further
regressions. After that, we can start the real work of supporting C++
freestanding fairly well in libc++.
<rdar://problem/47754795>
Reviewers: ldionne, mclow.lists, EricWF
Subscribers: christof, jkorous, dexonsmith, arphaman, miyuki, libcxx-commits
Differential Revision: https://reviews.llvm.org/D57624
llvm-svn: 353086
2019-02-05 04:31:13 +08:00
|
|
|
int main(int, char**)
|
2018-08-01 10:38:30 +08:00
|
|
|
{
|
|
|
|
run<test_basics>(integrals);
|
|
|
|
run<test_signed>(all_signed);
|
Support tests in freestanding
Summary:
Freestanding is *weird*. The standard allows it to differ in a bunch of odd
manners from regular C++, and the committee would like to improve that
situation. I'd like to make libc++ behave better with what freestanding should
be, so that it can be a tool we use in improving the standard. To do that we
need to try stuff out, both with "freestanding the language mode" and
"freestanding the library subset".
Let's start with the super basic: run the libc++ tests in freestanding, using
clang as the compiler, and see what works. The easiest hack to do this:
In utils/libcxx/test/config.py add:
self.cxx.compile_flags += ['-ffreestanding']
Run the tests and they all fail.
Why? Because in freestanding `main` isn't special. This "not special" property
has two effects: main doesn't get mangled, and main isn't allowed to omit its
`return` statement. The first means main gets mangled and the linker can't
create a valid executable for us to test. The second means we spew out warnings
(ew) and the compiler doesn't insert the `return` we omitted, and main just
falls of the end and does whatever undefined behavior (if you're luck, ud2
leading to non-zero return code).
Let's start my work with the basics. This patch changes all libc++ tests to
declare `main` as `int main(int, char**` so it mangles consistently (enabling us
to declare another `extern "C"` main for freestanding which calls the mangled
one), and adds `return 0;` to all places where it was missing. This touches 6124
files, and I apologize.
The former was done with The Magic Of Sed.
The later was done with a (not quite correct but decent) clang tool:
https://gist.github.com/jfbastien/793819ff360baa845483dde81170feed
This works for most tests, though I did have to adjust a few places when e.g.
the test runs with `-x c`, macros are used for main (such as for the filesystem
tests), etc.
Once this is in we can create a freestanding bot which will prevent further
regressions. After that, we can start the real work of supporting C++
freestanding fairly well in libc++.
<rdar://problem/47754795>
Reviewers: ldionne, mclow.lists, EricWF
Subscribers: christof, jkorous, dexonsmith, arphaman, miyuki, libcxx-commits
Differential Revision: https://reviews.llvm.org/D57624
llvm-svn: 353086
2019-02-05 04:31:13 +08:00
|
|
|
|
|
|
|
return 0;
|
2018-08-01 10:38:30 +08:00
|
|
|
}
|