diff --git a/libc/src/__support/integer_operations.h b/libc/src/__support/integer_operations.h index 733fb7ed9ce91..4c13bb86e2d87 100644 --- a/libc/src/__support/integer_operations.h +++ b/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 diff --git a/libc/src/assert/__assert_fail.cpp b/libc/src/assert/__assert_fail.cpp index 614e130276338..8bb76cd430d2e 100644 --- a/libc/src/assert/__assert_fail.cpp +++ b/libc/src/assert/__assert_fail.cpp @@ -20,7 +20,8 @@ namespace __llvm_libc { // will call fprintf(stderr, ...). static void writeToStderr(const char *s) { 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); } diff --git a/libc/src/ctype/ctype_utils.h b/libc/src/ctype/ctype_utils.h index 6238bd32d9f8c..b8457227aa832 100644 --- a/libc/src/ctype/ctype_utils.h +++ b/libc/src/ctype/ctype_utils.h @@ -18,17 +18,17 @@ namespace internal { // 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 index 3e8da722c674a..aae0112adaf73 100644 --- a/libc/src/ctype/isalnum.cpp +++ b/libc/src/ctype/isalnum.cpp @@ -15,6 +15,8 @@ namespace __llvm_libc { // 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.cpp b/libc/src/ctype/isalpha.cpp index cecf1b516939d..b019377cf5499 100644 --- a/libc/src/ctype/isalpha.cpp +++ b/libc/src/ctype/isalpha.cpp @@ -15,6 +15,8 @@ namespace __llvm_libc { // 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.cpp b/libc/src/ctype/isascii.cpp index c12915ecd6ee3..d7f00dcd0b2e9 100644 --- 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.cpp b/libc/src/ctype/isblank.cpp index 1c3061379b293..4e3d0d6297bbd 100644 --- a/libc/src/ctype/isblank.cpp +++ b/libc/src/ctype/isblank.cpp @@ -15,8 +15,7 @@ namespace __llvm_libc { // 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.cpp b/libc/src/ctype/iscntrl.cpp index b061199c47ec5..d4a9491e1e05f 100644 --- a/libc/src/ctype/iscntrl.cpp +++ b/libc/src/ctype/iscntrl.cpp @@ -15,7 +15,7 @@ namespace __llvm_libc { // 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.cpp b/libc/src/ctype/isdigit.cpp index 8471e4b5569a4..dc746860b7e21 100644 --- a/libc/src/ctype/isdigit.cpp +++ b/libc/src/ctype/isdigit.cpp @@ -14,6 +14,8 @@ namespace __llvm_libc { // 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.cpp b/libc/src/ctype/isgraph.cpp index 2bb6a57da4073..741ae96ef3c48 100644 --- a/libc/src/ctype/isgraph.cpp +++ b/libc/src/ctype/isgraph.cpp @@ -15,6 +15,8 @@ namespace __llvm_libc { // 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.cpp b/libc/src/ctype/islower.cpp index 907a322174969..230b10f3f7381 100644 --- a/libc/src/ctype/islower.cpp +++ b/libc/src/ctype/islower.cpp @@ -15,6 +15,8 @@ namespace __llvm_libc { // 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.cpp b/libc/src/ctype/isprint.cpp index a80500b133c4f..a155b95ca1ef6 100644 --- a/libc/src/ctype/isprint.cpp +++ b/libc/src/ctype/isprint.cpp @@ -15,7 +15,7 @@ namespace __llvm_libc { // 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.cpp b/libc/src/ctype/ispunct.cpp index 064b7b07c6e6a..f74967201e169 100644 --- a/libc/src/ctype/ispunct.cpp +++ b/libc/src/ctype/ispunct.cpp @@ -16,7 +16,8 @@ namespace __llvm_libc { // 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.cpp b/libc/src/ctype/isspace.cpp index 4a269ef29bf2f..85bed92231185 100644 --- a/libc/src/ctype/isspace.cpp +++ b/libc/src/ctype/isspace.cpp @@ -15,7 +15,7 @@ namespace __llvm_libc { // 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.cpp b/libc/src/ctype/isupper.cpp index f1c56fc942f68..e429dc20592ee 100644 --- a/libc/src/ctype/isupper.cpp +++ b/libc/src/ctype/isupper.cpp @@ -15,6 +15,8 @@ namespace __llvm_libc { // 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.cpp b/libc/src/ctype/isxdigit.cpp index 5ee1b1090b778..cf9b912ca76fc 100644 --- a/libc/src/ctype/isxdigit.cpp +++ b/libc/src/ctype/isxdigit.cpp @@ -16,7 +16,7 @@ namespace __llvm_libc { // 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/tolower.cpp b/libc/src/ctype/tolower.cpp index c01f4f0ded81d..ea64d83881076 100644 --- a/libc/src/ctype/tolower.cpp +++ b/libc/src/ctype/tolower.cpp @@ -16,7 +16,7 @@ namespace __llvm_libc { // 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.cpp b/libc/src/ctype/toupper.cpp index 254befc38f30a..fac1959d57b1e 100644 --- a/libc/src/ctype/toupper.cpp +++ b/libc/src/ctype/toupper.cpp @@ -16,7 +16,7 @@ namespace __llvm_libc { // 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/utils/FPUtil/x86_64/FEnvImpl.h b/libc/utils/FPUtil/x86_64/FEnvImpl.h index fae74bb5da9bc..e235d83fb2354 100644 --- a/libc/utils/FPUtil/x86_64/FEnvImpl.h +++ b/libc/utils/FPUtil/x86_64/FEnvImpl.h @@ -61,7 +61,7 @@ static constexpr uint16_t MXCSRExceptionContolBitPoistion = 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 @@ static inline uint16_t getStatusValueForExcept(int excepts) { (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) | @@ -251,7 +251,7 @@ static inline int raiseExcept(int excepts) { // 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; diff --git a/libc/utils/HdrGen/Command.h b/libc/utils/HdrGen/Command.h index edc40298d97d9..895f472c3ad32 100644 --- a/libc/utils/HdrGen/Command.h +++ b/libc/utils/HdrGen/Command.h @@ -36,7 +36,7 @@ class Command { 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); } diff --git a/llvm/include/llvm/Support/Compiler.h b/llvm/include/llvm/Support/Compiler.h index 57052b596edbe..ec90f75719470 100644 --- 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 index 6104573b4b25b..ccec8992db54c 100644 --- 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 @@ -42,9 +42,7 @@ static void PrintMessage(ArrayRef Loc, SourceMgr::DiagKind Kind, // Functions to print notes. -void PrintNote(const Twine &Msg) { - WithColor::note() << Msg << "\n"; -} +void PrintNote(const Twine &Msg) { WithColor::note() << Msg << "\n"; } void PrintNote(ArrayRef NoteLoc, const Twine &Msg) { PrintMessage(NoteLoc, SourceMgr::DK_Note, Msg); @@ -158,7 +156,7 @@ void PrintFatalError(const RecordVal *RecVal, const Twine &Msg) { // If not, print a nonfatal error along with the message. void CheckAssert(SMLoc Loc, Init *Condition, Init *Message) { 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()) {