Upgrade to 2022-era LLVM LIBCXX

This commit is contained in:
Justine Tunney 2024-05-27 02:12:27 -07:00
parent 2f4ca71f26
commit 8e68384e15
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
2078 changed files with 165657 additions and 65010 deletions

View file

@ -0,0 +1,54 @@
// -*- C++ -*-
//===----------------------------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
#ifndef _LIBCPP___SUPPORT_IBM_GETTOD_ZOS_H
#define _LIBCPP___SUPPORT_IBM_GETTOD_ZOS_H
#include <time.h>
inline _LIBCPP_HIDE_FROM_ABI int
gettimeofdayMonotonic(struct timespec64* Output) {
// The POSIX gettimeofday() function is not available on z/OS. Therefore,
// we will call stcke and other hardware instructions in implement equivalent.
// Note that nanoseconds alone will overflow when reaching new epoch in 2042.
struct _t {
uint64_t Hi;
uint64_t Lo;
};
struct _t Value = {0, 0};
uint64_t CC = 0;
asm(" stcke %0\n"
" ipm %1\n"
" srlg %1,%1,28\n"
: "=m"(Value), "+r"(CC)::);
if (CC != 0) {
errno = EMVSTODNOTSET;
return CC;
}
uint64_t us = (Value.Hi >> 4);
uint64_t ns = ((Value.Hi & 0x0F) << 8) + (Value.Lo >> 56);
ns = (ns * 1000) >> 12;
us = us - 2208988800000000;
register uint64_t DivPair0 asm("r0"); // dividend (upper half), remainder
DivPair0 = 0;
register uint64_t DivPair1 asm("r1"); // dividend (lower half), quotient
DivPair1 = us;
uint64_t Divisor = 1000000;
asm(" dlgr %0,%2" : "+r"(DivPair0), "+r"(DivPair1) : "r"(Divisor) :);
Output->tv_sec = DivPair1;
Output->tv_nsec = DivPair0 * 1000 + ns;
return 0;
}
#endif // _LIBCPP___SUPPORT_IBM_GETTOD_ZOS_H

View file

@ -0,0 +1,53 @@
// -*- C++ -*-
//===----------------------------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
#ifndef _LIBCPP___SUPPORT_IBM_LOCALE_MGMT_ZOS_H
#define _LIBCPP___SUPPORT_IBM_LOCALE_MGMT_ZOS_H
#if defined(__MVS__)
#include <locale.h>
#include <string>
#ifdef __cplusplus
extern "C" {
#endif
#define _LC_MAX LC_MESSAGES /* highest real category */
#define _NCAT (_LC_MAX + 1) /* maximum + 1 */
#define _CATMASK(n) (1 << (n))
#define LC_COLLATE_MASK _CATMASK(LC_COLLATE)
#define LC_CTYPE_MASK _CATMASK(LC_CTYPE)
#define LC_MONETARY_MASK _CATMASK(LC_MONETARY)
#define LC_NUMERIC_MASK _CATMASK(LC_NUMERIC)
#define LC_TIME_MASK _CATMASK(LC_TIME)
#define LC_MESSAGES_MASK _CATMASK(LC_MESSAGES)
#define LC_ALL_MASK (_CATMASK(_NCAT) - 1)
typedef struct locale_struct {
int category_mask;
std::string lc_collate;
std::string lc_ctype;
std::string lc_monetary;
std::string lc_numeric;
std::string lc_time;
std::string lc_messages;
} * locale_t;
// z/OS does not have newlocale, freelocale and uselocale.
// The functions below are workarounds in single thread mode.
locale_t newlocale(int category_mask, const char* locale, locale_t base);
void freelocale(locale_t locobj);
locale_t uselocale(locale_t newloc);
#ifdef __cplusplus
}
#endif
#endif // defined(__MVS__)
#endif // _LIBCPP___SUPPORT_IBM_LOCALE_MGMT_ZOS_H

View file

@ -0,0 +1,55 @@
// -*- C++ -*-
//===----------------------------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
#ifndef _LIBCPP___SUPPORT_IBM_NANOSLEEP_H
#define _LIBCPP___SUPPORT_IBM_NANOSLEEP_H
#include <unistd.h>
inline int nanosleep(const struct timespec* __req, struct timespec* __rem) {
// The nanosleep() function is not available on z/OS. Therefore, we will call
// sleep() to sleep for whole seconds and usleep() to sleep for any remaining
// fraction of a second. Any remaining nanoseconds will round up to the next
// microsecond.
if (__req->tv_sec < 0 || __req->tv_nsec < 0 || __req->tv_nsec > 999999999) {
errno = EINVAL;
return -1;
}
long __micro_sec = (__req->tv_nsec + 999) / 1000;
time_t __sec = __req->tv_sec;
if (__micro_sec > 999999) {
++__sec;
__micro_sec -= 1000000;
}
__sec = static_cast<time_t>(sleep(static_cast<unsigned int>(__sec)));
if (__sec) {
if (__rem) {
// Updating the remaining time to sleep in case of unsuccessful call to sleep().
__rem->tv_sec = __sec;
__rem->tv_nsec = __micro_sec * 1000;
}
errno = EINTR;
return -1;
}
if (__micro_sec) {
int __rt = usleep(static_cast<unsigned int>(__micro_sec));
if (__rt != 0 && __rem) {
// The usleep() does not provide the amount of remaining time upon its failure,
// so the time slept will be ignored.
__rem->tv_sec = 0;
__rem->tv_nsec = __micro_sec * 1000;
// The errno is already set.
return -1;
}
return __rt;
}
return 0;
}
#endif // _LIBCPP___SUPPORT_IBM_NANOSLEEP_H

View file

@ -0,0 +1,129 @@
// -*- C++ -*-
//===-----------------------------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
#ifndef _LIBCPP___SUPPORT_IBM_XLOCALE_H
#define _LIBCPP___SUPPORT_IBM_XLOCALE_H
#if defined(__MVS__)
#include <__support/ibm/locale_mgmt_zos.h>
#endif // defined(__MVS__)
#include <stdarg.h>
#include "cstdlib"
#ifdef __cplusplus
extern "C" {
#endif
#if defined(__MVS__)
#include <wctype.h>
// POSIX routines
#include <__support/xlocale/__posix_l_fallback.h>
#endif // defined(__MVS__)
namespace {
struct __setAndRestore {
explicit __setAndRestore(locale_t locale) {
if (locale == (locale_t)0) {
__cloc = newlocale(LC_ALL_MASK, "C", /* base */ (locale_t)0);
__stored = uselocale(__cloc);
} else {
__stored = uselocale(locale);
}
}
~__setAndRestore() {
uselocale(__stored);
if (__cloc)
freelocale(__cloc);
}
private:
locale_t __stored = (locale_t)0;
locale_t __cloc = (locale_t)0;
};
} // namespace
// The following are not POSIX routines. These are quick-and-dirty hacks
// to make things pretend to work
inline _LIBCPP_HIDE_FROM_ABI long long
strtoll_l(const char *__nptr, char **__endptr, int __base, locale_t locale) {
__setAndRestore __newloc(locale);
return ::strtoll(__nptr, __endptr, __base);
}
inline _LIBCPP_HIDE_FROM_ABI long
strtol_l(const char *__nptr, char **__endptr, int __base, locale_t locale) {
__setAndRestore __newloc(locale);
return ::strtol(__nptr, __endptr, __base);
}
inline _LIBCPP_HIDE_FROM_ABI double
strtod_l(const char *__nptr, char **__endptr, locale_t locale) {
__setAndRestore __newloc(locale);
return ::strtod(__nptr, __endptr);
}
inline _LIBCPP_HIDE_FROM_ABI float
strtof_l(const char *__nptr, char **__endptr, locale_t locale) {
__setAndRestore __newloc(locale);
return ::strtof(__nptr, __endptr);
}
inline _LIBCPP_HIDE_FROM_ABI long double
strtold_l(const char *__nptr, char **__endptr, locale_t locale) {
__setAndRestore __newloc(locale);
return ::strtold(__nptr, __endptr);
}
inline _LIBCPP_HIDE_FROM_ABI unsigned long long
strtoull_l(const char *__nptr, char **__endptr, int __base, locale_t locale) {
__setAndRestore __newloc(locale);
return ::strtoull(__nptr, __endptr, __base);
}
inline _LIBCPP_HIDE_FROM_ABI unsigned long
strtoul_l(const char *__nptr, char **__endptr, int __base, locale_t locale) {
__setAndRestore __newloc(locale);
return ::strtoul(__nptr, __endptr, __base);
}
inline _LIBCPP_HIDE_FROM_ABI int
vasprintf(char **strp, const char *fmt, va_list ap) {
const size_t buff_size = 256;
if ((*strp = (char *)malloc(buff_size)) == NULL) {
return -1;
}
va_list ap_copy;
// va_copy may not be provided by the C library in C++ 03 mode.
#if defined(_LIBCPP_CXX03_LANG) && __has_builtin(__builtin_va_copy)
__builtin_va_copy(ap_copy, ap);
#else
va_copy(ap_copy, ap);
#endif
int str_size = vsnprintf(*strp, buff_size, fmt, ap_copy);
va_end(ap_copy);
if ((size_t) str_size >= buff_size) {
if ((*strp = (char *)realloc(*strp, str_size + 1)) == NULL) {
return -1;
}
str_size = vsnprintf(*strp, str_size + 1, fmt, ap);
}
return str_size;
}
#ifdef __cplusplus
}
#endif
#endif // _LIBCPP___SUPPORT_IBM_XLOCALE_H