Add dontthrow attribute to most libc functions

This will help C++ code that uses exceptions to be tinier. For example,
this change shaves away 1000 lines of assembly code from LLVM's libcxx,
which is 0.7% of all assembly instructions in the entire library.
This commit is contained in:
Justine Tunney 2024-01-09 01:26:03 -08:00
parent cb19e172da
commit eeb20775d2
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
103 changed files with 1455 additions and 1456 deletions

View file

@ -5,39 +5,38 @@ COSMOPOLITAN_C_START_
int abs(int) libcesque pureconst;
long labs(long) libcesque pureconst;
long long llabs(long long) libcesque pureconst;
intmax_t imaxabs(intmax_t)
libcesque pureconst;
libcesque intmax_t imaxabs(intmax_t) pureconst;
int atoi(const char *) paramsnonnull() libcesque;
long atol(const char *) paramsnonnull() libcesque;
long long atoll(const char *) paramsnonnull() libcesque;
unsigned long strtoul(const char *, char **, int) paramsnonnull((1));
long long strtoll(const char *, char **, int) paramsnonnull((1));
unsigned long strtoul(const char *, char **, int) libcesque paramsnonnull((1));
long long strtoll(const char *, char **, int) libcesque paramsnonnull((1));
unsigned long long strtoull(const char *, char **, int) paramsnonnull((1));
intmax_t strtoimax(const char *, char **, int) paramsnonnull((1));
uintmax_t strtoumax(const char *, char **, int) paramsnonnull((1));
intmax_t wcstoimax(const wchar_t *, wchar_t **, int);
uintmax_t wcstoumax(const wchar_t *, wchar_t **, int);
long wcstol(const wchar_t *, wchar_t **, int);
unsigned long wcstoul(const wchar_t *, wchar_t **, int);
intmax_t strtoimax(const char *, char **, int) libcesque paramsnonnull((1));
uintmax_t strtoumax(const char *, char **, int) libcesque paramsnonnull((1));
intmax_t wcstoimax(const wchar_t *, wchar_t **, int) libcesque;
uintmax_t wcstoumax(const wchar_t *, wchar_t **, int) libcesque;
long wcstol(const wchar_t *, wchar_t **, int) libcesque;
unsigned long wcstoul(const wchar_t *, wchar_t **, int) libcesque;
long strtol(const char *, char **, int) paramsnonnull((1)) libcesque;
long sizetol(const char *, long) paramsnonnull() libcesque;
char *sizefmt(char *, uint64_t, uint64_t);
long long wcstoll(const wchar_t *, wchar_t **, int);
unsigned long long wcstoull(const wchar_t *, wchar_t **, int);
int wcscoll(const wchar_t *, const wchar_t *);
size_t wcsxfrm(wchar_t *, const wchar_t *, size_t);
char *sizefmt(char *, uint64_t, uint64_t) libcesque;
long long wcstoll(const wchar_t *, wchar_t **, int) libcesque;
unsigned long long wcstoull(const wchar_t *, wchar_t **, int) libcesque;
int wcscoll(const wchar_t *, const wchar_t *) libcesque;
size_t wcsxfrm(wchar_t *, const wchar_t *, size_t) libcesque;
double atof(const char *);
float strtof(const char *, char **);
double strtod(const char *, char **);
long double strtold(const char *, char **);
float wcstof(const wchar_t *, wchar_t **);
double wcstod(const wchar_t *, wchar_t **);
long double wcstold(const wchar_t *, wchar_t **);
double atof(const char *) libcesque;
float strtof(const char *, char **) libcesque;
double strtod(const char *, char **) libcesque;
long double strtold(const char *, char **) libcesque;
float wcstof(const wchar_t *, wchar_t **) libcesque;
double wcstod(const wchar_t *, wchar_t **) libcesque;
long double wcstold(const wchar_t *, wchar_t **) libcesque;
#ifdef _COSMO_SOURCE
char *stripext(char *);
char *stripexts(char *);
char *stripext(char *) libcesque;
char *stripexts(char *) libcesque;
#endif /* _COSMO_SOURCE */
typedef struct {
@ -60,10 +59,10 @@ typedef struct {
intmax_t rem;
} imaxdiv_t;
div_t div(int, int) pureconst;
ldiv_t ldiv(long, long) pureconst;
lldiv_t lldiv(long long, long long) pureconst;
imaxdiv_t imaxdiv(intmax_t, intmax_t) pureconst;
libcesque div_t div(int, int) pureconst;
libcesque ldiv_t ldiv(long, long) pureconst;
libcesque lldiv_t lldiv(long long, long long) pureconst;
libcesque imaxdiv_t imaxdiv(intmax_t, intmax_t) pureconst;
#if __STDC_VERSION__ + 0 >= 199901L
#define div(num, den) ((div_t){(num) / (den), (num) % (den)})

View file

@ -22,24 +22,24 @@ COSMOPOLITAN_C_START_
#define uint64toarray_fixed16 __uint64toarray_fixed16
#define uint64toarray_radix8 __uint64toarray_radix8
unsigned LengthInt64(int64_t) pureconst;
unsigned LengthUint64(uint64_t) pureconst;
unsigned LengthInt64Thousands(int64_t) pureconst;
unsigned LengthUint64Thousands(uint64_t) pureconst;
char *FormatInt32(char[hasatleast 12], int32_t);
char *FormatUint32(char[hasatleast 12], uint32_t);
char *FormatInt64(char[hasatleast 21], int64_t);
char *FormatUint64(char[hasatleast 21], uint64_t);
char *FormatInt64Thousands(char[hasatleast 27], int64_t);
char *FormatUint64Thousands(char[hasatleast 27], uint64_t);
char *FormatOctal32(char[hasatleast 13], uint32_t, bool32);
char *FormatOctal64(char[hasatleast 24], uint64_t, bool32);
char *FormatBinary64(char[hasatleast 67], uint64_t, char);
char *FormatHex64(char[hasatleast 19], uint64_t, char);
char *FormatFlex64(char[hasatleast 24], int64_t, char);
size_t uint64toarray_radix16(uint64_t, char[hasatleast 17]);
size_t uint64toarray_fixed16(uint64_t, char[hasatleast 17], uint8_t);
size_t uint64toarray_radix8(uint64_t, char[hasatleast 24]);
libcesque unsigned LengthInt64(int64_t) pureconst;
libcesque unsigned LengthUint64(uint64_t) pureconst;
libcesque unsigned LengthInt64Thousands(int64_t) pureconst;
libcesque unsigned LengthUint64Thousands(uint64_t) pureconst;
libcesque char *FormatInt32(char[hasatleast 12], int32_t);
libcesque char *FormatUint32(char[hasatleast 12], uint32_t);
libcesque char *FormatInt64(char[hasatleast 21], int64_t);
libcesque char *FormatUint64(char[hasatleast 21], uint64_t);
libcesque char *FormatInt64Thousands(char[hasatleast 27], int64_t);
libcesque char *FormatUint64Thousands(char[hasatleast 27], uint64_t);
libcesque char *FormatOctal32(char[hasatleast 13], uint32_t, bool32);
libcesque char *FormatOctal64(char[hasatleast 24], uint64_t, bool32);
libcesque char *FormatBinary64(char[hasatleast 67], uint64_t, char);
libcesque char *FormatHex64(char[hasatleast 19], uint64_t, char);
libcesque char *FormatFlex64(char[hasatleast 24], int64_t, char);
libcesque size_t uint64toarray_radix16(uint64_t, char[hasatleast 17]);
libcesque size_t uint64toarray_fixed16(uint64_t, char[hasatleast 17], uint8_t);
libcesque size_t uint64toarray_radix8(uint64_t, char[hasatleast 24]);
COSMOPOLITAN_C_END_
#endif /* _COSMO_SOURCE */

View file

@ -9,11 +9,11 @@ COSMOPOLITAN_C_START_
#define unzleb64 __unzleb64
#define unuleb64 __unuleb64
char *sleb64(char *, int64_t);
char *zleb64(char[hasatleast 10], int64_t);
char *uleb64(char[hasatleast 10], uint64_t);
int unzleb64(const char *, size_t, int64_t *);
int unuleb64(const char *, size_t, uint64_t *);
char *sleb64(char *, int64_t) libcesque;
char *zleb64(char[hasatleast 10], int64_t) libcesque;
char *uleb64(char[hasatleast 10], uint64_t) libcesque;
int unzleb64(const char *, size_t, int64_t *) libcesque;
int unuleb64(const char *, size_t, uint64_t *) libcesque;
COSMOPOLITAN_C_END_
#endif /* _COSMO_SOURCE */

View file

@ -2,8 +2,8 @@
#define COSMOPOLITAN_LIBC_FMT_LIBGEN_H_
COSMOPOLITAN_C_START_
char *dirname(char *);
char *basename(char *);
char *dirname(char *) libcesque;
char *basename(char *) libcesque;
COSMOPOLITAN_C_END_
#endif /* COSMOPOLITAN_LIBC_FMT_LIBGEN_H_ */

View file

@ -9,13 +9,13 @@
COSMOPOLITAN_C_START_
int64_t DosDateTimeToUnix(uint32_t, uint32_t) pureconst;
int64_t TimeSpecToWindowsTime(struct timespec) pureconst;
int64_t TimeValToWindowsTime(struct timeval) pureconst;
struct timespec WindowsDurationToTimeSpec(int64_t) pureconst;
struct timespec WindowsTimeToTimeSpec(int64_t) pureconst;
struct timeval WindowsDurationToTimeVal(int64_t) pureconst;
struct timeval WindowsTimeToTimeVal(int64_t) pureconst;
libcesque int64_t DosDateTimeToUnix(uint32_t, uint32_t) pureconst;
libcesque int64_t TimeSpecToWindowsTime(struct timespec) pureconst;
libcesque int64_t TimeValToWindowsTime(struct timeval) pureconst;
libcesque struct timespec WindowsDurationToTimeSpec(int64_t) pureconst;
libcesque struct timespec WindowsTimeToTimeSpec(int64_t) pureconst;
libcesque struct timeval WindowsDurationToTimeVal(int64_t) pureconst;
libcesque struct timeval WindowsTimeToTimeVal(int64_t) pureconst;
#define MakeFileTime(x) \
({ \