Index: libc/src/__support/integer_operations.h =================================================================== --- libc/src/__support/integer_operations.h +++ libc/src/__support/integer_operations.h @@ -14,10 +14,9 @@ namespace __llvm_libc { template -static inline cpp::EnableIfType::Value, T> integerAbs(T n) { - if (n < 0) - return -n; - return n; +static constexpr cpp::EnableIfType::Value, T> +integerAbs(T n) { + return (n < 0) ? -n : n; } } // namespace __llvm_libc Index: libc/src/ctype/ctype_utils.h =================================================================== --- libc/src/ctype/ctype_utils.h +++ 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 Index: libc/src/ctype/isalnum.h =================================================================== --- libc/src/ctype/isalnum.h +++ libc/src/ctype/isalnum.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -int isalnum(int c); +constexpr int isalnum(int c); } // namespace __llvm_libc Index: libc/src/ctype/isalnum.cpp =================================================================== --- libc/src/ctype/isalnum.cpp +++ 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); } +constexpr LLVM_LIBC_FUNCTION(int, isalnum, (int c)) { + return internal::isalnum(c); +} } // namespace __llvm_libc Index: libc/src/ctype/isalpha.h =================================================================== --- libc/src/ctype/isalpha.h +++ libc/src/ctype/isalpha.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -int isalpha(int c); +constexpr int isalpha(int c); } // namespace __llvm_libc Index: libc/src/ctype/isalpha.cpp =================================================================== --- libc/src/ctype/isalpha.cpp +++ 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); } +constexpr LLVM_LIBC_FUNCTION(int, isalpha, (int c)) { + return internal::isalpha(c); +} } // namespace __llvm_libc Index: libc/src/ctype/isascii.h =================================================================== --- libc/src/ctype/isascii.h +++ libc/src/ctype/isascii.h @@ -13,7 +13,7 @@ namespace __llvm_libc { -int isascii(int c); +constexpr int isascii(int c); } // namespace __llvm_libc Index: libc/src/ctype/isascii.cpp =================================================================== --- libc/src/ctype/isascii.cpp +++ libc/src/ctype/isascii.cpp @@ -12,6 +12,8 @@ namespace __llvm_libc { -LLVM_LIBC_FUNCTION(int, isascii, (int c)) { return (c & (~0x7f)) == 0; } +constexpr LLVM_LIBC_FUNCTION(int, isascii, (int c)) { + return (c & (~0x7f)) == 0; +} } // namespace __llvm_libc Index: libc/src/ctype/isblank.h =================================================================== --- libc/src/ctype/isblank.h +++ libc/src/ctype/isblank.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -int isblank(int c); +constexpr int isblank(int c); } // namespace __llvm_libc Index: libc/src/ctype/isblank.cpp =================================================================== --- libc/src/ctype/isblank.cpp +++ libc/src/ctype/isblank.cpp @@ -14,7 +14,7 @@ // TODO: Currently restricted to default locale. // These should be extended using locale information. -LLVM_LIBC_FUNCTION(int, isblank, (int c)) { +constexpr LLVM_LIBC_FUNCTION(int, isblank, (int c)) { const unsigned char ch = static_cast(c); return ch == ' ' || ch == '\t'; } Index: libc/src/ctype/iscntrl.h =================================================================== --- libc/src/ctype/iscntrl.h +++ libc/src/ctype/iscntrl.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -int iscntrl(int c); +constexpr int iscntrl(int c); } // namespace __llvm_libc Index: libc/src/ctype/iscntrl.cpp =================================================================== --- libc/src/ctype/iscntrl.cpp +++ libc/src/ctype/iscntrl.cpp @@ -14,7 +14,7 @@ // TODO: Currently restricted to default locale. // These should be extended using locale information. -LLVM_LIBC_FUNCTION(int, iscntrl, (int c)) { +constexpr LLVM_LIBC_FUNCTION(int, iscntrl, (int c)) { const unsigned char ch = static_cast(c); return ch < 0x20 || ch == 0x7f; } Index: libc/src/ctype/isdigit.h =================================================================== --- libc/src/ctype/isdigit.h +++ libc/src/ctype/isdigit.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -int isdigit(int c); +constexpr int isdigit(int c); } // namespace __llvm_libc Index: libc/src/ctype/isdigit.cpp =================================================================== --- libc/src/ctype/isdigit.cpp +++ 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); } +constexpr LLVM_LIBC_FUNCTION(int, isdigit, (int c)) { + return internal::isdigit(c); +} } // namespace __llvm_libc Index: libc/src/ctype/isgraph.h =================================================================== --- libc/src/ctype/isgraph.h +++ libc/src/ctype/isgraph.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -int isgraph(int c); +constexpr int isgraph(int c); } // namespace __llvm_libc Index: libc/src/ctype/isgraph.cpp =================================================================== --- libc/src/ctype/isgraph.cpp +++ 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); } +constexpr LLVM_LIBC_FUNCTION(int, isgraph, (int c)) { + return internal::isgraph(c); +} } // namespace __llvm_libc Index: libc/src/ctype/islower.h =================================================================== --- libc/src/ctype/islower.h +++ libc/src/ctype/islower.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -int islower(int c); +constexpr int islower(int c); } // namespace __llvm_libc Index: libc/src/ctype/islower.cpp =================================================================== --- libc/src/ctype/islower.cpp +++ libc/src/ctype/islower.cpp @@ -15,6 +15,6 @@ // TODO: Currently restricted to default locale. // These should be extended using locale information. -LLVM_LIBC_FUNCTION(int, islower, (int c)) { return internal::islower(c); } +constexpr LLVM_LIBC_FUNCTION(int, islower, (int c)) { return internal::islower(c); } } // namespace __llvm_libc Index: libc/src/ctype/isprint.h =================================================================== --- libc/src/ctype/isprint.h +++ libc/src/ctype/isprint.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -int isprint(int c); +constexpr int isprint(int c); } // namespace __llvm_libc Index: libc/src/ctype/isprint.cpp =================================================================== --- libc/src/ctype/isprint.cpp +++ libc/src/ctype/isprint.cpp @@ -14,7 +14,7 @@ // TODO: Currently restricted to default locale. // These should be extended using locale information. -LLVM_LIBC_FUNCTION(int, isprint, (int c)) { +constexpr LLVM_LIBC_FUNCTION(int, isprint, (int c)) { const unsigned ch = c; return (ch - ' ') < 95; } Index: libc/src/ctype/ispunct.h =================================================================== --- libc/src/ctype/ispunct.h +++ libc/src/ctype/ispunct.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -int ispunct(int c); +constexpr int ispunct(int c); } // namespace __llvm_libc Index: libc/src/ctype/ispunct.cpp =================================================================== --- libc/src/ctype/ispunct.cpp +++ libc/src/ctype/ispunct.cpp @@ -15,7 +15,7 @@ // TODO: Currently restricted to default locale. // These should be extended using locale information. -LLVM_LIBC_FUNCTION(int, ispunct, (int c)) { +constexpr LLVM_LIBC_FUNCTION(int, ispunct, (int c)) { return !internal::isalnum(c) && internal::isgraph(c); } Index: libc/src/ctype/isspace.h =================================================================== --- libc/src/ctype/isspace.h +++ libc/src/ctype/isspace.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -int isspace(int c); +constexpr int isspace(int c); } // namespace __llvm_libc Index: libc/src/ctype/isspace.cpp =================================================================== --- libc/src/ctype/isspace.cpp +++ libc/src/ctype/isspace.cpp @@ -14,7 +14,7 @@ // TODO: Currently restricted to default locale. // These should be extended using locale information. -LLVM_LIBC_FUNCTION(int, isspace, (int c)) { +constexpr LLVM_LIBC_FUNCTION(int, isspace, (int c)) { const unsigned ch = c; return ch == ' ' || (ch - '\t') < 5; } Index: libc/src/ctype/isupper.h =================================================================== --- libc/src/ctype/isupper.h +++ libc/src/ctype/isupper.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -int isupper(int c); +constexpr int isupper(int c); } // namespace __llvm_libc Index: libc/src/ctype/isupper.cpp =================================================================== --- libc/src/ctype/isupper.cpp +++ libc/src/ctype/isupper.cpp @@ -15,6 +15,6 @@ // TODO: Currently restricted to default locale. // These should be extended using locale information. -LLVM_LIBC_FUNCTION(int, isupper, (int c)) { return internal::isupper(c); } +constexpr LLVM_LIBC_FUNCTION(int, isupper, (int c)) { return internal::isupper(c); } } // namespace __llvm_libc Index: libc/src/ctype/isxdigit.h =================================================================== --- libc/src/ctype/isxdigit.h +++ libc/src/ctype/isxdigit.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -int isxdigit(int c); +constexpr int isxdigit(int c); } // namespace __llvm_libc Index: libc/src/ctype/isxdigit.cpp =================================================================== --- libc/src/ctype/isxdigit.cpp +++ libc/src/ctype/isxdigit.cpp @@ -15,7 +15,7 @@ // TODO: Currently restricted to default locale. // These should be extended using locale information. -LLVM_LIBC_FUNCTION(int, isxdigit, (int c)) { +constexpr LLVM_LIBC_FUNCTION(int, isxdigit, (int c)) { const unsigned ch = c; return internal::isdigit(ch) || (ch | 32) - 'a' < 6; } Index: libc/src/ctype/toascii.h =================================================================== --- libc/src/ctype/toascii.h +++ libc/src/ctype/toascii.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -int toascii(int c); +constexpr int toascii(int c); } // namespace __llvm_libc Index: libc/src/ctype/toascii.cpp =================================================================== --- libc/src/ctype/toascii.cpp +++ libc/src/ctype/toascii.cpp @@ -12,6 +12,6 @@ namespace __llvm_libc { -LLVM_LIBC_FUNCTION(int, toascii, (int c)) { return (c & 0x7f); } +constexpr LLVM_LIBC_FUNCTION(int, toascii, (int c)) { return (c & 0x7f); } } // namespace __llvm_libc Index: libc/src/ctype/tolower.h =================================================================== --- libc/src/ctype/tolower.h +++ libc/src/ctype/tolower.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -int tolower(int c); +constexpr int tolower(int c); } // namespace __llvm_libc Index: libc/src/ctype/tolower.cpp =================================================================== --- libc/src/ctype/tolower.cpp +++ libc/src/ctype/tolower.cpp @@ -15,9 +15,9 @@ // TODO: Currently restricted to default locale. // These should be extended using locale information. -LLVM_LIBC_FUNCTION(int, tolower, (int c)) { +constexpr LLVM_LIBC_FUNCTION(int, tolower, (int c)) { if (internal::isupper(c)) - return c + 'a' - 'A'; + c += 'a' - 'A'; return c; } Index: libc/src/ctype/toupper.h =================================================================== --- libc/src/ctype/toupper.h +++ libc/src/ctype/toupper.h @@ -11,7 +11,7 @@ namespace __llvm_libc { -int toupper(int c); +constexpr int toupper(int c); } // namespace __llvm_libc Index: libc/src/ctype/toupper.cpp =================================================================== --- libc/src/ctype/toupper.cpp +++ libc/src/ctype/toupper.cpp @@ -15,9 +15,9 @@ // TODO: Currently restricted to default locale. // These should be extended using locale information. -LLVM_LIBC_FUNCTION(int, toupper, (int c)) { +constexpr LLVM_LIBC_FUNCTION(int, toupper, (int c)) { if (internal::islower(c)) - return c + 'A' - 'a'; + c -= 'a' - 'A'; return c; } Index: libc/utils/HdrGen/Command.h =================================================================== --- libc/utils/HdrGen/Command.h +++ libc/utils/HdrGen/Command.h @@ -36,7 +36,7 @@ public: ErrorReporter(llvm::SMLoc L, llvm::SourceMgr &SM) : Loc(L), SrcMgr(SM) {} - void printFatalError(llvm::Twine Msg) const { + [[noreturn]] void printFatalError(llvm::Twine Msg) const { SrcMgr.PrintMessage(Loc, llvm::SourceMgr::DK_Error, Msg); std::exit(1); }