diff --git a/libc/config/linux/x86_64/syscall.h.inc b/libc/config/linux/x86_64/syscall.h.inc --- a/libc/config/linux/x86_64/syscall.h.inc +++ b/libc/config/linux/x86_64/syscall.h.inc @@ -14,92 +14,93 @@ namespace __llvm_libc { -__attribute__((always_inline)) inline long syscall(long __number) { - long retcode; - LIBC_INLINE_ASM("syscall" - : "=a"(retcode) - : "a"(__number) - : SYSCALL_CLOBBER_LIST); - return retcode; -} + __attribute__((always_inline)) inline long syscall(long __number) noexcept { + long retcode; + LIBC_INLINE_ASM("syscall" + : "=a"(retcode) + : "a"(__number) + : SYSCALL_CLOBBER_LIST); + return retcode; + } -__attribute__((always_inline)) inline long syscall(long __number, long __arg1) { - long retcode; - LIBC_INLINE_ASM("syscall" - : "=a"(retcode) - : "a"(__number), "D"(__arg1) - : SYSCALL_CLOBBER_LIST); - return retcode; -} + __attribute__((always_inline)) inline long syscall(long __number, + long __arg1) noexcept { + long retcode; + LIBC_INLINE_ASM("syscall" + : "=a"(retcode) + : "a"(__number), "D"(__arg1) + : SYSCALL_CLOBBER_LIST); + return retcode; + } -__attribute__((always_inline)) inline long syscall(long __number, long __arg1, - long __arg2) { - long retcode; - LIBC_INLINE_ASM("syscall" - : "=a"(retcode) - : "a"(__number), "D"(__arg1), "S"(__arg2) - : SYSCALL_CLOBBER_LIST); - return retcode; -} + __attribute__((always_inline)) inline long syscall(long __number, long __arg1, + long __arg2) noexcept { + long retcode; + LIBC_INLINE_ASM("syscall" + : "=a"(retcode) + : "a"(__number), "D"(__arg1), "S"(__arg2) + : SYSCALL_CLOBBER_LIST); + return retcode; + } -__attribute__((always_inline)) inline long syscall(long __number, long __arg1, - long __arg2, long __arg3) { - long retcode; - LIBC_INLINE_ASM("syscall" - : "=a"(retcode) - : "a"(__number), "D"(__arg1), "S"(__arg2), "d"(__arg3) - : SYSCALL_CLOBBER_LIST); - return retcode; -} + __attribute__((always_inline)) inline long syscall( + long __number, long __arg1, long __arg2, long __arg3) noexcept { + long retcode; + LIBC_INLINE_ASM("syscall" + : "=a"(retcode) + : "a"(__number), "D"(__arg1), "S"(__arg2), "d"(__arg3) + : SYSCALL_CLOBBER_LIST); + return retcode; + } -__attribute__((always_inline)) inline long -syscall(long __number, long __arg1, long __arg2, long __arg3, long __arg4) { - long retcode; - register long r10 __asm__("r10") = __arg4; - LIBC_INLINE_ASM("syscall" - : "=a"(retcode) - : "a"(__number), "D"(__arg1), "S"(__arg2), "d"(__arg3), - "r"(r10) - : SYSCALL_CLOBBER_LIST); - return retcode; -} + __attribute__((always_inline)) inline long syscall(long __number, long __arg1, + long __arg2, long __arg3, + long __arg4) noexcept { + long retcode; + register long r10 __asm__("r10") = __arg4; + LIBC_INLINE_ASM("syscall" + : "=a"(retcode) + : "a"(__number), "D"(__arg1), "S"(__arg2), "d"(__arg3), + "r"(r10) + : SYSCALL_CLOBBER_LIST); + return retcode; + } -__attribute__((always_inline)) inline long syscall(long __number, long __arg1, - long __arg2, long __arg3, - long __arg4, long __arg5) { - long retcode; - register long r10 __asm__("r10") = __arg4; - register long r8 __asm__("r8") = __arg5; - LIBC_INLINE_ASM("syscall" - : "=a"(retcode) - : "a"(__number), "D"(__arg1), "S"(__arg2), "d"(__arg3), - "r"(r10), "r"(r8) - : SYSCALL_CLOBBER_LIST); - return retcode; -} + __attribute__((always_inline)) inline long syscall( + long __number, long __arg1, long __arg2, long __arg3, long __arg4, + long __arg5) noexcept { + long retcode; + register long r10 __asm__("r10") = __arg4; + register long r8 __asm__("r8") = __arg5; + LIBC_INLINE_ASM("syscall" + : "=a"(retcode) + : "a"(__number), "D"(__arg1), "S"(__arg2), "d"(__arg3), + "r"(r10), "r"(r8) + : SYSCALL_CLOBBER_LIST); + return retcode; + } -__attribute__((always_inline)) inline long syscall(long __number, long __arg1, - long __arg2, long __arg3, - long __arg4, long __arg5, - long __arg6) { - long retcode; - register long r10 __asm__("r10") = __arg4; - register long r8 __asm__("r8") = __arg5; - register long r9 __asm__("r9") = __arg6; - LIBC_INLINE_ASM("syscall" - : "=a"(retcode) - : "a"(__number), "D"(__arg1), "S"(__arg2), "d"(__arg3), - "r"(r10), "r"(r8), "r"(r9) - : SYSCALL_CLOBBER_LIST); - return retcode; -} - -template -__attribute__((always_inline)) inline long syscall(long __number, Ts... ts) { - static_assert(sizeof...(Ts) <= 6, "Too many arguments for syscall"); - return syscall(__number, (long)ts...); -} + __attribute__((always_inline)) inline long syscall( + long __number, long __arg1, long __arg2, long __arg3, long __arg4, + long __arg5, long __arg6) noexcept { + long retcode; + register long r10 __asm__("r10") = __arg4; + register long r8 __asm__("r8") = __arg5; + register long r9 __asm__("r9") = __arg6; + LIBC_INLINE_ASM("syscall" + : "=a"(retcode) + : "a"(__number), "D"(__arg1), "S"(__arg2), "d"(__arg3), + "r"(r10), "r"(r8), "r"(r9) + : SYSCALL_CLOBBER_LIST); + return retcode; + } + template + __attribute__((always_inline)) inline long syscall(long __number, + Ts... ts) noexcept { + static_assert(sizeof...(Ts) <= 6, "Too many arguments for syscall"); + return syscall(__number, static_cast(ts...)); + } #undef SYSCALL_CLOBBER_LIST diff --git a/libc/src/__support/common.h b/libc/src/__support/common.h --- a/libc/src/__support/common.h +++ b/libc/src/__support/common.h @@ -24,9 +24,9 @@ LLVM_LIBC_FUNCTION_ATTR decltype(__llvm_libc::name) \ __##name##_impl__ __asm__(#name); \ decltype(__llvm_libc::name) name [[gnu::alias(#name)]]; \ - type __##name##_impl__ arglist + type __##name##_impl__ arglist noexcept #else -#define LLVM_LIBC_FUNCTION(type, name, arglist) type name arglist +#define LLVM_LIBC_FUNCTION(type, name, arglist) type name arglist noexcept #endif namespace __llvm_libc { diff --git a/libc/src/__support/integer_operations.h b/libc/src/__support/integer_operations.h --- a/libc/src/__support/integer_operations.h +++ b/libc/src/__support/integer_operations.h @@ -14,10 +14,8 @@ namespace __llvm_libc { template -static inline cpp::EnableIfType::Value, T> integerAbs(T n) { - if (n < 0) - return -n; - return n; +static constexpr inline cpp::EnableIfType::Value, T> integerAbs(T n) { + return (n < 0) ? -n : n; } } // namespace __llvm_libc diff --git a/libc/src/assert/__assert_fail.cpp b/libc/src/assert/__assert_fail.cpp --- a/libc/src/assert/__assert_fail.cpp +++ b/libc/src/assert/__assert_fail.cpp @@ -18,15 +18,16 @@ // This is just a temporary solution to make assert available to internal // llvm libc code. In the future writeToStderr will not exist and __assert_fail // will call fprintf(stderr, ...). -static void writeToStderr(const char *s) { +static void writeToStderr(const char *s) noexcept { size_t length = 0; - for (const char *curr = s; *curr; ++curr, ++length); + for (const char *curr = s; *curr; ++curr) + ++length; __llvm_libc::syscall(SYS_write, 2, s, length); } -LLVM_LIBC_FUNCTION(void, __assert_fail, - (const char *assertion, const char *file, unsigned line, - const char *function)) { +[[noreturn]] LLVM_LIBC_FUNCTION(void, __assert_fail, + (const char *assertion, const char *file, + unsigned line, const char *function)) { writeToStderr(file); writeToStderr(": Assertion failed: '"); writeToStderr(assertion); diff --git a/libc/src/ctype/ctype_utils.h b/libc/src/ctype/ctype_utils.h --- a/libc/src/ctype/ctype_utils.h +++ b/libc/src/ctype/ctype_utils.h @@ -18,17 +18,17 @@ // of a function call by inlining them. // ------------------------------------------------------ -static inline int isalpha(unsigned ch) { return (ch | 32) - 'a' < 26; } +static constexpr int isalpha(unsigned ch) { return (ch | 32) - 'a' < 26; } -static inline int isdigit(unsigned ch) { return (ch - '0') < 10; } +static constexpr int isdigit(unsigned ch) { return (ch - '0') < 10; } -static inline int isalnum(unsigned ch) { return isalpha(ch) || isdigit(ch); } +static constexpr int isalnum(unsigned ch) { return isalpha(ch) || isdigit(ch); } -static inline int isgraph(unsigned ch) { return 0x20 < ch && ch < 0x7f; } +static constexpr int isgraph(unsigned ch) { return 0x20 < ch && ch < 0x7f; } -static inline int islower(unsigned ch) { return (ch - 'a') < 26; } +static constexpr int islower(unsigned ch) { return (ch - 'a') < 26; } -static inline int isupper(unsigned ch) { return (ch - 'A') < 26; } +static constexpr int isupper(unsigned ch) { return (ch - 'A') < 26; } } // namespace internal } // namespace __llvm_libc diff --git a/libc/src/ctype/isalnum.cpp b/libc/src/ctype/isalnum.cpp --- a/libc/src/ctype/isalnum.cpp +++ b/libc/src/ctype/isalnum.cpp @@ -15,6 +15,8 @@ // TODO: Currently restricted to default locale. // These should be extended using locale information. -LLVM_LIBC_FUNCTION(int, isalnum, (int c)) { return internal::isalnum(c); } +LLVM_LIBC_FUNCTION(int, isalnum, (int c)) { + return internal::isalnum(static_cast(c)); +} } // namespace __llvm_libc diff --git a/libc/src/ctype/isalpha.h b/libc/src/ctype/isalpha.h --- a/libc/src/ctype/isalpha.h +++ b/libc/src/ctype/isalpha.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -int isalpha(int c); +int isalpha(int c) noexcept; } // namespace __llvm_libc diff --git a/libc/src/ctype/isalpha.cpp b/libc/src/ctype/isalpha.cpp --- a/libc/src/ctype/isalpha.cpp +++ b/libc/src/ctype/isalpha.cpp @@ -15,6 +15,8 @@ // TODO: Currently restricted to default locale. // These should be extended using locale information. -LLVM_LIBC_FUNCTION(int, isalpha, (int c)) { return internal::isalpha(c); } +LLVM_LIBC_FUNCTION(int, isalpha, (int c)) { + return internal::isalpha(static_cast(c)); +} } // namespace __llvm_libc diff --git a/libc/src/ctype/isascii.h b/libc/src/ctype/isascii.h --- a/libc/src/ctype/isascii.h +++ b/libc/src/ctype/isascii.h @@ -13,7 +13,7 @@ namespace __llvm_libc { -int isascii(int c); +int isascii(int c) noexcept; } // namespace __llvm_libc diff --git a/libc/src/ctype/isascii.cpp b/libc/src/ctype/isascii.cpp --- a/libc/src/ctype/isascii.cpp +++ b/libc/src/ctype/isascii.cpp @@ -12,6 +12,8 @@ namespace __llvm_libc { -LLVM_LIBC_FUNCTION(int, isascii, (int c)) { return (c & (~0x7f)) == 0; } +LLVM_LIBC_FUNCTION(int, isascii, (int c)) { + return static_cast(c) <= 0x7f; +} } // namespace __llvm_libc diff --git a/libc/src/ctype/isblank.h b/libc/src/ctype/isblank.h --- a/libc/src/ctype/isblank.h +++ b/libc/src/ctype/isblank.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -int isblank(int c); +int isblank(int c) noexcept; } // namespace __llvm_libc diff --git a/libc/src/ctype/isblank.cpp b/libc/src/ctype/isblank.cpp --- a/libc/src/ctype/isblank.cpp +++ b/libc/src/ctype/isblank.cpp @@ -15,8 +15,7 @@ // TODO: Currently restricted to default locale. // These should be extended using locale information. LLVM_LIBC_FUNCTION(int, isblank, (int c)) { - const unsigned char ch = static_cast(c); - return ch == ' ' || ch == '\t'; + return c == ' ' || c == '\t'; } } // namespace __llvm_libc diff --git a/libc/src/ctype/iscntrl.h b/libc/src/ctype/iscntrl.h --- a/libc/src/ctype/iscntrl.h +++ b/libc/src/ctype/iscntrl.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -int iscntrl(int c); +int iscntrl(int c) noexcept; } // namespace __llvm_libc diff --git a/libc/src/ctype/iscntrl.cpp b/libc/src/ctype/iscntrl.cpp --- a/libc/src/ctype/iscntrl.cpp +++ b/libc/src/ctype/iscntrl.cpp @@ -15,7 +15,7 @@ // TODO: Currently restricted to default locale. // These should be extended using locale information. LLVM_LIBC_FUNCTION(int, iscntrl, (int c)) { - const unsigned char ch = static_cast(c); + const unsigned ch = static_cast(c); return ch < 0x20 || ch == 0x7f; } diff --git a/libc/src/ctype/isdigit.h b/libc/src/ctype/isdigit.h --- a/libc/src/ctype/isdigit.h +++ b/libc/src/ctype/isdigit.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -int isdigit(int c); +int isdigit(int c) noexcept; } // namespace __llvm_libc diff --git a/libc/src/ctype/isdigit.cpp b/libc/src/ctype/isdigit.cpp --- a/libc/src/ctype/isdigit.cpp +++ b/libc/src/ctype/isdigit.cpp @@ -14,6 +14,8 @@ // TODO: Currently restricted to default locale. // These should be extended using locale information. -LLVM_LIBC_FUNCTION(int, isdigit, (int c)) { return internal::isdigit(c); } +LLVM_LIBC_FUNCTION(int, isdigit, (int c)) { + return internal::isdigit(static_cast(c)); +} } // namespace __llvm_libc diff --git a/libc/src/ctype/isgraph.h b/libc/src/ctype/isgraph.h --- a/libc/src/ctype/isgraph.h +++ b/libc/src/ctype/isgraph.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -int isgraph(int c); +int isgraph(int c) noexcept; } // namespace __llvm_libc diff --git a/libc/src/ctype/isgraph.cpp b/libc/src/ctype/isgraph.cpp --- a/libc/src/ctype/isgraph.cpp +++ b/libc/src/ctype/isgraph.cpp @@ -15,6 +15,8 @@ // TODO: Currently restricted to default locale. // These should be extended using locale information. -LLVM_LIBC_FUNCTION(int, isgraph, (int c)) { return internal::isgraph(c); } +LLVM_LIBC_FUNCTION(int, isgraph, (int c)) { + return internal::isgraph(static_cast(c)); +} } // namespace __llvm_libc diff --git a/libc/src/ctype/islower.h b/libc/src/ctype/islower.h --- a/libc/src/ctype/islower.h +++ b/libc/src/ctype/islower.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -int islower(int c); +int islower(int c) noexcept; } // namespace __llvm_libc diff --git a/libc/src/ctype/islower.cpp b/libc/src/ctype/islower.cpp --- a/libc/src/ctype/islower.cpp +++ b/libc/src/ctype/islower.cpp @@ -15,6 +15,8 @@ // TODO: Currently restricted to default locale. // These should be extended using locale information. -LLVM_LIBC_FUNCTION(int, islower, (int c)) { return internal::islower(c); } +LLVM_LIBC_FUNCTION(int, islower, (int c)) { + return internal::islower(static_cast(c)); +} } // namespace __llvm_libc diff --git a/libc/src/ctype/isprint.h b/libc/src/ctype/isprint.h --- a/libc/src/ctype/isprint.h +++ b/libc/src/ctype/isprint.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -int isprint(int c); +int isprint(int c) noexcept; } // namespace __llvm_libc diff --git a/libc/src/ctype/isprint.cpp b/libc/src/ctype/isprint.cpp --- a/libc/src/ctype/isprint.cpp +++ b/libc/src/ctype/isprint.cpp @@ -15,7 +15,7 @@ // TODO: Currently restricted to default locale. // These should be extended using locale information. LLVM_LIBC_FUNCTION(int, isprint, (int c)) { - const unsigned ch = c; + const unsigned ch = static_cast(c); return (ch - ' ') < 95; } diff --git a/libc/src/ctype/ispunct.h b/libc/src/ctype/ispunct.h --- a/libc/src/ctype/ispunct.h +++ b/libc/src/ctype/ispunct.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -int ispunct(int c); +int ispunct(int c) noexcept; } // namespace __llvm_libc diff --git a/libc/src/ctype/ispunct.cpp b/libc/src/ctype/ispunct.cpp --- a/libc/src/ctype/ispunct.cpp +++ b/libc/src/ctype/ispunct.cpp @@ -16,7 +16,8 @@ // TODO: Currently restricted to default locale. // These should be extended using locale information. LLVM_LIBC_FUNCTION(int, ispunct, (int c)) { - return !internal::isalnum(c) && internal::isgraph(c); + const unsigned ch = static_cast(c); + return !internal::isalnum(ch) && internal::isgraph(ch); } } // namespace __llvm_libc diff --git a/libc/src/ctype/isspace.h b/libc/src/ctype/isspace.h --- a/libc/src/ctype/isspace.h +++ b/libc/src/ctype/isspace.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -int isspace(int c); +int isspace(int c) noexcept; } // namespace __llvm_libc diff --git a/libc/src/ctype/isspace.cpp b/libc/src/ctype/isspace.cpp --- a/libc/src/ctype/isspace.cpp +++ b/libc/src/ctype/isspace.cpp @@ -15,7 +15,7 @@ // TODO: Currently restricted to default locale. // These should be extended using locale information. LLVM_LIBC_FUNCTION(int, isspace, (int c)) { - const unsigned ch = c; + const unsigned ch = static_cast(c); return ch == ' ' || (ch - '\t') < 5; } diff --git a/libc/src/ctype/isupper.h b/libc/src/ctype/isupper.h --- a/libc/src/ctype/isupper.h +++ b/libc/src/ctype/isupper.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -int isupper(int c); +int isupper(int c) noexcept; } // namespace __llvm_libc diff --git a/libc/src/ctype/isupper.cpp b/libc/src/ctype/isupper.cpp --- a/libc/src/ctype/isupper.cpp +++ b/libc/src/ctype/isupper.cpp @@ -15,6 +15,8 @@ // TODO: Currently restricted to default locale. // These should be extended using locale information. -LLVM_LIBC_FUNCTION(int, isupper, (int c)) { return internal::isupper(c); } +LLVM_LIBC_FUNCTION(int, isupper, (int c)) { + return internal::isupper(static_cast(c)); +} } // namespace __llvm_libc diff --git a/libc/src/ctype/isxdigit.h b/libc/src/ctype/isxdigit.h --- a/libc/src/ctype/isxdigit.h +++ b/libc/src/ctype/isxdigit.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -int isxdigit(int c); +int isxdigit(int c) noexcept; } // namespace __llvm_libc diff --git a/libc/src/ctype/isxdigit.cpp b/libc/src/ctype/isxdigit.cpp --- a/libc/src/ctype/isxdigit.cpp +++ b/libc/src/ctype/isxdigit.cpp @@ -16,7 +16,7 @@ // TODO: Currently restricted to default locale. // These should be extended using locale information. LLVM_LIBC_FUNCTION(int, isxdigit, (int c)) { - const unsigned ch = c; + const unsigned ch = static_cast(c); return internal::isdigit(ch) || (ch | 32) - 'a' < 6; } diff --git a/libc/src/ctype/toascii.h b/libc/src/ctype/toascii.h --- a/libc/src/ctype/toascii.h +++ b/libc/src/ctype/toascii.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -int toascii(int c); +int toascii(int c) noexcept; } // namespace __llvm_libc diff --git a/libc/src/ctype/tolower.h b/libc/src/ctype/tolower.h --- a/libc/src/ctype/tolower.h +++ b/libc/src/ctype/tolower.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -int tolower(int c); +int tolower(int c) noexcept; } // namespace __llvm_libc diff --git a/libc/src/ctype/tolower.cpp b/libc/src/ctype/tolower.cpp --- a/libc/src/ctype/tolower.cpp +++ b/libc/src/ctype/tolower.cpp @@ -16,7 +16,7 @@ // TODO: Currently restricted to default locale. // These should be extended using locale information. LLVM_LIBC_FUNCTION(int, tolower, (int c)) { - if (internal::isupper(c)) + if (internal::isupper(static_cast(c))) return c + 'a' - 'A'; return c; } diff --git a/libc/src/ctype/toupper.h b/libc/src/ctype/toupper.h --- a/libc/src/ctype/toupper.h +++ b/libc/src/ctype/toupper.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -int toupper(int c); +int toupper(int c) noexcept; } // namespace __llvm_libc diff --git a/libc/src/ctype/toupper.cpp b/libc/src/ctype/toupper.cpp --- a/libc/src/ctype/toupper.cpp +++ b/libc/src/ctype/toupper.cpp @@ -16,7 +16,7 @@ // TODO: Currently restricted to default locale. // These should be extended using locale information. LLVM_LIBC_FUNCTION(int, toupper, (int c)) { - if (internal::islower(c)) + if (internal::islower(static_cast(c))) return c + 'A' - 'a'; return c; } diff --git a/libc/src/errno/__errno_location.h b/libc/src/errno/__errno_location.h --- a/libc/src/errno/__errno_location.h +++ b/libc/src/errno/__errno_location.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -int *__errno_location(); +int *__errno_location() noexcept; } // namespace __llvm_libc diff --git a/libc/src/fenv/feclearexcept.h b/libc/src/fenv/feclearexcept.h --- a/libc/src/fenv/feclearexcept.h +++ b/libc/src/fenv/feclearexcept.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -int feclearexcept(int); +int feclearexcept(int) noexcept; } // namespace __llvm_libc diff --git a/libc/src/fenv/fegetenv.h b/libc/src/fenv/fegetenv.h --- a/libc/src/fenv/fegetenv.h +++ b/libc/src/fenv/fegetenv.h @@ -13,7 +13,7 @@ namespace __llvm_libc { -int fegetenv(fenv_t *); +int fegetenv(fenv_t *) noexcept; } // namespace __llvm_libc diff --git a/libc/src/fenv/fegetexceptflag.h b/libc/src/fenv/fegetexceptflag.h --- a/libc/src/fenv/fegetexceptflag.h +++ b/libc/src/fenv/fegetexceptflag.h @@ -13,7 +13,7 @@ namespace __llvm_libc { -int fegetexceptflag(fexcept_t *, int excepts); +int fegetexceptflag(fexcept_t *, int excepts) noexcept; } // namespace __llvm_libc diff --git a/libc/src/fenv/fegetround.h b/libc/src/fenv/fegetround.h --- a/libc/src/fenv/fegetround.h +++ b/libc/src/fenv/fegetround.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -int fegetround(); +int fegetround() noexcept; } // namespace __llvm_libc diff --git a/libc/src/fenv/feholdexcept.h b/libc/src/fenv/feholdexcept.h --- a/libc/src/fenv/feholdexcept.h +++ b/libc/src/fenv/feholdexcept.h @@ -13,7 +13,7 @@ namespace __llvm_libc { -int feholdexcept(fenv_t *); +int feholdexcept(fenv_t *) noexcept; } // namespace __llvm_libc diff --git a/libc/src/fenv/feraiseexcept.h b/libc/src/fenv/feraiseexcept.h --- a/libc/src/fenv/feraiseexcept.h +++ b/libc/src/fenv/feraiseexcept.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -int feraiseexcept(int); +int feraiseexcept(int) noexcept; } // namespace __llvm_libc diff --git a/libc/src/fenv/fesetenv.h b/libc/src/fenv/fesetenv.h --- a/libc/src/fenv/fesetenv.h +++ b/libc/src/fenv/fesetenv.h @@ -13,7 +13,7 @@ namespace __llvm_libc { -int fesetenv(const fenv_t *); +int fesetenv(const fenv_t *) noexcept; } // namespace __llvm_libc diff --git a/libc/src/fenv/fesetexceptflag.h b/libc/src/fenv/fesetexceptflag.h --- a/libc/src/fenv/fesetexceptflag.h +++ b/libc/src/fenv/fesetexceptflag.h @@ -13,7 +13,7 @@ namespace __llvm_libc { -int fesetexceptflag(const fexcept_t *, int excepts); +int fesetexceptflag(const fexcept_t *, int excepts) noexcept; } // namespace __llvm_libc diff --git a/libc/src/fenv/fesetround.h b/libc/src/fenv/fesetround.h --- a/libc/src/fenv/fesetround.h +++ b/libc/src/fenv/fesetround.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -int fesetround(int); +int fesetround(int) noexcept; } // namespace __llvm_libc diff --git a/libc/src/fenv/fetestexcept.h b/libc/src/fenv/fetestexcept.h --- a/libc/src/fenv/fetestexcept.h +++ b/libc/src/fenv/fetestexcept.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -int fetestexcept(int); +int fetestexcept(int) noexcept; } // namespace __llvm_libc diff --git a/libc/src/fenv/feupdateenv.h b/libc/src/fenv/feupdateenv.h --- a/libc/src/fenv/feupdateenv.h +++ b/libc/src/fenv/feupdateenv.h @@ -13,7 +13,7 @@ namespace __llvm_libc { -int feupdateenv(const fenv_t *); +int feupdateenv(const fenv_t *) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/ceil.h b/libc/src/math/ceil.h --- a/libc/src/math/ceil.h +++ b/libc/src/math/ceil.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -double ceil(double x); +double ceil(double x) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/ceilf.h b/libc/src/math/ceilf.h --- a/libc/src/math/ceilf.h +++ b/libc/src/math/ceilf.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -float ceilf(float x); +float ceilf(float x) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/ceill.h b/libc/src/math/ceill.h --- a/libc/src/math/ceill.h +++ b/libc/src/math/ceill.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -long double ceill(long double x); +long double ceill(long double x) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/copysign.h b/libc/src/math/copysign.h --- a/libc/src/math/copysign.h +++ b/libc/src/math/copysign.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -double copysign(double x, double y); +double copysign(double x, double y) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/copysignf.h b/libc/src/math/copysignf.h --- a/libc/src/math/copysignf.h +++ b/libc/src/math/copysignf.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -float copysignf(float x, float y); +float copysignf(float x, float y) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/copysignl.h b/libc/src/math/copysignl.h --- a/libc/src/math/copysignl.h +++ b/libc/src/math/copysignl.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -long double copysignl(long double x, long double y); +long double copysignl(long double x, long double y) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/cos.h b/libc/src/math/cos.h --- a/libc/src/math/cos.h +++ b/libc/src/math/cos.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -double cos(double x); +double cos(double x) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/cosf.h b/libc/src/math/cosf.h --- a/libc/src/math/cosf.h +++ b/libc/src/math/cosf.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -float cosf(float x); +float cosf(float x) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/exp2f.h b/libc/src/math/exp2f.h --- a/libc/src/math/exp2f.h +++ b/libc/src/math/exp2f.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -float exp2f(float x); +float exp2f(float x) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/expf.h b/libc/src/math/expf.h --- a/libc/src/math/expf.h +++ b/libc/src/math/expf.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -float expf(float x); +float expf(float x) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/expm1f.h b/libc/src/math/expm1f.h --- a/libc/src/math/expm1f.h +++ b/libc/src/math/expm1f.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -float expm1f(float x); +float expm1f(float x) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/fabs.h b/libc/src/math/fabs.h --- a/libc/src/math/fabs.h +++ b/libc/src/math/fabs.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -double fabs(double x); +double fabs(double x) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/fabsf.h b/libc/src/math/fabsf.h --- a/libc/src/math/fabsf.h +++ b/libc/src/math/fabsf.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -float fabsf(float x); +float fabsf(float x) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/fabsl.h b/libc/src/math/fabsl.h --- a/libc/src/math/fabsl.h +++ b/libc/src/math/fabsl.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -long double fabsl(long double x); +long double fabsl(long double x) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/fdim.h b/libc/src/math/fdim.h --- a/libc/src/math/fdim.h +++ b/libc/src/math/fdim.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -double fdim(double x, double y); +double fdim(double x, double y) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/fdimf.h b/libc/src/math/fdimf.h --- a/libc/src/math/fdimf.h +++ b/libc/src/math/fdimf.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -float fdimf(float x, float y); +float fdimf(float x, float y) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/fdiml.h b/libc/src/math/fdiml.h --- a/libc/src/math/fdiml.h +++ b/libc/src/math/fdiml.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -long double fdiml(long double x, long double y); +long double fdiml(long double x, long double y) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/floor.h b/libc/src/math/floor.h --- a/libc/src/math/floor.h +++ b/libc/src/math/floor.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -double floor(double x); +double floor(double x) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/floorf.h b/libc/src/math/floorf.h --- a/libc/src/math/floorf.h +++ b/libc/src/math/floorf.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -float floorf(float x); +float floorf(float x) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/floorl.h b/libc/src/math/floorl.h --- a/libc/src/math/floorl.h +++ b/libc/src/math/floorl.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -long double floorl(long double x); +long double floorl(long double x) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/fma.h b/libc/src/math/fma.h --- a/libc/src/math/fma.h +++ b/libc/src/math/fma.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -double fma(double x, double y, double z); +double fma(double x, double y, double z) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/fmaf.h b/libc/src/math/fmaf.h --- a/libc/src/math/fmaf.h +++ b/libc/src/math/fmaf.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -float fmaf(float x, float y, float z); +float fmaf(float x, float y, float z) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/fmax.h b/libc/src/math/fmax.h --- a/libc/src/math/fmax.h +++ b/libc/src/math/fmax.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -double fmax(double x, double y); +double fmax(double x, double y) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/fmaxf.h b/libc/src/math/fmaxf.h --- a/libc/src/math/fmaxf.h +++ b/libc/src/math/fmaxf.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -float fmaxf(float x, float y); +float fmaxf(float x, float y) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/fmaxl.h b/libc/src/math/fmaxl.h --- a/libc/src/math/fmaxl.h +++ b/libc/src/math/fmaxl.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -long double fmaxl(long double x, long double y); +long double fmaxl(long double x, long double y) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/fmin.h b/libc/src/math/fmin.h --- a/libc/src/math/fmin.h +++ b/libc/src/math/fmin.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -double fmin(double x, double y); +double fmin(double x, double y) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/fminf.h b/libc/src/math/fminf.h --- a/libc/src/math/fminf.h +++ b/libc/src/math/fminf.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -float fminf(float x, float y); +float fminf(float x, float y) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/fminl.h b/libc/src/math/fminl.h --- a/libc/src/math/fminl.h +++ b/libc/src/math/fminl.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -long double fminl(long double x, long double y); +long double fminl(long double x, long double y) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/frexp.h b/libc/src/math/frexp.h --- a/libc/src/math/frexp.h +++ b/libc/src/math/frexp.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -double frexp(double x, int *exp); +double frexp(double x, int *exp) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/frexpf.h b/libc/src/math/frexpf.h --- a/libc/src/math/frexpf.h +++ b/libc/src/math/frexpf.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -float frexpf(float x, int *exp); +float frexpf(float x, int *exp) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/frexpl.h b/libc/src/math/frexpl.h --- a/libc/src/math/frexpl.h +++ b/libc/src/math/frexpl.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -long double frexpl(long double x, int *exp); +long double frexpl(long double x, int *exp) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/generic/math_utils.h b/libc/src/math/generic/math_utils.h --- a/libc/src/math/generic/math_utils.h +++ b/libc/src/math/generic/math_utils.h @@ -18,25 +18,29 @@ namespace __llvm_libc { -static inline uint32_t as_uint32_bits(float x) { +static inline uint32_t as_uint32_bits(float x) noexcept { return *reinterpret_cast(&x); } -static inline uint64_t as_uint64_bits(double x) { +static inline uint64_t as_uint64_bits(double x) noexcept { return *reinterpret_cast(&x); } -static inline float as_float(uint32_t x) { +static inline float as_float(uint32_t x) noexcept { return *reinterpret_cast(&x); } -static inline double as_double(uint64_t x) { +static inline double as_double(uint64_t x) noexcept { return *reinterpret_cast(&x); } -static inline uint32_t top12_bits(float x) { return as_uint32_bits(x) >> 20; } +static inline uint32_t top12_bits(float x) noexcept { + return as_uint32_bits(x) >> 20; +} -static inline uint32_t top12_bits(double x) { return as_uint64_bits(x) >> 52; } +static inline uint32_t top12_bits(double x) noexcept { + return as_uint64_bits(x) >> 52; +} // Values to trigger underflow and overflow. template struct XFlowValues; @@ -53,17 +57,17 @@ static const double may_underflow_value; }; -template static inline T with_errno(T x, int err) { +template static inline T with_errno(T x, int err) noexcept { if (math_errhandling & MATH_ERRNO) errno = err; // NOLINT return x; } -template static inline void force_eval(T x) { +template static inline void force_eval(T x) noexcept { volatile T y UNUSED = x; } -template static inline T opt_barrier(T x) { +template static inline T opt_barrier(T x) noexcept { volatile T y = x; return y; } @@ -77,28 +81,30 @@ using EnableIfFloatOrDouble = cpp::EnableIfType::Value, int>; template = 0> -T xflow(uint32_t sign, T y) { +T xflow(uint32_t sign, T y) noexcept { // Underflow happens when two extremely small values are multiplied. // Likewise, overflow happens when two large values are multiplied. y = opt_barrier(sign ? -y : y) * y; return with_errno(y, ERANGE); } -template = 0> T overflow(uint32_t sign) { +template = 0> +T overflow(uint32_t sign) noexcept { return xflow(sign, XFlowValues::overflow_value); } -template = 0> T underflow(uint32_t sign) { +template = 0> +T underflow(uint32_t sign) noexcept { return xflow(sign, XFlowValues::underflow_value); } template = 0> -T may_underflow(uint32_t sign) { +T may_underflow(uint32_t sign) noexcept { return xflow(sign, XFlowValues::may_underflow_value); } template = 0> -static inline constexpr float invalid(T x) { +static constexpr float invalid(T x) { T y = (x - x) / (x - x); return isnan(x) ? y : with_errno(y, EDOM); } diff --git a/libc/src/math/generic/sincosf_utils.h b/libc/src/math/generic/sincosf_utils.h --- a/libc/src/math/generic/sincosf_utils.h +++ b/libc/src/math/generic/sincosf_utils.h @@ -36,7 +36,7 @@ extern const uint32_t __inv_pio4[]; // Top 12 bits of the float representation with the sign bit cleared. -static inline uint32_t abstop12(float x) { +static inline uint32_t abstop12(float x) noexcept { return (as_uint32_bits(x) >> 20) & 0x7ff; } @@ -44,7 +44,7 @@ // polynomial P and store the results in SINP and COSP. N is the quadrant, // if odd the cosine and sine polynomials are swapped. static inline void sincosf_poly(double x, double x2, const sincos_t *p, int n, - float *sinp, float *cosp) { + float *sinp, float *cosp) noexcept { double x3, x4, x5, x6, s, c, c1, c2, s1; x4 = x2 * x2; @@ -70,7 +70,8 @@ // Return the sine of inputs X and X2 (X squared) using the polynomial P. // N is the quadrant, and if odd the cosine polynomial is used. -static inline float sinf_poly(double x, double x2, const sincos_t *p, int n) { +static inline float sinf_poly(double x, double x2, const sincos_t *p, + int n) noexcept { double x3, x4, x6, x7, s, c, c1, c2, s1; if ((n & 1) == 0) { @@ -98,7 +99,8 @@ // The values for PI/2 and 2/PI are accessed via P. Since PI/2 as a double // is accurate to 55 bits and the worst-case cancellation happens at 6 * PI/4, // the result is accurate for |X| <= 120.0. -static inline double reduce_fast(double x, const sincos_t *p, int *np) { +static inline double reduce_fast(double x, const sincos_t *p, + int *np) noexcept { double r; // Use scaled float to int conversion with explicit rounding. // hpi_inv is prescaled by 2^24 so the quadrant ends up in bits 24..31. @@ -116,7 +118,7 @@ // multiply computes the exact 2.62-bit fixed-point modulo. Since the result // can have at most 29 leading zeros after the binary point, the double // precision result is accurate to 33 bits. -static inline double reduce_large(uint32_t xi, int *np) { +static inline double reduce_large(uint32_t xi, int *np) noexcept { const uint32_t *arr = &__inv_pio4[(xi >> 26) & 15]; int shift = (xi >> 23) & 7; uint64_t n, res0, res1, res2; diff --git a/libc/src/math/hypot.h b/libc/src/math/hypot.h --- a/libc/src/math/hypot.h +++ b/libc/src/math/hypot.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -double hypot(double x, double y); +double hypot(double x, double y) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/hypotf.h b/libc/src/math/hypotf.h --- a/libc/src/math/hypotf.h +++ b/libc/src/math/hypotf.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -float hypotf(float x, float y); +float hypotf(float x, float y) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/ilogb.h b/libc/src/math/ilogb.h --- a/libc/src/math/ilogb.h +++ b/libc/src/math/ilogb.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -int ilogb(double x); +int ilogb(double x) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/ilogbf.h b/libc/src/math/ilogbf.h --- a/libc/src/math/ilogbf.h +++ b/libc/src/math/ilogbf.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -int ilogbf(float x); +int ilogbf(float x) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/ilogbl.h b/libc/src/math/ilogbl.h --- a/libc/src/math/ilogbl.h +++ b/libc/src/math/ilogbl.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -int ilogbl(long double x); +int ilogbl(long double x) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/ldexp.h b/libc/src/math/ldexp.h --- a/libc/src/math/ldexp.h +++ b/libc/src/math/ldexp.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -double ldexp(double x, int exp); +double ldexp(double x, int exp) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/ldexpf.h b/libc/src/math/ldexpf.h --- a/libc/src/math/ldexpf.h +++ b/libc/src/math/ldexpf.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -float ldexpf(float x, int exp); +float ldexpf(float x, int exp) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/ldexpl.h b/libc/src/math/ldexpl.h --- a/libc/src/math/ldexpl.h +++ b/libc/src/math/ldexpl.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -long double ldexpl(long double x, int exp); +long double ldexpl(long double x, int exp) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/llrint.h b/libc/src/math/llrint.h --- a/libc/src/math/llrint.h +++ b/libc/src/math/llrint.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -long long llrint(double x); +long long llrint(double x) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/llrintf.h b/libc/src/math/llrintf.h --- a/libc/src/math/llrintf.h +++ b/libc/src/math/llrintf.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -long long llrintf(float x); +long long llrintf(float x) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/llrintl.h b/libc/src/math/llrintl.h --- a/libc/src/math/llrintl.h +++ b/libc/src/math/llrintl.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -long long llrintl(long double x); +long long llrintl(long double x) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/llround.h b/libc/src/math/llround.h --- a/libc/src/math/llround.h +++ b/libc/src/math/llround.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -long long llround(double x); +long long llround(double x) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/llroundf.h b/libc/src/math/llroundf.h --- a/libc/src/math/llroundf.h +++ b/libc/src/math/llroundf.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -long long llroundf(float x); +long long llroundf(float x) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/llroundl.h b/libc/src/math/llroundl.h --- a/libc/src/math/llroundl.h +++ b/libc/src/math/llroundl.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -long long llroundl(long double x); +long long llroundl(long double x) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/logb.h b/libc/src/math/logb.h --- a/libc/src/math/logb.h +++ b/libc/src/math/logb.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -double logb(double x); +double logb(double x) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/logbf.h b/libc/src/math/logbf.h --- a/libc/src/math/logbf.h +++ b/libc/src/math/logbf.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -float logbf(float x); +float logbf(float x) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/logbl.h b/libc/src/math/logbl.h --- a/libc/src/math/logbl.h +++ b/libc/src/math/logbl.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -long double logbl(long double x); +long double logbl(long double x) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/lrint.h b/libc/src/math/lrint.h --- a/libc/src/math/lrint.h +++ b/libc/src/math/lrint.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -long lrint(double x); +long lrint(double x) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/lrintf.h b/libc/src/math/lrintf.h --- a/libc/src/math/lrintf.h +++ b/libc/src/math/lrintf.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -long lrintf(float x); +long lrintf(float x) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/lrintl.h b/libc/src/math/lrintl.h --- a/libc/src/math/lrintl.h +++ b/libc/src/math/lrintl.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -long lrintl(long double x); +long lrintl(long double x) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/lround.h b/libc/src/math/lround.h --- a/libc/src/math/lround.h +++ b/libc/src/math/lround.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -long lround(double x); +long lround(double x) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/lroundf.h b/libc/src/math/lroundf.h --- a/libc/src/math/lroundf.h +++ b/libc/src/math/lroundf.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -long lroundf(float x); +long lroundf(float x) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/lroundl.h b/libc/src/math/lroundl.h --- a/libc/src/math/lroundl.h +++ b/libc/src/math/lroundl.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -long lroundl(long double x); +long lroundl(long double x) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/modf.h b/libc/src/math/modf.h --- a/libc/src/math/modf.h +++ b/libc/src/math/modf.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -double modf(double x, double *iptr); +double modf(double x, double *iptr) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/modff.h b/libc/src/math/modff.h --- a/libc/src/math/modff.h +++ b/libc/src/math/modff.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -float modff(float x, float *iptr); +float modff(float x, float *iptr) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/modfl.h b/libc/src/math/modfl.h --- a/libc/src/math/modfl.h +++ b/libc/src/math/modfl.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -long double modfl(long double x, long double *iptr); +long double modfl(long double x, long double *iptr) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/nearbyint.h b/libc/src/math/nearbyint.h --- a/libc/src/math/nearbyint.h +++ b/libc/src/math/nearbyint.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -double nearbyint(double x); +double nearbyint(double x) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/nearbyintf.h b/libc/src/math/nearbyintf.h --- a/libc/src/math/nearbyintf.h +++ b/libc/src/math/nearbyintf.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -float nearbyintf(float x); +float nearbyintf(float x) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/nearbyintl.h b/libc/src/math/nearbyintl.h --- a/libc/src/math/nearbyintl.h +++ b/libc/src/math/nearbyintl.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -long double nearbyintl(long double x); +long double nearbyintl(long double x) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/nextafter.h b/libc/src/math/nextafter.h --- a/libc/src/math/nextafter.h +++ b/libc/src/math/nextafter.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -double nextafter(double x, double y); +double nextafter(double x, double y) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/nextafterf.h b/libc/src/math/nextafterf.h --- a/libc/src/math/nextafterf.h +++ b/libc/src/math/nextafterf.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -float nextafterf(float x, float y); +float nextafterf(float x, float y) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/nextafterl.h b/libc/src/math/nextafterl.h --- a/libc/src/math/nextafterl.h +++ b/libc/src/math/nextafterl.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -long double nextafterl(long double x, long double y); +long double nextafterl(long double x, long double y) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/remainder.h b/libc/src/math/remainder.h --- a/libc/src/math/remainder.h +++ b/libc/src/math/remainder.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -double remainder(double x, double y); +double remainder(double x, double y) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/remainderf.h b/libc/src/math/remainderf.h --- a/libc/src/math/remainderf.h +++ b/libc/src/math/remainderf.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -float remainderf(float x, float y); +float remainderf(float x, float y) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/remainderl.h b/libc/src/math/remainderl.h --- a/libc/src/math/remainderl.h +++ b/libc/src/math/remainderl.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -long double remainderl(long double x, long double y); +long double remainderl(long double x, long double y) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/remquo.h b/libc/src/math/remquo.h --- a/libc/src/math/remquo.h +++ b/libc/src/math/remquo.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -double remquo(double x, double y, int *exp); +double remquo(double x, double y, int *exp) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/remquof.h b/libc/src/math/remquof.h --- a/libc/src/math/remquof.h +++ b/libc/src/math/remquof.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -float remquof(float x, float y, int *exp); +float remquof(float x, float y, int *exp) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/remquol.h b/libc/src/math/remquol.h --- a/libc/src/math/remquol.h +++ b/libc/src/math/remquol.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -long double remquol(long double x, long double y, int *exp); +long double remquol(long double x, long double y, int *exp) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/rint.h b/libc/src/math/rint.h --- a/libc/src/math/rint.h +++ b/libc/src/math/rint.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -double rint(double x); +double rint(double x) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/rintf.h b/libc/src/math/rintf.h --- a/libc/src/math/rintf.h +++ b/libc/src/math/rintf.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -float rintf(float x); +float rintf(float x) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/rintl.h b/libc/src/math/rintl.h --- a/libc/src/math/rintl.h +++ b/libc/src/math/rintl.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -long double rintl(long double x); +long double rintl(long double x) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/round.h b/libc/src/math/round.h --- a/libc/src/math/round.h +++ b/libc/src/math/round.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -double round(double x); +double round(double x) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/roundf.h b/libc/src/math/roundf.h --- a/libc/src/math/roundf.h +++ b/libc/src/math/roundf.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -float roundf(float x); +float roundf(float x) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/roundl.h b/libc/src/math/roundl.h --- a/libc/src/math/roundl.h +++ b/libc/src/math/roundl.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -long double roundl(long double x); +long double roundl(long double x) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/sin.h b/libc/src/math/sin.h --- a/libc/src/math/sin.h +++ b/libc/src/math/sin.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -double sin(double x); +double sin(double x) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/sincosf.h b/libc/src/math/sincosf.h --- a/libc/src/math/sincosf.h +++ b/libc/src/math/sincosf.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -void sincosf(float x, float *sinx, float *cosx); +void sincosf(float x, float *sinx, float *cosx) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/sinf.h b/libc/src/math/sinf.h --- a/libc/src/math/sinf.h +++ b/libc/src/math/sinf.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -float sinf(float x); +float sinf(float x) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/sqrt.h b/libc/src/math/sqrt.h --- a/libc/src/math/sqrt.h +++ b/libc/src/math/sqrt.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -double sqrt(double x); +double sqrt(double x) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/sqrtf.h b/libc/src/math/sqrtf.h --- a/libc/src/math/sqrtf.h +++ b/libc/src/math/sqrtf.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -float sqrtf(float x); +float sqrtf(float x) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/sqrtl.h b/libc/src/math/sqrtl.h --- a/libc/src/math/sqrtl.h +++ b/libc/src/math/sqrtl.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -long double sqrtl(long double x); +long double sqrtl(long double x) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/tan.h b/libc/src/math/tan.h --- a/libc/src/math/tan.h +++ b/libc/src/math/tan.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -double tan(double x); +double tan(double x) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/trunc.h b/libc/src/math/trunc.h --- a/libc/src/math/trunc.h +++ b/libc/src/math/trunc.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -double trunc(double x); +double trunc(double x) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/truncf.h b/libc/src/math/truncf.h --- a/libc/src/math/truncf.h +++ b/libc/src/math/truncf.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -float truncf(float x); +float truncf(float x) noexcept; } // namespace __llvm_libc diff --git a/libc/src/math/truncl.h b/libc/src/math/truncl.h --- a/libc/src/math/truncl.h +++ b/libc/src/math/truncl.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -long double truncl(long double x); +long double truncl(long double x) noexcept; } // namespace __llvm_libc diff --git a/libc/src/signal/linux/sigaction.cpp b/libc/src/signal/linux/sigaction.cpp --- a/libc/src/signal/linux/sigaction.cpp +++ b/libc/src/signal/linux/sigaction.cpp @@ -21,7 +21,7 @@ extern "C" void __restore_rt(); template -static void copySigaction(T &dest, const V &source) { +static void copySigaction(T &dest, const V &source) noexcept { dest.sa_handler = source.sa_handler; dest.sa_mask = source.sa_mask; dest.sa_flags = source.sa_flags; diff --git a/libc/src/signal/linux/sigaddset.cpp b/libc/src/signal/linux/sigaddset.cpp --- a/libc/src/signal/linux/sigaddset.cpp +++ b/libc/src/signal/linux/sigaddset.cpp @@ -15,8 +15,8 @@ namespace __llvm_libc { -LLVM_LIBC_FUNCTION(int, sigaddset, (sigset_t * set, int signum)) { - if (!set || (unsigned)(signum - 1) >= (8 * sizeof(sigset_t))) { +LLVM_LIBC_FUNCTION(int, sigaddset, (sigset_t * set, int signum)) noexcept { + if (!set || static_cast(signum - 1) >= (8 * sizeof(sigset_t))) { llvmlibc_errno = EINVAL; return -1; } diff --git a/libc/src/signal/linux/sigdelset.cpp b/libc/src/signal/linux/sigdelset.cpp --- a/libc/src/signal/linux/sigdelset.cpp +++ b/libc/src/signal/linux/sigdelset.cpp @@ -15,8 +15,8 @@ namespace __llvm_libc { -LLVM_LIBC_FUNCTION(int, sigdelset, (sigset_t * set, int signum)) { - if (!set || (unsigned)(signum - 1) >= (8 * sizeof(sigset_t))) { +LLVM_LIBC_FUNCTION(int, sigdelset, (sigset_t * set, int signum)) noexcept { + if (!set || static_cast(signum - 1) >= (8 * sizeof(sigset_t))) { llvmlibc_errno = EINVAL; return -1; } diff --git a/libc/src/signal/linux/sigemptyset.cpp b/libc/src/signal/linux/sigemptyset.cpp --- a/libc/src/signal/linux/sigemptyset.cpp +++ b/libc/src/signal/linux/sigemptyset.cpp @@ -15,7 +15,7 @@ namespace __llvm_libc { -LLVM_LIBC_FUNCTION(int, sigemptyset, (sigset_t * set)) { +LLVM_LIBC_FUNCTION(int, sigemptyset, (sigset_t * set)) noexcept { if (!set) { llvmlibc_errno = EINVAL; return -1; diff --git a/libc/src/signal/linux/sigfillset.cpp b/libc/src/signal/linux/sigfillset.cpp --- a/libc/src/signal/linux/sigfillset.cpp +++ b/libc/src/signal/linux/sigfillset.cpp @@ -15,7 +15,7 @@ namespace __llvm_libc { -LLVM_LIBC_FUNCTION(int, sigfillset, (sigset_t * set)) { +LLVM_LIBC_FUNCTION(int, sigfillset, (sigset_t * set)) noexcept { if (!set) { llvmlibc_errno = EINVAL; return -1; diff --git a/libc/src/signal/linux/signal.h b/libc/src/signal/linux/signal.h --- a/libc/src/signal/linux/signal.h +++ b/libc/src/signal/linux/signal.h @@ -35,7 +35,7 @@ constexpr static Sigset all = Sigset::fullset(); -static inline int block_all_signals(Sigset &set) { +static inline int block_all_signals(Sigset &set) noexcept { sigset_t nativeSigset = all; sigset_t oldSet = set; int ret = __llvm_libc::syscall(SYS_rt_sigprocmask, SIG_BLOCK, &nativeSigset, @@ -44,7 +44,7 @@ return ret; } -static inline int restore_signals(const Sigset &set) { +static inline int restore_signals(const Sigset &set) noexcept { sigset_t nativeSigset = set; return __llvm_libc::syscall(SYS_rt_sigprocmask, SIG_SETMASK, &nativeSigset, nullptr, sizeof(sigset_t)); diff --git a/libc/src/signal/raise.h b/libc/src/signal/raise.h --- a/libc/src/signal/raise.h +++ b/libc/src/signal/raise.h @@ -13,7 +13,7 @@ namespace __llvm_libc { -int raise(int sig); +int raise(int sig) noexcept; } // namespace __llvm_libc diff --git a/libc/src/signal/sigaction.h b/libc/src/signal/sigaction.h --- a/libc/src/signal/sigaction.h +++ b/libc/src/signal/sigaction.h @@ -15,7 +15,7 @@ namespace __llvm_libc { int sigaction(int signal, const struct __sigaction *__restrict libc_new, - struct __sigaction *__restrict libc_old); + struct __sigaction *__restrict libc_old) noexcept; } // namespace __llvm_libc diff --git a/libc/src/signal/sigaddset.h b/libc/src/signal/sigaddset.h --- a/libc/src/signal/sigaddset.h +++ b/libc/src/signal/sigaddset.h @@ -13,7 +13,7 @@ namespace __llvm_libc { -int sigaddset(sigset_t *set, int signum); +int sigaddset(sigset_t *set, int signum) noexcept; } // namespace __llvm_libc diff --git a/libc/src/signal/sigdelset.h b/libc/src/signal/sigdelset.h --- a/libc/src/signal/sigdelset.h +++ b/libc/src/signal/sigdelset.h @@ -13,7 +13,7 @@ namespace __llvm_libc { -int sigdelset(sigset_t *set, int signum); +int sigdelset(sigset_t *set, int signum) noexcept; } // namespace __llvm_libc diff --git a/libc/src/signal/sigemptyset.h b/libc/src/signal/sigemptyset.h --- a/libc/src/signal/sigemptyset.h +++ b/libc/src/signal/sigemptyset.h @@ -13,7 +13,7 @@ namespace __llvm_libc { -int sigemptyset(sigset_t *set); +int sigemptyset(sigset_t *set) noexcept; } // namespace __llvm_libc diff --git a/libc/src/signal/sigfillset.h b/libc/src/signal/sigfillset.h --- a/libc/src/signal/sigfillset.h +++ b/libc/src/signal/sigfillset.h @@ -13,7 +13,7 @@ namespace __llvm_libc { -int sigfillset(sigset_t *set); +int sigfillset(sigset_t *set) noexcept; } // namespace __llvm_libc diff --git a/libc/src/signal/signal.h b/libc/src/signal/signal.h --- a/libc/src/signal/signal.h +++ b/libc/src/signal/signal.h @@ -15,7 +15,7 @@ using sighandler_t = __sighandler_t; -sighandler_t signal(int signum, sighandler_t handler); +sighandler_t signal(int signum, sighandler_t handler) noexcept; } // namespace __llvm_libc diff --git a/libc/src/signal/sigprocmask.h b/libc/src/signal/sigprocmask.h --- a/libc/src/signal/sigprocmask.h +++ b/libc/src/signal/sigprocmask.h @@ -14,7 +14,7 @@ namespace __llvm_libc { int sigprocmask(int how, const sigset_t *__restrict set, - sigset_t *__restrict oldset); + sigset_t *__restrict oldset) noexcept; } // namespace __llvm_libc diff --git a/libc/src/stdio/FILE.h b/libc/src/stdio/FILE.h --- a/libc/src/stdio/FILE.h +++ b/libc/src/stdio/FILE.h @@ -19,7 +19,7 @@ using write_function_t = size_t(FILE *, const char *, size_t); - write_function_t *write; + write_function_t *write noexcept; }; } // namespace __llvm_libc diff --git a/libc/src/stdio/fwrite.h b/libc/src/stdio/fwrite.h --- a/libc/src/stdio/fwrite.h +++ b/libc/src/stdio/fwrite.h @@ -15,7 +15,7 @@ namespace __llvm_libc { size_t fwrite(const void *__restrict ptr, size_t size, size_t nmeb, - __llvm_libc::FILE *__restrict stream); + __llvm_libc::FILE *__restrict stream) noexcept; } // namespace __llvm_libc diff --git a/libc/src/stdio/fwrite.cpp b/libc/src/stdio/fwrite.cpp --- a/libc/src/stdio/fwrite.cpp +++ b/libc/src/stdio/fwrite.cpp @@ -14,13 +14,13 @@ namespace __llvm_libc { size_t fwrite_unlocked(const void *__restrict ptr, size_t size, size_t nmeb, - __llvm_libc::FILE *__restrict stream) { + __llvm_libc::FILE *__restrict stream) noexcept { return stream->write(stream, reinterpret_cast(ptr), size * nmeb); } size_t fwrite(const void *__restrict ptr, size_t size, size_t nmeb, - __llvm_libc::FILE *__restrict stream) { + __llvm_libc::FILE *__restrict stream) noexcept { __llvm_libc::mtx_lock(&stream->lock); size_t written = fwrite_unlocked(ptr, size, nmeb, stream); __llvm_libc::mtx_unlock(&stream->lock); diff --git a/libc/src/stdlib/abort.cpp b/libc/src/stdlib/abort.cpp --- a/libc/src/stdlib/abort.cpp +++ b/libc/src/stdlib/abort.cpp @@ -14,7 +14,7 @@ namespace __llvm_libc { -LLVM_LIBC_FUNCTION(void, abort, ()) { +[[noreturn]] LLVM_LIBC_FUNCTION(void, abort, ()) { // TODO: When sigprocmask and sigaction land: // Unblock SIGABRT, raise it, if it was ignored or the handler returned, // change its action to SIG_DFL, raise it again. diff --git a/libc/src/stdlib/abs.h b/libc/src/stdlib/abs.h --- a/libc/src/stdlib/abs.h +++ b/libc/src/stdlib/abs.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -int abs(int n); +int abs(int n) noexcept; } // namespace __llvm_libc diff --git a/libc/src/stdlib/labs.h b/libc/src/stdlib/labs.h --- a/libc/src/stdlib/labs.h +++ b/libc/src/stdlib/labs.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -long labs(long n); +long labs(long n) noexcept; } // namespace __llvm_libc diff --git a/libc/src/stdlib/linux/_Exit.cpp b/libc/src/stdlib/linux/_Exit.cpp --- a/libc/src/stdlib/linux/_Exit.cpp +++ b/libc/src/stdlib/linux/_Exit.cpp @@ -14,7 +14,7 @@ namespace __llvm_libc { -LLVM_LIBC_FUNCTION(void, _Exit, (int status)) { +[[noreturn]] LLVM_LIBC_FUNCTION(void, _Exit, (int status)) { for (;;) { __llvm_libc::syscall(SYS_exit_group, status); __llvm_libc::syscall(SYS_exit, status); diff --git a/libc/src/stdlib/llabs.h b/libc/src/stdlib/llabs.h --- a/libc/src/stdlib/llabs.h +++ b/libc/src/stdlib/llabs.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -long long llabs(long long n); +long long llabs(long long n) noexcept; } // namespace __llvm_libc diff --git a/libc/src/string/memchr.h b/libc/src/string/memchr.h --- a/libc/src/string/memchr.h +++ b/libc/src/string/memchr.h @@ -13,7 +13,7 @@ namespace __llvm_libc { -void *memchr(const void *src, int c, size_t n); +void *memchr(const void *src, int c, size_t n) noexcept; } // namespace __llvm_libc diff --git a/libc/src/string/memmove.cpp b/libc/src/string/memmove.cpp --- a/libc/src/string/memmove.cpp +++ b/libc/src/string/memmove.cpp @@ -16,7 +16,7 @@ namespace __llvm_libc { static inline void move_byte_forward(char *dest_m, const char *src_m, - size_t count) { + size_t count) noexcept { for (size_t offset = 0; count; --count, ++offset) dest_m[offset] = src_m[offset]; } diff --git a/libc/src/sys/mman/mmap.h b/libc/src/sys/mman/mmap.h --- a/libc/src/sys/mman/mmap.h +++ b/libc/src/sys/mman/mmap.h @@ -13,7 +13,8 @@ namespace __llvm_libc { -void *mmap(void *addr, size_t size, int prot, int flags, int fd, off_t offset); +void *mmap(void *addr, size_t size, int prot, int flags, int fd, + off_t offset) noexcept; } // namespace __llvm_libc diff --git a/libc/src/sys/mman/munmap.h b/libc/src/sys/mman/munmap.h --- a/libc/src/sys/mman/munmap.h +++ b/libc/src/sys/mman/munmap.h @@ -13,7 +13,7 @@ namespace __llvm_libc { -int munmap(void *addr, size_t size); +int munmap(void *addr, size_t size) noexcept; } // namespace __llvm_libc diff --git a/libc/src/threads/call_once.h b/libc/src/threads/call_once.h --- a/libc/src/threads/call_once.h +++ b/libc/src/threads/call_once.h @@ -13,7 +13,7 @@ namespace __llvm_libc { -void call_once(once_flag *flag, __call_once_func_t func); +void call_once(once_flag *flag, __call_once_func_t func) noexcept; } // namespace __llvm_libc diff --git a/libc/src/threads/linux/thrd_create.cpp b/libc/src/threads/linux/thrd_create.cpp --- a/libc/src/threads/linux/thrd_create.cpp +++ b/libc/src/threads/linux/thrd_create.cpp @@ -30,7 +30,7 @@ void *arg; }; -static __attribute__((noinline)) void start_thread() { +static __attribute__((noinline)) void start_thread() noexcept { StartArgs *start_args = reinterpret_cast(get_start_args_addr()); __llvm_libc::syscall(SYS_exit, start_args->thread->__retval = start_args->func(start_args->arg)); diff --git a/libc/src/threads/linux/x86_64/thread_start_args.h.in b/libc/src/threads/linux/x86_64/thread_start_args.h.in --- a/libc/src/threads/linux/x86_64/thread_start_args.h.in +++ b/libc/src/threads/linux/x86_64/thread_start_args.h.in @@ -10,7 +10,7 @@ namespace __llvm_libc { -__attribute__((always_inline)) inline uintptr_t get_start_args_addr() { +__attribute__((always_inline)) inline uintptr_t get_start_args_addr() noexcept { // NOTE: For __builtin_frame_address to work reliably across compilers, // architectures and various optimization levels, the TU including this file // should be compiled with -fno-omit-frame-pointer. diff --git a/libc/src/threads/mtx_init.h b/libc/src/threads/mtx_init.h --- a/libc/src/threads/mtx_init.h +++ b/libc/src/threads/mtx_init.h @@ -13,7 +13,7 @@ namespace __llvm_libc { -int mtx_init(mtx_t *mutex, int type); +int mtx_init(mtx_t *mutex, int type) noexcept; } // namespace __llvm_libc diff --git a/libc/src/threads/mtx_lock.h b/libc/src/threads/mtx_lock.h --- a/libc/src/threads/mtx_lock.h +++ b/libc/src/threads/mtx_lock.h @@ -13,7 +13,7 @@ namespace __llvm_libc { -int mtx_lock(mtx_t *mutex); +int mtx_lock(mtx_t *mutex) noexcept; } // namespace __llvm_libc diff --git a/libc/src/threads/mtx_unlock.h b/libc/src/threads/mtx_unlock.h --- a/libc/src/threads/mtx_unlock.h +++ b/libc/src/threads/mtx_unlock.h @@ -13,7 +13,7 @@ namespace __llvm_libc { -int mtx_unlock(mtx_t *mutex); +int mtx_unlock(mtx_t *mutex) noexcept; } // namespace __llvm_libc diff --git a/libc/src/threads/thrd_create.h b/libc/src/threads/thrd_create.h --- a/libc/src/threads/thrd_create.h +++ b/libc/src/threads/thrd_create.h @@ -13,7 +13,7 @@ namespace __llvm_libc { -int thrd_create(thrd_t *thread, thrd_start_t func, void *arg); +int thrd_create(thrd_t *thread, thrd_start_t func, void *arg) noexcept; } // namespace __llvm_libc diff --git a/libc/src/threads/thrd_join.h b/libc/src/threads/thrd_join.h --- a/libc/src/threads/thrd_join.h +++ b/libc/src/threads/thrd_join.h @@ -13,7 +13,7 @@ namespace __llvm_libc { -int thrd_join(thrd_t *thread, int *retval); +int thrd_join(thrd_t *thread, int *retval) noexcept; } // namespace __llvm_libc diff --git a/libc/src/time/asctime.h b/libc/src/time/asctime.h --- a/libc/src/time/asctime.h +++ b/libc/src/time/asctime.h @@ -13,7 +13,7 @@ namespace __llvm_libc { -char *asctime(const struct tm *timeptr); +char *asctime(const struct tm *timeptr) noexcept; } // namespace __llvm_libc diff --git a/libc/src/time/asctime_r.h b/libc/src/time/asctime_r.h --- a/libc/src/time/asctime_r.h +++ b/libc/src/time/asctime_r.h @@ -13,7 +13,7 @@ namespace __llvm_libc { -char *asctime_r(const struct tm *timeptr, char *buffer); +char *asctime_r(const struct tm *timeptr, char *buffer) noexcept; } // namespace __llvm_libc diff --git a/libc/src/time/gmtime.h b/libc/src/time/gmtime.h --- a/libc/src/time/gmtime.h +++ b/libc/src/time/gmtime.h @@ -13,7 +13,7 @@ namespace __llvm_libc { -struct tm *gmtime(const time_t *timer); +struct tm *gmtime(const time_t *timer) noexcept; } // namespace __llvm_libc diff --git a/libc/src/time/gmtime_r.h b/libc/src/time/gmtime_r.h --- a/libc/src/time/gmtime_r.h +++ b/libc/src/time/gmtime_r.h @@ -13,7 +13,7 @@ namespace __llvm_libc { -struct tm *gmtime_r(const time_t *timer, struct tm *result); +struct tm *gmtime_r(const time_t *timer, struct tm *result) noexcept; } // namespace __llvm_libc diff --git a/libc/src/time/mktime.h b/libc/src/time/mktime.h --- a/libc/src/time/mktime.h +++ b/libc/src/time/mktime.h @@ -14,7 +14,7 @@ namespace __llvm_libc { -time_t mktime(struct tm *t1); +time_t mktime(struct tm *t1) noexcept; } // namespace __llvm_libc diff --git a/libc/src/time/time_utils.h b/libc/src/time/time_utils.h --- a/libc/src/time/time_utils.h +++ b/libc/src/time/time_utils.h @@ -68,15 +68,15 @@ extern int64_t UpdateFromSeconds(int64_t total_seconds, struct tm *tm); // POSIX.1-2017 requires this. -static inline time_t OutOfRange() { +static inline time_t OutOfRange() noexcept { llvmlibc_errno = EOVERFLOW; return static_cast(-1); } -static inline void InvalidValue() { llvmlibc_errno = EINVAL; } +static inline void InvalidValue() noexcept { llvmlibc_errno = EINVAL; } static inline char *asctime(const struct tm *timeptr, char *buffer, - size_t bufferLength) { + size_t bufferLength) noexcept { if (timeptr == nullptr || buffer == nullptr) { InvalidValue(); return nullptr; @@ -114,7 +114,7 @@ } static inline struct tm *gmtime_internal(const time_t *timer, - struct tm *result) { + struct tm *result) noexcept { int64_t seconds = *timer; // Update the tm structure's year, month, day, etc. from seconds. if (UpdateFromSeconds(seconds, result) < 0) { diff --git a/libc/src/unistd/write.h b/libc/src/unistd/write.h --- a/libc/src/unistd/write.h +++ b/libc/src/unistd/write.h @@ -14,7 +14,7 @@ namespace __llvm_libc { -ssize_t write(int fd, const void *buf, size_t count); +ssize_t write(int fd, const void *buf, size_t count) noexcept; } // namespace __llvm_libc diff --git a/libc/utils/CPP/Array.h b/libc/utils/CPP/Array.h --- a/libc/utils/CPP/Array.h +++ b/libc/utils/CPP/Array.h @@ -43,7 +43,7 @@ constexpr const_iterator begin() const { return Data; } constexpr iterator end() { return Data + N; } - const_iterator end() const { return Data + N; } + const_iterator end() const noexcept { return Data + N; } }; } // namespace cpp diff --git a/libc/utils/CPP/ArrayRef.h b/libc/utils/CPP/ArrayRef.h --- a/libc/utils/CPP/ArrayRef.h +++ b/libc/utils/CPP/ArrayRef.h @@ -50,44 +50,46 @@ template constexpr ArrayRefBase(QualifiedT (&Arr)[N]) : Data(Arr), Length(N) {} - QualifiedT *data() const { return Data; } - size_t size() const { return Length; } + QualifiedT *data() const noexcept { return Data; } + size_t size() const noexcept { return Length; } - auto begin() const { return data(); } - auto end() const { return data() + size(); } + auto begin() const noexcept { return data(); } + auto end() const noexcept { return data() + size(); } - bool empty() const { return size() == 0; } + bool empty() const noexcept { return size() == 0; } auto operator[](size_t Index) const { return data()[Index]; } // slice(n, m) - Chop off the first N elements of the array, and keep M // elements in the array. - auto slice(size_t N, size_t M) const { return ArrayRefBase(data() + N, M); } + auto slice(size_t N, size_t M) const noexcept { + return ArrayRefBase(data() + N, M); + } // slice(n) - Chop off the first N elements of the array. - auto slice(size_t N) const { return slice(N, size() - N); } + auto slice(size_t N) const noexcept { return slice(N, size() - N); } // Drop the first \p N elements of the array. - auto drop_front(size_t N = 1) const { return slice(N, size() - N); } + auto drop_front(size_t N = 1) const noexcept { return slice(N, size() - N); } // Drop the last \p N elements of the array. - auto drop_back(size_t N = 1) const { return slice(0, size() - N); } + auto drop_back(size_t N = 1) const noexcept { return slice(0, size() - N); } // Return a copy of *this with only the first \p N elements. - auto take_front(size_t N = 1) const { + auto take_front(size_t N = 1) const noexcept { if (N >= size()) return *this; return drop_back(size() - N); } // Return a copy of *this with only the last \p N elements. - auto take_back(size_t N = 1) const { + auto take_back(size_t N = 1) const noexcept { if (N >= size()) return *this; return drop_front(size() - N); } // equals - Check for element-wise equality. - bool equals(ArrayRefBase RHS) const { + bool equals(ArrayRefBase RHS) const noexcept { if (Length != RHS.Length) return false; auto First1 = begin(); diff --git a/libc/utils/FPUtil/BasicOperations.h b/libc/utils/FPUtil/BasicOperations.h --- a/libc/utils/FPUtil/BasicOperations.h +++ b/libc/utils/FPUtil/BasicOperations.h @@ -18,7 +18,7 @@ template ::Value, int> = 0> -static inline T abs(T x) { +static inline T abs(T x) noexcept { FPBits bits(x); bits.setSign(0); return T(bits); @@ -26,7 +26,7 @@ template ::Value, int> = 0> -static inline T fmin(T x, T y) { +static inline T fmin(T x, T y) noexcept { FPBits bitx(x), bity(y); if (bitx.isNaN()) { @@ -45,7 +45,7 @@ template ::Value, int> = 0> -static inline T fmax(T x, T y) { +static inline T fmax(T x, T y) noexcept { FPBits bitx(x), bity(y); if (bitx.isNaN()) { diff --git a/libc/utils/FPUtil/DivisionAndRemainderOperations.h b/libc/utils/FPUtil/DivisionAndRemainderOperations.h --- a/libc/utils/FPUtil/DivisionAndRemainderOperations.h +++ b/libc/utils/FPUtil/DivisionAndRemainderOperations.h @@ -24,7 +24,7 @@ // to evaluate the quotient and remainder. template ::Value, int> = 0> -static inline T remquo(T x, T y, int &q) { +static inline T remquo(T x, T y, int &q) noexcept { FPBits xbits(x), ybits(y); if (xbits.isNaN()) return x; diff --git a/libc/utils/FPUtil/FPBits.h b/libc/utils/FPUtil/FPBits.h --- a/libc/utils/FPUtil/FPBits.h +++ b/libc/utils/FPUtil/FPBits.h @@ -48,32 +48,34 @@ UIntType bits; - void setMantissa(UIntType mantVal) { + void setMantissa(UIntType mantVal) noexcept { mantVal &= (FloatProp::mantissaMask); bits &= ~(FloatProp::mantissaMask); bits |= mantVal; } - UIntType getMantissa() const { return bits & FloatProp::mantissaMask; } + UIntType getMantissa() const noexcept { + return bits & FloatProp::mantissaMask; + } - void setUnbiasedExponent(UIntType expVal) { + void setUnbiasedExponent(UIntType expVal) noexcept { expVal = (expVal << (FloatProp::mantissaWidth)) & FloatProp::exponentMask; bits &= ~(FloatProp::exponentMask); bits |= expVal; } - uint16_t getUnbiasedExponent() const { + uint16_t getUnbiasedExponent() const noexcept { return uint16_t((bits & FloatProp::exponentMask) >> (FloatProp::mantissaWidth)); } - void setSign(bool signVal) { + void setSign(bool signVal) noexcept { bits &= ~(FloatProp::signMask); UIntType sign = UIntType(signVal) << (FloatProp::bitWidth - 1); bits |= sign; } - bool getSign() const { + bool getSign() const noexcept { return ((bits & FloatProp::signMask) >> (FloatProp::bitWidth - 1)); } T val; @@ -106,43 +108,47 @@ explicit operator T() { return val; } - UIntType uintval() const { return bits; } + UIntType uintval() const noexcept { return bits; } - int getExponent() const { return int(getUnbiasedExponent()) - exponentBias; } + int getExponent() const noexcept { + return int(getUnbiasedExponent()) - exponentBias; + } - bool isZero() const { + bool isZero() const noexcept { return getMantissa() == 0 && getUnbiasedExponent() == 0; } - bool isInf() const { + bool isInf() const noexcept { return getMantissa() == 0 && getUnbiasedExponent() == maxExponent; } - bool isNaN() const { + bool isNaN() const noexcept { return getUnbiasedExponent() == maxExponent && getMantissa() != 0; } - bool isInfOrNaN() const { return getUnbiasedExponent() == maxExponent; } + bool isInfOrNaN() const noexcept { + return getUnbiasedExponent() == maxExponent; + } - static FPBits zero() { return FPBits(); } + static FPBits zero() noexcept { return FPBits(); } - static FPBits negZero() { + static FPBits negZero() noexcept { return FPBits(UIntType(1) << (sizeof(UIntType) * 8 - 1)); } - static FPBits inf() { + static FPBits inf() noexcept { FPBits bits; bits.setUnbiasedExponent(maxExponent); return bits; } - static FPBits negInf() { + static FPBits negInf() noexcept { FPBits bits = inf(); bits.setSign(1); return bits; } - static T buildNaN(UIntType v) { + static T buildNaN(UIntType v) noexcept { FPBits bits = inf(); bits.setMantissa(v); return T(bits); diff --git a/libc/utils/FPUtil/Hypot.h b/libc/utils/FPUtil/Hypot.h --- a/libc/utils/FPUtil/Hypot.h +++ b/libc/utils/FPUtil/Hypot.h @@ -18,10 +18,10 @@ namespace internal { -template static inline T findLeadingOne(T mant, int &shift_length); +template static inline T findLeadingOne(T mant, int &shift_length) noexcept; template <> -inline uint32_t findLeadingOne(uint32_t mant, int &shift_length) { +inline uint32_t findLeadingOne(uint32_t mant, int &shift_length) noexcept { shift_length = 0; constexpr int nsteps = 5; constexpr uint32_t bounds[nsteps] = {1 << 16, 1 << 8, 1 << 4, 1 << 2, 1 << 1}; @@ -36,7 +36,7 @@ } template <> -inline uint64_t findLeadingOne(uint64_t mant, int &shift_length) { +inline uint64_t findLeadingOne(uint64_t mant, int &shift_length) noexcept { shift_length = 0; constexpr int nsteps = 6; constexpr uint64_t bounds[nsteps] = {1ULL << 32, 1ULL << 16, 1ULL << 8, @@ -117,7 +117,7 @@ // template ::Value, int> = 0> -static inline T hypot(T x, T y) { +static inline T hypot(T x, T y) noexcept { using FPBits_t = FPBits; using UIntType = typename FPBits::UIntType; using DUIntType = typename DoubleLength::Type; diff --git a/libc/utils/FPUtil/LongDoubleBitsX86.h b/libc/utils/FPUtil/LongDoubleBitsX86.h --- a/libc/utils/FPUtil/LongDoubleBitsX86.h +++ b/libc/utils/FPUtil/LongDoubleBitsX86.h @@ -43,43 +43,45 @@ UIntType bits; - void setMantissa(UIntType mantVal) { + void setMantissa(UIntType mantVal) noexcept { mantVal &= (FloatProp::mantissaMask); bits &= ~(FloatProp::mantissaMask); bits |= mantVal; } - UIntType getMantissa() const { return bits & FloatProp::mantissaMask; } + UIntType getMantissa() const noexcept { + return bits & FloatProp::mantissaMask; + } - void setUnbiasedExponent(UIntType expVal) { + void setUnbiasedExponent(UIntType expVal) noexcept { expVal = (expVal << (FloatProp::bitWidth - 1 - FloatProp::exponentWidth)) & FloatProp::exponentMask; bits &= ~(FloatProp::exponentMask); bits |= expVal; } - uint16_t getUnbiasedExponent() const { + uint16_t getUnbiasedExponent() const noexcept { return uint16_t((bits & FloatProp::exponentMask) >> (FloatProp::bitWidth - 1 - FloatProp::exponentWidth)); } - void setImplicitBit(bool implicitVal) { + void setImplicitBit(bool implicitVal) noexcept { bits &= ~(UIntType(1) << FloatProp::mantissaWidth); bits |= (UIntType(implicitVal) << FloatProp::mantissaWidth); } - bool getImplicitBit() const { + bool getImplicitBit() const noexcept { return ((bits & (UIntType(1) << FloatProp::mantissaWidth)) >> FloatProp::mantissaWidth); } - void setSign(bool signVal) { + void setSign(bool signVal) noexcept { bits &= ~(FloatProp::signMask); UIntType sign1 = UIntType(signVal) << (FloatProp::bitWidth - 1); bits |= sign1; } - bool getSign() const { + bool getSign() const noexcept { return ((bits & FloatProp::signMask) >> (FloatProp::bitWidth - 1)); } @@ -106,23 +108,23 @@ return bits & mask; } - int getExponent() const { + int getExponent() const noexcept { if (getUnbiasedExponent() == 0) return int(1) - exponentBias; return int(getUnbiasedExponent()) - exponentBias; } - bool isZero() const { + bool isZero() const noexcept { return getUnbiasedExponent() == 0 && getMantissa() == 0 && getImplicitBit() == 0; } - bool isInf() const { + bool isInf() const noexcept { return getUnbiasedExponent() == maxExponent && getMantissa() == 0 && getImplicitBit() == 1; } - bool isNaN() const { + bool isNaN() const noexcept { if (getUnbiasedExponent() == maxExponent) { return (getImplicitBit() == 0) || getMantissa() != 0; } else if (getUnbiasedExponent() != 0) { @@ -131,29 +133,31 @@ return false; } - bool isInfOrNaN() const { + bool isInfOrNaN() const noexcept { return (getUnbiasedExponent() == maxExponent) || (getUnbiasedExponent() != 0 && getImplicitBit() == 0); } // Methods below this are used by tests. - static FPBits zero() { return FPBits(0.0l); } + static FPBits zero() noexcept { + return FPBits(0.0l); + } - static FPBits negZero() { + static FPBits negZero() noexcept { FPBits bits(0.0l); bits.setSign(1); return bits; } - static FPBits inf() { + static FPBits inf() noexcept { FPBits bits(0.0l); bits.setUnbiasedExponent(maxExponent); bits.setImplicitBit(1); return bits; } - static FPBits negInf() { + static FPBits negInf() noexcept { FPBits bits(0.0l); bits.setUnbiasedExponent(maxExponent); bits.setImplicitBit(1); @@ -161,7 +165,7 @@ return bits; } - static long double buildNaN(UIntType v) { + static long double buildNaN(UIntType v) noexcept { FPBits bits(0.0l); bits.setUnbiasedExponent(maxExponent); bits.setImplicitBit(1); diff --git a/libc/utils/FPUtil/ManipulationFunctions.h b/libc/utils/FPUtil/ManipulationFunctions.h --- a/libc/utils/FPUtil/ManipulationFunctions.h +++ b/libc/utils/FPUtil/ManipulationFunctions.h @@ -24,7 +24,7 @@ template ::Value, int> = 0> -static inline T frexp(T x, int &exp) { +static inline T frexp(T x, int &exp) noexcept { FPBits bits(x); if (bits.isInfOrNaN()) return x; @@ -41,7 +41,7 @@ template ::Value, int> = 0> -static inline T modf(T x, T &iptr) { +static inline T modf(T x, T &iptr) noexcept { FPBits bits(x); if (bits.isZero() || bits.isNaN()) { iptr = x; @@ -63,7 +63,7 @@ template ::Value, int> = 0> -static inline T copysign(T x, T y) { +static inline T copysign(T x, T y) noexcept { FPBits xbits(x); xbits.setSign(FPBits(y).getSign()); return T(xbits); @@ -71,7 +71,7 @@ template ::Value, int> = 0> -static inline int ilogb(T x) { +static inline int ilogb(T x) noexcept { // TODO: Raise appropriate floating point exceptions and set errno to the // an appropriate error value wherever relevant. FPBits bits(x); @@ -100,7 +100,7 @@ template ::Value, int> = 0> -static inline T logb(T x) { +static inline T logb(T x) noexcept { FPBits bits(x); if (bits.isZero()) { // TODO(Floating point exception): Raise div-by-zero exception. @@ -119,7 +119,7 @@ template ::Value, int> = 0> -static inline T ldexp(T x, int exp) { +static inline T ldexp(T x, int exp) noexcept { FPBits bits(x); if (bits.isZero() || bits.isInfOrNaN() || exp == 0) return x; @@ -146,7 +146,7 @@ template ::Value, int> = 0> -static inline T nextafter(T from, T to) { +static inline T nextafter(T from, T to) noexcept { FPBits fromBits(from); if (fromBits.isNaN()) return from; diff --git a/libc/utils/FPUtil/NearestIntegerOperations.h b/libc/utils/FPUtil/NearestIntegerOperations.h --- a/libc/utils/FPUtil/NearestIntegerOperations.h +++ b/libc/utils/FPUtil/NearestIntegerOperations.h @@ -24,7 +24,7 @@ template ::Value, int> = 0> -static inline T trunc(T x) { +static inline T trunc(T x) noexcept { FPBits bits(x); // If x is infinity or NaN, return it. @@ -56,7 +56,7 @@ template ::Value, int> = 0> -static inline T ceil(T x) { +static inline T ceil(T x) noexcept { FPBits bits(x); // If x is infinity NaN or zero, return it. @@ -95,7 +95,7 @@ template ::Value, int> = 0> -static inline T floor(T x) { +static inline T floor(T x) noexcept { FPBits bits(x); if (bits.getSign()) { return -ceil(-x); @@ -106,7 +106,7 @@ template ::Value, int> = 0> -static inline T round(T x) { +static inline T round(T x) noexcept { using UIntType = typename FPBits::UIntType; FPBits bits(x); @@ -158,7 +158,7 @@ template ::Value, int> = 0> -static inline T roundUsingCurrentRoundingMode(T x) { +static inline T roundUsingCurrentRoundingMode(T x) noexcept { using UIntType = typename FPBits::UIntType; FPBits bits(x); @@ -240,7 +240,7 @@ cpp::EnableIfType::Value && cpp::IsIntegral::Value, int> = 0> -static inline I roundedFloatToSignedInteger(F x) { +static inline I roundedFloatToSignedInteger(F x) noexcept { constexpr I IntegerMin = (I(1) << (sizeof(I) * 8 - 1)); constexpr I IntegerMax = -(IntegerMin + 1); FPBits bits(x); @@ -284,7 +284,7 @@ cpp::EnableIfType::Value && cpp::IsIntegral::Value, int> = 0> -static inline I roundToSignedInteger(F x) { +static inline I roundToSignedInteger(F x) noexcept { return internal::roundedFloatToSignedInteger(round(x)); } @@ -292,7 +292,7 @@ cpp::EnableIfType::Value && cpp::IsIntegral::Value, int> = 0> -static inline I roundToSignedIntegerUsingCurrentRoundingMode(F x) { +static inline I roundToSignedIntegerUsingCurrentRoundingMode(F x) noexcept { return internal::roundedFloatToSignedInteger( roundUsingCurrentRoundingMode(x)); } diff --git a/libc/utils/FPUtil/NextAfterLongDoubleX86.h b/libc/utils/FPUtil/NextAfterLongDoubleX86.h --- a/libc/utils/FPUtil/NextAfterLongDoubleX86.h +++ b/libc/utils/FPUtil/NextAfterLongDoubleX86.h @@ -16,7 +16,7 @@ namespace __llvm_libc { namespace fputil { -static inline long double nextafter(long double from, long double to) { +static inline long double nextafter(long double from, long double to) noexcept { using FPBits = FPBits; FPBits fromBits(from); if (fromBits.isNaN()) diff --git a/libc/utils/FPUtil/NormalFloat.h b/libc/utils/FPUtil/NormalFloat.h --- a/libc/utils/FPUtil/NormalFloat.h +++ b/libc/utils/FPUtil/NormalFloat.h @@ -45,7 +45,7 @@ bool sign; NormalFloat(int32_t e, UIntType m, bool s) - : exponent(e), mantissa(m), sign(s) { + : exponent(e), mantissa(m), sign(s) noexcept { if (mantissa >= one) return; @@ -61,7 +61,7 @@ // Compares this normalized number with another normalized number. // Returns -1 is this number is less than |other|, 0 if this number is equal // to |other|, and 1 if this number is greater than |other|. - int cmp(const NormalFloat &other) const { + int cmp(const NormalFloat &other) const noexcept { if (sign != other.sign) return sign ? -1 : 1; @@ -82,7 +82,7 @@ // Returns a new normalized floating point number which is equal in value // to this number multiplied by 2^e. That is: // new = this * 2^e - NormalFloat mul2(int e) const { + NormalFloat mul2(int e) const noexcept { NormalFloat result = *this; result.exponent += e; return result; @@ -138,7 +138,7 @@ } private: - void initFromBits(FPBits bits) { + void initFromBits(FPBits bits) noexcept { sign = bits.getSign(); if (bits.isInfOrNaN() || bits.isZero()) { @@ -160,7 +160,7 @@ } } - unsigned evaluateNormalizationShift(UIntType m) { + unsigned evaluateNormalizationShift(UIntType m) noexcept { unsigned shift = 0; for (; (one & m) == 0 && (shift < MantissaWidth::value); m <<= 1, ++shift) @@ -171,7 +171,7 @@ #ifdef SPECIAL_X86_LONG_DOUBLE template <> -inline void NormalFloat::initFromBits(FPBits bits) { +inline void NormalFloat::initFromBits(FPBits bits) noexcept { sign = bits.getSign(); if (bits.isInfOrNaN() || bits.isZero()) { diff --git a/libc/utils/FPUtil/PolyEval.h b/libc/utils/FPUtil/PolyEval.h --- a/libc/utils/FPUtil/PolyEval.h +++ b/libc/utils/FPUtil/PolyEval.h @@ -24,10 +24,12 @@ namespace __llvm_libc { namespace fputil { -template static inline T polyeval(T x, T a0) { return a0; } +template static inline T polyeval(T x, T a0) noexcept { + return a0; +} template -static inline T polyeval(T x, T a0, Ts... a) { +static inline T polyeval(T x, T a0, Ts... a) noexcept { return fma(x, polyeval(x, a...), a0); } @@ -39,10 +41,12 @@ namespace __llvm_libc { namespace fputil { -template static inline T polyeval(T x, T a0) { return a0; } +template static inline T polyeval(T x, T a0) noexcept { + return a0; +} template -static inline T polyeval(T x, T a0, Ts... a) { +static inline T polyeval(T x, T a0, Ts... a) noexcept { return x * polyeval(x, a...) + a0; } diff --git a/libc/utils/FPUtil/Sqrt.h b/libc/utils/FPUtil/Sqrt.h --- a/libc/utils/FPUtil/Sqrt.h +++ b/libc/utils/FPUtil/Sqrt.h @@ -21,9 +21,10 @@ template static inline void normalize(int &exponent, - typename FPBits::UIntType &mantissa); + typename FPBits::UIntType &mantissa) noexcept; -template <> inline void normalize(int &exponent, uint32_t &mantissa) { +template <> +inline void normalize(int &exponent, uint32_t &mantissa) noexcept { // Use binary search to shift the leading 1 bit. // With MantissaWidth = 23, it will take // ceil(log2(23)) = 5 steps checking the mantissa bits as followed: @@ -45,7 +46,8 @@ } } -template <> inline void normalize(int &exponent, uint64_t &mantissa) { +template <> +inline void normalize(int &exponent, uint64_t &mantissa) noexcept { // Use binary search to shift the leading 1 bit similar to float. // With MantissaWidth = 52, it will take // ceil(log2(52)) = 6 steps checking the mantissa bits. @@ -64,12 +66,13 @@ #ifdef LONG_DOUBLE_IS_DOUBLE template <> -inline void normalize(int &exponent, uint64_t &mantissa) { +inline void normalize(int &exponent, uint64_t &mantissa) noexcept { normalize(exponent, mantissa); } #elif !defined(SPECIAL_X86_LONG_DOUBLE) template <> -inline void normalize(int &exponent, __uint128_t &mantissa) { +inline void normalize(int &exponent, + __uint128_t &mantissa) noexcept { // Use binary search to shift the leading 1 bit similar to float. // With MantissaWidth = 112, it will take // ceil(log2(112)) = 7 steps checking the mantissa bits. @@ -95,7 +98,7 @@ // Shift-and-add algorithm. template ::Value, int> = 0> -static inline T sqrt(T x) { +static inline T sqrt(T x) noexcept { using UIntType = typename FPBits::UIntType; constexpr UIntType One = UIntType(1) << MantissaWidth::value; diff --git a/libc/utils/FPUtil/SqrtLongDoubleX86.h b/libc/utils/FPUtil/SqrtLongDoubleX86.h --- a/libc/utils/FPUtil/SqrtLongDoubleX86.h +++ b/libc/utils/FPUtil/SqrtLongDoubleX86.h @@ -20,7 +20,8 @@ namespace internal { template <> -inline void normalize(int &exponent, __uint128_t &mantissa) { +inline void normalize(int &exponent, + __uint128_t &mantissa) noexcept { // Use binary search to shift the leading 1 bit similar to float. // With MantissaWidth = 63, it will take // ceil(log2(63)) = 6 steps checking the mantissa bits. @@ -42,7 +43,7 @@ // Correctly rounded SQRT with round to nearest, ties to even. // Shift-and-add algorithm. -template <> inline long double sqrt(long double x) { +template <> inline long double sqrt(long double x) noexcept { using UIntType = typename FPBits::UIntType; constexpr UIntType One = UIntType(1) << int(MantissaWidth::value); diff --git a/libc/utils/FPUtil/x86_64/FEnvImpl.h b/libc/utils/FPUtil/x86_64/FEnvImpl.h --- a/libc/utils/FPUtil/x86_64/FEnvImpl.h +++ b/libc/utils/FPUtil/x86_64/FEnvImpl.h @@ -61,7 +61,7 @@ // Exception flags are individual bits in the corresponding registers. // So, we just OR the bit values to get the full set of exceptions. -static inline uint16_t getStatusValueForExcept(int excepts) { +static constexpr uint16_t getStatusValueForExcept(int excepts) { // We will make use of the fact that exception control bits are single // bit flags in the control registers. return (excepts & FE_INVALID ? ExceptionFlags::Invalid : 0) | @@ -74,7 +74,7 @@ (excepts & FE_INEXACT ? ExceptionFlags::Inexact : 0); } -static inline int exceptionStatusToMacro(uint16_t status) { +static constexpr int exceptionStatusToMacro(uint16_t status) { return (status & ExceptionFlags::Invalid ? FE_INVALID : 0) | #ifdef __FE_DENORM (status & ExceptionFlags::Denormal ? __FE_DENORM : 0) | @@ -107,53 +107,54 @@ sizeof(fenv_t) == sizeof(FPState), "Internal floating point state does not match the public fenv_t type."); -static inline uint16_t getX87ControlWord() { +static inline uint16_t getX87ControlWord() noexcept { uint16_t w; __asm__ __volatile__("fnstcw %0" : "=m"(w)::); SANITIZER_MEMORY_INITIALIZED(&w, sizeof(w)); return w; } -static inline void writeX87ControlWord(uint16_t w) { +static inline void writeX87ControlWord(uint16_t w) noexcept { __asm__ __volatile__("fldcw %0" : : "m"(w) :); } -static inline uint16_t getX87StatusWord() { +static inline uint16_t getX87StatusWord() noexcept { uint16_t w; __asm__ __volatile__("fnstsw %0" : "=m"(w)::); SANITIZER_MEMORY_INITIALIZED(&w, sizeof(w)); return w; } -static inline void clearX87Exceptions() { +static inline void clearX87Exceptions() noexcept { __asm__ __volatile__("fnclex" : : :); } -static inline uint32_t getMXCSR() { +static inline uint32_t getMXCSR() noexcept { uint32_t w; __asm__ __volatile__("stmxcsr %0" : "=m"(w)::); SANITIZER_MEMORY_INITIALIZED(&w, sizeof(w)); return w; } -static inline void writeMXCSR(uint32_t w) { +static inline void writeMXCSR(uint32_t w) noexcept { __asm__ __volatile__("ldmxcsr %0" : : "m"(w) :); } -static inline void getX87StateDescriptor(X87StateDescriptor &s) { +static inline void getX87StateDescriptor(X87StateDescriptor &s) noexcept { __asm__ __volatile__("fnstenv %0" : "=m"(s)); SANITIZER_MEMORY_INITIALIZED(&s, sizeof(s)); } -static inline void writeX87StateDescriptor(const X87StateDescriptor &s) { +static inline void +writeX87StateDescriptor(const X87StateDescriptor &s) noexcept { __asm__ __volatile__("fldenv %0" : : "m"(s) :); } -static inline void fwait() { __asm__ __volatile__("fwait"); } +static inline void fwait() noexcept { __asm__ __volatile__("fwait"); } } // namespace internal -static inline int enableExcept(int excepts) { +static inline int enableExcept(int excepts) noexcept { // In the x87 control word and in MXCSR, an exception is blocked // if the corresponding bit is set. That is the reason for all the // bit-flip operations below as we need to turn the bits to zero @@ -180,7 +181,7 @@ return internal::exceptionStatusToMacro(oldExcepts); } -static inline int disableExcept(int excepts) { +static inline int disableExcept(int excepts) noexcept { // In the x87 control word and in MXCSR, an exception is blocked // if the corresponding bit is set. @@ -200,7 +201,7 @@ return internal::exceptionStatusToMacro(oldExcepts); } -static inline int clearExcept(int excepts) { +static inline int clearExcept(int excepts) noexcept { internal::X87StateDescriptor state; internal::getX87StateDescriptor(state); state.StatusWord &= ~internal::getStatusValueForExcept(excepts); @@ -212,7 +213,7 @@ return 0; } -static inline int testExcept(int excepts) { +static inline int testExcept(int excepts) noexcept { uint16_t statusValue = internal::getStatusValueForExcept(excepts); // Check both x87 status word and MXCSR. return internal::exceptionStatusToMacro( @@ -221,7 +222,7 @@ } // Sets the exception flags but does not trigger the exception handler. -static inline int setExcept(int excepts) { +static inline int setExcept(int excepts) noexcept { uint16_t statusValue = internal::getStatusValueForExcept(excepts); internal::X87StateDescriptor state; internal::getX87StateDescriptor(state); @@ -235,7 +236,7 @@ return 0; } -static inline int raiseExcept(int excepts) { +static inline int raiseExcept(int excepts) noexcept { uint16_t statusValue = internal::getStatusValueForExcept(excepts); // We set the status flag for exception one at a time and call the @@ -251,7 +252,7 @@ // ensure that the writes by the exception handler are maintained // when raising the next exception. - auto raiseHelper = [](uint16_t singleExceptFlag) { + auto raiseHelper = [](uint16_t singleExceptFlag) { internal::X87StateDescriptor state; internal::getX87StateDescriptor(state); state.StatusWord |= singleExceptFlag; @@ -283,7 +284,7 @@ return 0; } -static inline int getRound() { +static inline int getRound() noexcept { uint16_t bitValue = (internal::getMXCSR() >> internal::MXCSRRoundingControlBitPosition) & 0x3; switch (bitValue) { @@ -300,7 +301,7 @@ } } -static inline int setRound(int mode) { +static inline int setRound(int mode) noexcept { uint16_t bitValue; switch (mode) { case FE_TONEAREST: @@ -339,14 +340,14 @@ } #if !(defined(_WIN32)) -static inline int getEnv(fenv_t *envp) { +static inline int getEnv(fenv_t *envp) noexcept { internal::FPState *state = reinterpret_cast(envp); internal::getX87StateDescriptor(state->X87Status); state->MXCSR = internal::getMXCSR(); return 0; } -static inline int setEnv(const fenv_t *envp) { +static inline int setEnv(const fenv_t *envp) noexcept { const internal::FPState *state = reinterpret_cast(envp); internal::writeX87StateDescriptor(state->X87Status); diff --git a/libc/utils/FPUtil/x86_64/FMA.h b/libc/utils/FPUtil/x86_64/FMA.h --- a/libc/utils/FPUtil/x86_64/FMA.h +++ b/libc/utils/FPUtil/x86_64/FMA.h @@ -15,8 +15,8 @@ namespace fputil { template -static inline cpp::EnableIfType::Value, T> fma(T x, T y, - T z) { +static inline cpp::EnableIfType::Value, T> +fma(T x, T y, T z) noexcept { float result = x; __asm__ __volatile__("vfmadd213ss %x2, %x1, %x0" : "+x"(result) @@ -25,8 +25,8 @@ } template -static inline cpp::EnableIfType::Value, T> fma(T x, T y, - T z) { +static inline cpp::EnableIfType::Value, T> +fma(T x, T y, T z) noexcept { double result = x; __asm__ __volatile__("vfmadd213sd %x2, %x1, %x0" : "+x"(result) diff --git a/llvm/include/llvm/Support/Compiler.h b/llvm/include/llvm/Support/Compiler.h --- a/llvm/include/llvm/Support/Compiler.h +++ b/llvm/include/llvm/Support/Compiler.h @@ -246,8 +246,10 @@ #define LLVM_ATTRIBUTE_NORETURN __attribute__((noreturn)) #elif defined(_MSC_VER) #define LLVM_ATTRIBUTE_NORETURN __declspec(noreturn) +#elif __cplusplus +#define LLVM_ATTRIBUTE_NORETURN [[noreturn]] #else -#define LLVM_ATTRIBUTE_NORETURN +#define LLVM_ATTRIBUTE_NORETURN _Noreturn #endif #if __has_attribute(returns_nonnull) || LLVM_GNUC_PREREQ(4, 9, 0) diff --git a/llvm/lib/TableGen/Error.cpp b/llvm/lib/TableGen/Error.cpp --- a/llvm/lib/TableGen/Error.cpp +++ b/llvm/lib/TableGen/Error.cpp @@ -11,11 +11,11 @@ // //===----------------------------------------------------------------------===// +#include "llvm/TableGen/Error.h" #include "llvm/ADT/Twine.h" -#include "llvm/Support/raw_ostream.h" #include "llvm/Support/Signals.h" #include "llvm/Support/WithColor.h" -#include "llvm/TableGen/Error.h" +#include "llvm/Support/raw_ostream.h" #include "llvm/TableGen/Record.h" #include @@ -25,7 +25,7 @@ unsigned ErrorsPrinted = 0; static void PrintMessage(ArrayRef Loc, SourceMgr::DiagKind Kind, - const Twine &Msg) { + const Twine &Msg) noexcept { // Count the total number of errors printed. // This is used to exit with an error code if there were any errors. if (Kind == SourceMgr::DK_Error) @@ -42,24 +42,23 @@ // Functions to print notes. -void PrintNote(const Twine &Msg) { - WithColor::note() << Msg << "\n"; -} +void PrintNote(const Twine &Msg) noexcept { WithColor::note() << Msg << "\n"; } -void PrintNote(ArrayRef NoteLoc, const Twine &Msg) { +void PrintNote(ArrayRef NoteLoc, const Twine &Msg) noexcept { PrintMessage(NoteLoc, SourceMgr::DK_Note, Msg); } // Functions to print fatal notes. -void PrintFatalNote(const Twine &Msg) { +LLVM_ATTRIBUTE_NORETURN void PrintFatalNote(const Twine &Msg) noexcept { PrintNote(Msg); // The following call runs the file cleanup handlers. sys::RunInterruptHandlers(); std::exit(1); } -void PrintFatalNote(ArrayRef NoteLoc, const Twine &Msg) { +LLVM_ATTRIBUTE_NORETURN void PrintFatalNote(ArrayRef NoteLoc, + const Twine &Msg) noexcept { PrintNote(NoteLoc, Msg); // The following call runs the file cleanup handlers. sys::RunInterruptHandlers(); @@ -68,7 +67,7 @@ // This method takes a Record and uses the source location // stored in it. -void PrintFatalNote(const Record *Rec, const Twine &Msg) { +LLVM_ATTRIBUTE_NORETURN void PrintFatalNote(const Record *Rec, const Twine &Msg) noexcept { PrintNote(Rec->getLoc(), Msg); // The following call runs the file cleanup handlers. sys::RunInterruptHandlers(); @@ -77,7 +76,8 @@ // This method takes a RecordVal and uses the source location // stored in it. -void PrintFatalNote(const RecordVal *RecVal, const Twine &Msg) { +LLVM_ATTRIBUTE_NORETURN void PrintFatalNote(const RecordVal *RecVal, + const Twine &Msg) noexcept { PrintNote(RecVal->getLoc(), Msg); // The following call runs the file cleanup handlers. sys::RunInterruptHandlers(); @@ -86,50 +86,55 @@ // Functions to print warnings. -void PrintWarning(const Twine &Msg) { WithColor::warning() << Msg << "\n"; } +void PrintWarning(const Twine &Msg) noexcept { + WithColor::warning() << Msg << "\n"; +} -void PrintWarning(ArrayRef WarningLoc, const Twine &Msg) { +void PrintWarning(ArrayRef WarningLoc, const Twine &Msg) noexcept { PrintMessage(WarningLoc, SourceMgr::DK_Warning, Msg); } -void PrintWarning(const char *Loc, const Twine &Msg) { +void PrintWarning(const char *Loc, const Twine &Msg) noexcept { SrcMgr.PrintMessage(SMLoc::getFromPointer(Loc), SourceMgr::DK_Warning, Msg); } // Functions to print errors. -void PrintError(const Twine &Msg) { WithColor::error() << Msg << "\n"; } +void PrintError(const Twine &Msg) noexcept { + WithColor::error() << Msg << "\n"; +} -void PrintError(ArrayRef ErrorLoc, const Twine &Msg) { +void PrintError(ArrayRef ErrorLoc, const Twine &Msg) noexcept { PrintMessage(ErrorLoc, SourceMgr::DK_Error, Msg); } -void PrintError(const char *Loc, const Twine &Msg) { +void PrintError(const char *Loc, const Twine &Msg) noexcept { SrcMgr.PrintMessage(SMLoc::getFromPointer(Loc), SourceMgr::DK_Error, Msg); } // This method takes a Record and uses the source location // stored in it. -void PrintError(const Record *Rec, const Twine &Msg) { +void PrintError(const Record *Rec, const Twine &Msg) noexcept { PrintMessage(Rec->getLoc(), SourceMgr::DK_Error, Msg); } // This method takes a RecordVal and uses the source location // stored in it. -void PrintError(const RecordVal *RecVal, const Twine &Msg) { +void PrintError(const RecordVal *RecVal, const Twine &Msg) noexcept { PrintMessage(RecVal->getLoc(), SourceMgr::DK_Error, Msg); } // Functions to print fatal errors. -void PrintFatalError(const Twine &Msg) { +[[noreturn]] void PrintFatalError(const Twine &Msg) noexcept { PrintError(Msg); // The following call runs the file cleanup handlers. sys::RunInterruptHandlers(); std::exit(1); } -void PrintFatalError(ArrayRef ErrorLoc, const Twine &Msg) { +[[noreturn]] void PrintFatalError(ArrayRef ErrorLoc, + const Twine &Msg) noexcept { PrintError(ErrorLoc, Msg); // The following call runs the file cleanup handlers. sys::RunInterruptHandlers(); @@ -138,7 +143,8 @@ // This method takes a Record and uses the source location // stored in it. -void PrintFatalError(const Record *Rec, const Twine &Msg) { +[[noreturn]] void PrintFatalError(const Record *Rec, + const Twine &Msg) noexcept { PrintError(Rec->getLoc(), Msg); // The following call runs the file cleanup handlers. sys::RunInterruptHandlers(); @@ -147,7 +153,8 @@ // This method takes a RecordVal and uses the source location // stored in it. -void PrintFatalError(const RecordVal *RecVal, const Twine &Msg) { +[[noreturn]] void PrintFatalError(const RecordVal *RecVal, + const Twine &Msg) noexcept { PrintError(RecVal->getLoc(), Msg); // The following call runs the file cleanup handlers. sys::RunInterruptHandlers(); @@ -156,9 +163,9 @@ // Check an assertion: Obtain the condition value and be sure it is true. // If not, print a nonfatal error along with the message. -void CheckAssert(SMLoc Loc, Init *Condition, Init *Message) { +void CheckAssert(SMLoc Loc, Init *Condition, Init *Message) noexcept { auto *CondValue = dyn_cast_or_null( - Condition->convertInitializerTo(IntRecTy::get())); + Condition->convertInitializerTo(IntRecTy::get())); if (!CondValue) PrintError(Loc, "assert condition must of type bit, bits, or int."); else if (!CondValue->getValue()) {