HomePhabricator

Initial commit of mktime.

Authored by rtenneti on Nov 30 2020, 9:06 PM.

Description

Initial commit of mktime.

This introduces mktime to LLVM libc, based on C99/C2X/Single Unix Spec.

Co-authored-by: Jeff Bailey <jeffbailey@google.com>

This change doesn't handle TIMEZONE, tm_isdst and leap seconds. It returns -1 for invalid dates. I have verified the return results for all the possible dates with glibc's mktime.

TODO:
+ Handle leap seconds.
+ Handle out of range time and date values that don't overflow or underflow.
+ Implement the following suggestion Siva - As we start accumulating the seconds, we should be able to check if the next amount of seconds to be added can lead to an overflow. If it does, return the overflow value. If not keep accumulating. The benefit is that, we don't have to validate every input, and also do not need the special cases for sizeof(time_t) == 4.
+ Handle timezone and update of tm_isdst

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D91551

Details

Committed
rtennetiNov 30 2020, 9:07 PM
Reviewer
sivachandra
Differential Revision
D91551: Initial commit of mktime.
Parents
rG40659cd2c6f4: [RISCV] Rename RISCVGenSystemOperands.inc to RISCVGenSearchableTables.inc to…
Branches
Unknown
Tags
Unknown

Event Timeline

As far as I can tell, this implemention incorrectly returns overflow for 32-bit time_t for 00:00:08 UTC Jan 1 2038 since you forgot to check that the month, day, hour, and minute are equal to the 32-bit overflow time before checking that the seconds overflow. likewise for day, hour and minute.