99 Commits

Author SHA1 Message Date
Mark de Wever
dda4184808
[libc++][TZDB] Adds basics of zoned_time class. (#94999)
This implements the class, its non-templated constructors and its
getters to verify the construction.

Completes
- LWG3224 zoned_time constructor from TimeZonePtr does not specify
initialization of tp_

Implements parts of:
- P0355 Extending chrono to Calendars and Time Zones
2024-07-09 20:14:40 +02:00
Nikolas Klauser
9e9404387d
[libc++] Remove annotations for GCC 13 and update the documentation (#97744)
GCC 14 has been released a while ago. We've updated the CI to use GCC 14
now. This removes any old annotations in the tests and updates the
documentation to reflect the updated version requirements.
2024-07-06 16:52:45 +02:00
Mark de Wever
093ddac68c
[libc++][chrono] Fixes leap seconds. (#90070)
While implementing the UTC clock it turns out that the implementation of
the leap seconds was not correct, it should store the individual value,
not the sum.

It also looks like LWG3359 has not been fully implemented.

Implements parts of:
- LWG3359 <chrono> leap second support should allow for negative leap
seconds
2024-07-04 20:45:15 +02:00
Mark de Wever
e48f211ab8
[libc++][TZDB] Disables a failing test. (#95659)
The test fails depending on the timezone database used. Disable it for
now so it can be properly investigated later.
2024-06-15 19:59:05 +02:00
Louis Dionne
148417bfaa
[libc++] Mark local_time test as a long test (#95170)
It can otherwise timeout under some slow configurations.
2024-06-12 17:24:38 -04:00
Florian Mayer
00c5474918 [HWASan] make get_info.local_time.pass.cpp UNSUPPORTED 2024-06-11 09:06:07 -07:00
Florian Mayer
503fb1aaf4 [HWASan] skip libcxx test that times out with hwasan 2024-06-10 10:35:18 -07:00
Mark de Wever
151bd7cab4
[libc++][TZDB] Implements zoned_traits. (#91059)
Implements parts of:
- P0355 Extending chrono to Calendars and Time Zones
2024-06-10 17:13:08 +02:00
Mark de Wever
da03175cae
[libc++][TZDB] Implements time_zone::to_local. (#91003)
Implements parts of:
- P0355 Extending chrono to Calendars and Time Zones
2024-06-10 12:40:27 +02:00
Mark de Wever
87cedbec1c
[libc++][TZDB] Implements time_zone::to_sys. (#90901)
This implements the overload with the choose argument and adds this
enum.

Implements parts of:
- P0355 Extending chrono to Calendars and Time Zones
2024-06-10 08:40:04 +02:00
Mark de Wever
77116bd7d2
[libc++][TZDB] Implements time_zone::to_sys. (#90394)
This implements the throwing overload and the exception classes throw by
this overload.

Implements parts of:
- P0355 Extending chrono to Calendars and Time Zones
2024-06-10 00:33:39 +02:00
Mark de Wever
de736d9c6a
[libc++][TZDB] Implements time_zone get_info(local_time). (#89537)
Implements parts of:
- P0355 Extending chrono to Calendars and Time Zones
2024-06-09 18:21:35 +02:00
Nikolas Klauser
cb7a03b41f
[libc++] Fix failures with GCC 14 (#92663)
Fixes #91831
2024-06-01 12:20:41 +02:00
Stephan T. Lavavej
2ba0838615
[libc++] [test] Fix portability issues for MSVC (#93259)
* Guard `std::__make_from_tuple_impl` tests with `#ifdef _LIBCPP_VERSION` and `LIBCPP_STATIC_ASSERT`.
* Change `_LIBCPP_CONSTEXPR_SINCE_CXX20` to `TEST_CONSTEXPR_CXX20`.
+ Other functions in `variant.swap/swap.pass.cpp` were already using the proper test macro.
* Mark `what` as `[[maybe_unused]]` when used by `TEST_LIBCPP_REQUIRE`.
  + This updates one occurrence in `libcxx/test/libcxx` for consistency.
* Windows `_putenv_s()` takes 2 arguments, not 3.
  + See MSVC documentation: https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/putenv-s-wputenv-s?view=msvc-170
+ POSIX `setenv()` takes `int overwrite`, but Windows `_putenv_s()` always overwrites.
* Avoid non-Standard zero-length arrays.
  + Followup to #74183 and #79792.
* Add `operator++()` to `unsized_it`.
+ The Standard requires this due to [N4981][] [move.iter.requirements]/1 "The template parameter `Iterator` shall
  either meet the *Cpp17InputIterator* requirements ([input.iterators])
  or model `input_iterator` ([iterator.concept.input])."
+ MSVC's STL requires this because it has a strengthened exception
  specification in `move_iterator` that inspects the underlying iterator's
  increment operator.
* `uniform_int_distribution` forbids `int8_t`/`uint8_t`.
  + See [N4981][] [rand.req.genl]/1.5. MSVC's STL enforces this.
+ Note that when changing the distribution's `IntType`, we need to be
  careful to preserve the original value range of `[0, max_input]`.
* fstreams are constructible from `const fs::path::value_type*` on wide systems.
  + See [ifstream.cons], [ofstream.cons], [fstream.cons].
* In `msvc_stdlib_force_include.h`, map `_HAS_CXX23` to `TEST_STD_VER` 23 instead of 99.
+ On 2023-05-23, 71400505ca
  started recognizing 23 as a distinct value.
* Fix test name typo: `destory_elements.pass.cpp` => `destroy_elements.pass.cpp`

[N4981]: https://wg21.link/N4981
2024-05-28 12:20:58 -07:00
Mark de Wever
4e9decf294
[libc++][TZDB] Fixes reverse time lookups. (#89502)
Testing with the get_info() returning a local_info revealed some issues
in the reverse lookup. This needed an additional quirk. Also the
skipping when not in the current continuation optimization was wrong. It
prevented merging two sys_info objects.
2024-04-23 22:28:31 +02:00
Mark de Wever
579d30109a
[libc++][chrono] Fixes format output of negative values. (#89408)
When trying to express a time before the epoch (e.g. "one nanosecond
before 00:01:40 on 1900-01-01")
the date would be shown as:

  1900-01-01 00:01:39.-00000001

After this patch, that time would be correctly shown as:

  1900-01-01 00:01:39.999999999
2024-04-23 19:42:00 +02:00
Mark de Wever
a4422a5194
[libc++][TZDB] Renames incomplete. (#89250)
The new name uses experimental which better conveys what it means.
2024-04-20 12:09:13 +02:00
Mark de Wever
e9654880df [NFC][libc++][chrono] Renames a file.
This uses a period instead of a comma; the latter was a typo.
2024-04-18 19:39:22 +02:00
Mark de Wever
8a21d59f29
[libc++][TZDB] Adds local_info formatter. (#86256)
This adds the local_info type and its formatting options.
The usage of the local_info object will be done in separate patches.

Implements parts of:
- P0355 Extending to Calendars and Time Zones
- P1361 Integration of chrono with text formatting
2024-04-18 17:23:07 +02:00
Mark de Wever
6f7976c883
[libc++][TZDB] Adds sys_info formatter. (#85896)
Implements parts of:
- P0355 Extending <chrono> to Calendars and Time Zones
- P1361 Integration of chrono with text formatting
2024-04-17 20:55:51 +02:00
Mark de Wever
812963f6aa
[libc++][chrono] Improves date formatting. (#86127)
The formatting of years has been done manually since the results of %Y
outside the "typical" range may produce unexpected values. The same
applies to %F which is identical to %Y-%m-%d. None of these conversion
specifiers is affected by the locale used. So it's trivial to manually
handle this case.

This removes several platform specific ifdefs from the tests.
2024-04-17 17:02:07 +02:00
Mark de Wever
a6fcbcce8f
[libc++][TZDB] Improves time zone format specifiers. (#85797)
Per [tab:time.format.spec]
%z  The offset from UTC as specified in ISO 8601-1:2019, subclause
    5.3.4.1. For example -0430 refers to 4 hours 30 minutes behind UTC.
    If the offset is zero, +0000 is used. The modified commands %Ez and
    %Oz insert a : between the hours and minutes: -04:30. If the offset
    information is not available, an exception of type format_error is
    thrown.

Typically the modified versions Oz or Ez would have wording like

  The modified command %OS produces the locale's alternative
  representation.

In this case the modified version does not depend on the locale.

This change is a preparation for formatting sys_info which has time zone
information. The function time_put<_CharT>::put() does not have proper
time zone support, therefore it's a manual implementation.

Fixes https://github.com/llvm/llvm-project/issues/78184
2024-04-17 07:59:43 +02:00
Mark de Wever
8885813ebb [libc++][chrono] Disables a test.
This tests seems problematic on different platforms. There is still a
test that ensures coverage, but in an automatic fashion. This test needs
to be investigated.
2024-04-16 20:46:47 +02:00
Mark de Wever
ecf44b4b71 [libc++][TZDB] Removes test_indian_kerguelen test.
The work-around in 26852565a5f609e6b466f43c2f690ce3047d04c7 didn't fix
the CI. Since the entire local database is compared with the libc++
implementation in a separate this this change does not remove coverage.
2024-04-13 20:35:59 +02:00
Mark de Wever
26852565a5 [libc++][TZDZ] Validates the database version.
It seems one of the tests requires a very recent timezone database. Skip
the test when the database is older.
2024-04-13 16:08:07 +02:00
Mark de Wever
0a1317564a
[libc++] Adds a global private constructor tag. (#87920)
This removes the similar tags used in the chrono tzdb implementation.

Fixes: https://github.com/llvm/llvm-project/issues/85432
2024-04-10 20:34:58 +02:00
Mark de Wever
1fda1776e3
[libc++][chrono] Adds the sys_info class. (#85619)
Adds the sys_info class and time_zone::get_info(). The code still has a
few quirks and has not been optimized for performance yet.

The returned sys_info is compared against the output of the zdump tool
in the test giving confidence the implementation is correct.

Implements parts of:
- P0355 Extending <chrono> to Calendars and Time Zones

Implements:
- LWGXXXX The sys_info range should be affected by save
2024-04-10 07:50:17 +02:00
Mark de Wever
4167fec407
[libc++][chrono] Completes the tzdb class. (#82157)
It adds the missing member functions of the tzdb class and adds the free
functions that use these member functions.

Implements parts of:
- P0355 Extending <chrono> to Calendars and Time Zones
2024-04-04 19:03:01 +02:00
Mark de Wever
6f2d8cc061
[libc++][chrono] Loads leap-seconds.list in tzdb. (#82113)
This implements the loading of the leap-seconds.list file and store its
contents in the tzdb struct.

This adds the required `leap_seconds` member.

The class leap_seconds is fully implemented including its non-member
functions.

Implements parts of:
- P0355 Extending <chrono> to Calendars and Time Zones
- P1614 The Mothership has Landed

Implements:
- P1981 Rename leap to leap_second
- LWG3359 <chrono> leap second support should allow for negative leap
seconds
- LWG3383 §[time.zone.leap.nonmembers] sys_seconds should be replaced
with seconds
2024-04-03 18:15:24 +02:00
Mark de Wever
abe292f9f8
[libc++] Enables TZDB tests. (#82108)
With the timezone information available in the CI these tests can be
enabled again.

Fixes: https://github.com/llvm/llvm-project/issues/81654
2024-03-15 08:17:08 +01:00
Lei Huang
e4d4cfa5a0
[libc++] Fixes time formatter test output for Linux on PowerPC (#75526)
Fix output to match actual.
2024-03-07 09:32:43 -05:00
Dominik Wójt
d1a461dbb2
[libc++] tests with picolibc: prevent looking for unneeded "rt" library (#82262)
Picolibc does not provide the clock_gettime function nor the "rt" library.
check_library_exists was invalidly detecting the "rt" library due to cmake issue 
present, when cross-compiling[1]. This resulted with "chrono.cpp" trying to link
to the "rt" library and following error:
    unable to find library from dependent library specifier: rt

[1] https://gitlab.kitware.com/cmake/cmake/-/issues/18121
2024-02-29 08:54:58 +01:00
Mark de Wever
d332d88b91
[libc++][chrono] Loads tzdata.zi in tzdb. (#74928)
This implements the loading of the tzdata.zi file and store its contents
in the tzdb struct.

This adds all required members except:
- the leap seconds,
- the locate_zone, and
- current_zone.

The class time_zone is incomplete and only contains the parts needed for
storing the parsed data.

The class time_zone_link is fully implemented including its non-member
functions.

Implements parts of:
- P0355 Extending <chrono> to Calendars and Time Zones
- P1614 The Mothership has Landed

Implements:
- P1982 Rename link to time_zone_link
2024-02-17 14:28:01 +01:00
Mark de Wever
7d9540ea96
[libc++][chrono] Implements duration Rep constraints. (#80539)
Applies LWG3050 to the constraints of operator*, operator/, and
operator%. The changes to the constructor were done in
https://reviews.llvm.org/D118902, but that patch did not identify the
related LWG-issue, and only adjusted the constructor to the wording in
the Standard.

Implements:
- LWG 3050: Conversion specification problem in chrono::duration
constructor

---------

Co-authored-by: h-vetinari <h.vetinari@gmx.com>
2024-02-10 14:21:57 +01:00
Mark de Wever
042a6a1349
[libc++][chrono] Fixes (sys|local)_time formatters. (#76456)
- The sys_time formatter is constrained, which was not implemented.
- There is a sys_days formatter which was not implemented.
- The local_time formatter uses the sys_time formatter in its
implementation so "inherited" the same issues.

Fixes: https://github.com/llvm/llvm-project/issues/73849
Fixes: https://github.com/llvm/llvm-project/issues/67983
2024-01-22 19:06:15 +01:00
Mark de Wever
766bf140ff
[libc++][chrono] Fixes year_month year wrapping. (#74938)
Adding months to a year_month should wrap the year when the month
becomes greater than twelve or less than one.

This fixes the issue for year_month. Other classes with a year and month
do not have this issue. This has been verified and tests are added to
avoid possible regressions.

Also fixes some variable copy-paste errors in the tests.

Fixes https://github.com/llvm/llvm-project/issues/73162
2023-12-12 19:14:13 +01:00
Mark de Wever
965fe352a7
[libc++][test] Adds transcode option. (#73395)
This should make it easier to get better output when wchar_t tests fail.
The code is based on the Unicode transcoding in `<format>`.

Differential Revision: https://reviews.llvm.org/D150593
2023-12-08 18:25:54 +01:00
Michael Platings
be811d1617 [libc++] Run picolibc tests with qemu
This patch actually runs the tests for picolibc behind an emulator,
removing a few workarounds and increasing coverage.

Differential Revision: https://reviews.llvm.org/D155521
2023-11-29 17:21:08 -05:00
Michael Platings
8aeacebf28 [libc++] Add initial support for picolibc
Picolibc is a C Standard Library that is commonly used in embedded
environments. This patch adds initial support for this configuration
along with pre-commit CI. As of this patch, the test suite only builds
the tests and nothing is run. A follow-up patch will make the test suite
actually run the tests.

Differential Revision: https://reviews.llvm.org/D154246
2023-11-29 10:43:16 -05:00
Mark de Wever
efac016e32
[NFC][libc++] Refactors the time.cal tests. (#73356)
These tests use an old way to test code in constexpr context. This
changes the code to the idomatic libc++ method.

This is a preparation for #73162.

Side changes
- Updated formatting
- Made some helper functions constexpr
- Some naming improvements
2023-11-28 19:19:21 +01:00
Stephan T. Lavavej
f5832bab6f
[libc++][test] Cleanup typos and unnecessary semicolons (#73435)
I've structured this into a series of commits for even easier reviewing,
if that helps. I could easily split this up into separate PRs if
desired, but as this is low-risk with simple edits, I thought one PR
would be easiest.

* Drop unnecessary semicolons after function definitions.
* Cleanup comment typos.
* Cleanup `static_assert` typos.
* Cleanup test code typos.
+ There should be no functional changes, assuming I've changed all
occurrences.
* ~~Fix massive test code typos.~~
+ This was a real problem, but needed more surgery. I reverted those
changes here, and @philnik777 is fixing this properly with #73444.
* clang-formatting as requested by the CI.
2023-11-27 02:11:24 +01:00
Louis Dionne
9bb9ec380a
[libc++][NFC] Simplify checks for static assertions in .verify.cpp tests (#67559)
We don't neeed to handle both spellings anymore since we don't support
Clang 15 anymore.
2023-09-28 09:07:08 -04:00
Mark de Wever
88359213ee [libc++][chrono] TZDB CI fixes.
Fixes a conflict with adding the no experimental module build.

Disables some tests that need further investigation, this should fix the
CI runners.

These issues were reported on Discord and in D154282.
2023-09-07 20:31:18 +02:00
Mark de Wever
f78f93bc9f [libc++][chrono] Adds tzdb_list implementation.
This is the first step to implement time zone support in libc++. This
adds the complete tzdb_list class and a minimal tzdb class. The tzdb
class only contains the version, which is used by reload_tzdb.

Next to these classes it contains documentation and build system support
needed for time zone support. The code depends on the IANA Time Zone
Database, which should be available on the platform used or provided by
the libc++ vendors.

The code is labeled as experimental since there will be ABI breaks
during development; the tzdb class needs to have the standard headers.

Implements parts of:
- P0355 Extending <chrono> to Calendars and Time Zones

Addresses:
- LWG3319 Properly reference specification of IANA time zone database

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D154282
2023-09-06 20:48:07 +02:00
Louis Dionne
b397921fc7 [runtimes] Fix some duplicate word typos
Those fixes were taken from https://reviews.llvm.org/D137338.
2023-08-31 11:55:10 -04:00
Mark de Wever
8f01029b17 [libc++][chrono] Fixes FreeBSD tests.
This adjusts the output of the tests to match reality.

Reviewed By: emaste, #libc, dim, philnik

Differential Revision: https://reviews.llvm.org/D157778
2023-08-17 18:00:25 +02:00
Mark de Wever
b9f3d241f4 [libc++][format] Fixes times before epoch.
The number of days should be rounded down, for both positive and
negative times since epoch. The original code truncated, which is
correct for positive values, but wrong for negative values.

Depends on D138826

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D154865
2023-07-18 21:17:11 +02:00
Mark de Wever
402eb2ef09 [libc++][format] Improves diagnostics.
Improves both the compile-time and run-time errors.
At compile-time it does a bit more work to get more specific errors.
This could be done at run-time too, but that has a performance penalty.
Since it's expected most use-cases use format* instead of vformat* the
compile-time errors are more common.

For example when using

  std::format_to("{:-c}", 42);

Before compile output would contain

  std::__throw_format_error("The format-spec should consume the input or end with a '}'");

Now it contains

  std::__throw_format_error("The format specifier does not allow the sign option");

Given a better indication the sign option is not allowed. Note the
output is still not user-friendly; C++ doesn't have good facilities to
generate nice messages from the library.

In general all messages have been reviewed and improved, using a more
consistent style and using less terms used in the standard. For example

  format-spec -> format specifier
  arg-id -> argument index

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D152624
2023-07-18 21:11:12 +02:00
Mark de Wever
ab0d757bcf [libc++][chrono] Fixes month inc and dec operations.
The operator++, operator++(int), operator--, and operator--(int) need to
change the month to a valid value. The wording is specified in terms of
  operator+(const month& x, const months& y) noexcept;
which has the correct behavior. The aforementioned operators instead
used ++/-- on the internal value direction, resulting in incorrect
behaviour.

As a drive-by improve the unit tests:
- use the typical constexpr test method
- test whether the month is valid after the operations
- format the tests

Fixes: https://llvm.org/PR63912

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D155504
2023-07-18 17:32:11 +02:00
Mark de Wever
a4814bdc53 [libc++][chrono] Fixes formatter duration.
@EricWF spotted this issue in the post-commit review comments of
D134742. However the suggestion to just use chrono calculations can
result in similar issues when using small fractional seconds.

Reviewed By: EricWF, #libc

Differential Revision: https://reviews.llvm.org/D138826
2023-07-15 12:02:03 +02:00