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/assert/__assert_fail.cpp =================================================================== --- libc/src/assert/__assert_fail.cpp +++ libc/src/assert/__assert_fail.cpp @@ -20,7 +20,8 @@ // 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); } 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.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); } +LLVM_LIBC_FUNCTION(int, isalnum, (int c)) { + return internal::isalnum(static_cast(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); } +LLVM_LIBC_FUNCTION(int, isalpha, (int c)) { + return internal::isalpha(static_cast(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; } +LLVM_LIBC_FUNCTION(int, isascii, (int c)) { + return static_cast(c) <= 0x7f; +} } // namespace __llvm_libc Index: libc/src/ctype/isblank.cpp =================================================================== --- libc/src/ctype/isblank.cpp +++ libc/src/ctype/isblank.cpp @@ -14,9 +14,6 @@ // 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'; -} +LLVM_LIBC_FUNCTION(int, isblank, (int c)) { return c == ' ' || c == '\t'; } } // namespace __llvm_libc Index: libc/src/ctype/iscntrl.cpp =================================================================== --- libc/src/ctype/iscntrl.cpp +++ 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; } 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); } +LLVM_LIBC_FUNCTION(int, isdigit, (int c)) { + return internal::isdigit(static_cast(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); } +LLVM_LIBC_FUNCTION(int, isgraph, (int c)) { + return internal::isgraph(static_cast(c)); +} } // namespace __llvm_libc Index: libc/src/ctype/islower.cpp =================================================================== --- libc/src/ctype/islower.cpp +++ 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 Index: libc/src/ctype/isprint.cpp =================================================================== --- libc/src/ctype/isprint.cpp +++ 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; } Index: libc/src/ctype/ispunct.cpp =================================================================== --- libc/src/ctype/ispunct.cpp +++ 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 Index: libc/src/ctype/isspace.cpp =================================================================== --- libc/src/ctype/isspace.cpp +++ 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; } Index: libc/src/ctype/isupper.cpp =================================================================== --- libc/src/ctype/isupper.cpp +++ 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 Index: libc/src/ctype/isxdigit.cpp =================================================================== --- libc/src/ctype/isxdigit.cpp +++ 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; } Index: libc/src/ctype/tolower.cpp =================================================================== --- libc/src/ctype/tolower.cpp +++ 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; } Index: libc/src/ctype/toupper.cpp =================================================================== --- libc/src/ctype/toupper.cpp +++ 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; } 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); } Index: llvm/include/llvm/Support/Compiler.h =================================================================== --- llvm/include/llvm/Support/Compiler.h +++ llvm/include/llvm/Support/Compiler.h @@ -27,28 +27,28 @@ #endif #ifndef __has_feature -# define __has_feature(x) 0 +#define __has_feature(x) 0 #endif #ifndef __has_extension -# define __has_extension(x) 0 +#define __has_extension(x) 0 #endif #ifndef __has_attribute -# define __has_attribute(x) 0 +#define __has_attribute(x) 0 #endif #ifndef __has_builtin -# define __has_builtin(x) 0 +#define __has_builtin(x) 0 #endif // Only use __has_cpp_attribute in C++ mode. GCC defines __has_cpp_attribute in // C mode, but the :: in __has_cpp_attribute(scoped::attribute) is invalid. #ifndef LLVM_HAS_CPP_ATTRIBUTE #if defined(__cplusplus) && defined(__has_cpp_attribute) -# define LLVM_HAS_CPP_ATTRIBUTE(x) __has_cpp_attribute(x) +#define LLVM_HAS_CPP_ATTRIBUTE(x) __has_cpp_attribute(x) #else -# define LLVM_HAS_CPP_ATTRIBUTE(x) 0 +#define LLVM_HAS_CPP_ATTRIBUTE(x) 0 #endif #endif @@ -56,16 +56,16 @@ /// Extend the default __GNUC_PREREQ even if glibc's features.h isn't /// available. #ifndef LLVM_GNUC_PREREQ -# if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__) -# define LLVM_GNUC_PREREQ(maj, min, patch) \ - ((__GNUC__ << 20) + (__GNUC_MINOR__ << 10) + __GNUC_PATCHLEVEL__ >= \ - ((maj) << 20) + ((min) << 10) + (patch)) -# elif defined(__GNUC__) && defined(__GNUC_MINOR__) -# define LLVM_GNUC_PREREQ(maj, min, patch) \ - ((__GNUC__ << 20) + (__GNUC_MINOR__ << 10) >= ((maj) << 20) + ((min) << 10)) -# else -# define LLVM_GNUC_PREREQ(maj, min, patch) 0 -# endif +#if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__) +#define LLVM_GNUC_PREREQ(maj, min, patch) \ + ((__GNUC__ << 20) + (__GNUC_MINOR__ << 10) + __GNUC_PATCHLEVEL__ >= \ + ((maj) << 20) + ((min) << 10) + (patch)) +#elif defined(__GNUC__) && defined(__GNUC_MINOR__) +#define LLVM_GNUC_PREREQ(maj, min, patch) \ + ((__GNUC__ << 20) + (__GNUC_MINOR__ << 10) >= ((maj) << 20) + ((min) << 10)) +#else +#define LLVM_GNUC_PREREQ(maj, min, patch) 0 +#endif #endif /// \macro LLVM_MSC_PREREQ @@ -125,8 +125,8 @@ /// they are linked in to. #if (__has_attribute(visibility) || LLVM_GNUC_PREREQ(4, 0, 0)) && \ !defined(__MINGW32__) && !defined(__CYGWIN__) && !defined(_WIN32) -#define LLVM_LIBRARY_VISIBILITY __attribute__ ((visibility("hidden"))) -#define LLVM_EXTERNAL_VISIBILITY __attribute__ ((visibility("default"))) +#define LLVM_LIBRARY_VISIBILITY __attribute__((visibility("hidden"))) +#define LLVM_EXTERNAL_VISIBILITY __attribute__((visibility("default"))) #else #define LLVM_LIBRARY_VISIBILITY #define LLVM_EXTERNAL_VISIBILITY @@ -147,7 +147,8 @@ /// LLVM_NODISCARD - Warn if a type or return value is discarded. // Use the 'nodiscard' attribute in C++17 or newer mode. -#if defined(__cplusplus) && __cplusplus > 201402L && LLVM_HAS_CPP_ATTRIBUTE(nodiscard) +#if defined(__cplusplus) && __cplusplus > 201402L && \ + LLVM_HAS_CPP_ATTRIBUTE(nodiscard) #define LLVM_NODISCARD [[nodiscard]] #elif LLVM_HAS_CPP_ATTRIBUTE(clang::warn_unused_result) #define LLVM_NODISCARD [[clang::warn_unused_result]] @@ -269,7 +270,8 @@ #endif /// LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements. -#if defined(__cplusplus) && __cplusplus > 201402L && LLVM_HAS_CPP_ATTRIBUTE(fallthrough) +#if defined(__cplusplus) && __cplusplus > 201402L && \ + LLVM_HAS_CPP_ATTRIBUTE(fallthrough) #define LLVM_FALLTHROUGH [[fallthrough]] #elif LLVM_HAS_CPP_ATTRIBUTE(gnu::fallthrough) #define LLVM_FALLTHROUGH [[gnu::fallthrough]] @@ -323,51 +325,51 @@ /// to an expression which states that it is undefined behavior for the /// compiler to reach this point. Otherwise is not defined. #if __has_builtin(__builtin_unreachable) || LLVM_GNUC_PREREQ(4, 5, 0) -# define LLVM_BUILTIN_UNREACHABLE __builtin_unreachable() +#define LLVM_BUILTIN_UNREACHABLE __builtin_unreachable() #elif defined(_MSC_VER) -# define LLVM_BUILTIN_UNREACHABLE __assume(false) +#define LLVM_BUILTIN_UNREACHABLE __assume(false) #endif /// LLVM_BUILTIN_TRAP - On compilers which support it, expands to an expression /// which causes the program to exit abnormally. #if __has_builtin(__builtin_trap) || LLVM_GNUC_PREREQ(4, 3, 0) -# define LLVM_BUILTIN_TRAP __builtin_trap() +#define LLVM_BUILTIN_TRAP __builtin_trap() #elif defined(_MSC_VER) // The __debugbreak intrinsic is supported by MSVC, does not require forward // declarations involving platform-specific typedefs (unlike RaiseException), // results in a call to vectored exception handlers, and encodes to a short // instruction that still causes the trapping behavior we want. -# define LLVM_BUILTIN_TRAP __debugbreak() +#define LLVM_BUILTIN_TRAP __debugbreak() #else -# define LLVM_BUILTIN_TRAP *(volatile int*)0x11 = 0 +#define LLVM_BUILTIN_TRAP *(volatile int *)0x11 = 0 #endif /// LLVM_BUILTIN_DEBUGTRAP - On compilers which support it, expands to /// an expression which causes the program to break while running /// under a debugger. #if __has_builtin(__builtin_debugtrap) -# define LLVM_BUILTIN_DEBUGTRAP __builtin_debugtrap() +#define LLVM_BUILTIN_DEBUGTRAP __builtin_debugtrap() #elif defined(_MSC_VER) // The __debugbreak intrinsic is supported by MSVC and breaks while // running under the debugger, and also supports invoking a debugger // when the OS is configured appropriately. -# define LLVM_BUILTIN_DEBUGTRAP __debugbreak() +#define LLVM_BUILTIN_DEBUGTRAP __debugbreak() #else // Just continue execution when built with compilers that have no // support. This is a debugging aid and not intended to force the // program to abort if encountered. -# define LLVM_BUILTIN_DEBUGTRAP +#define LLVM_BUILTIN_DEBUGTRAP #endif /// \macro LLVM_ASSUME_ALIGNED /// Returns a pointer with an assumed alignment. #if __has_builtin(__builtin_assume_aligned) || LLVM_GNUC_PREREQ(4, 7, 0) -# define LLVM_ASSUME_ALIGNED(p, a) __builtin_assume_aligned(p, a) +#define LLVM_ASSUME_ALIGNED(p, a) __builtin_assume_aligned(p, a) #elif defined(LLVM_BUILTIN_UNREACHABLE) -# define LLVM_ASSUME_ALIGNED(p, a) \ - (((uintptr_t(p) % (a)) == 0) ? (p) : (LLVM_BUILTIN_UNREACHABLE, (p))) +#define LLVM_ASSUME_ALIGNED(p, a) \ + (((uintptr_t(p) % (a)) == 0) ? (p) : (LLVM_BUILTIN_UNREACHABLE, (p))) #else -# define LLVM_ASSUME_ALIGNED(p, a) (p) +#define LLVM_ASSUME_ALIGNED(p, a) (p) #endif /// \macro LLVM_PACKED @@ -389,13 +391,13 @@ /// }; /// LLVM_PACKED_END #ifdef _MSC_VER -# define LLVM_PACKED(d) __pragma(pack(push, 1)) d __pragma(pack(pop)) -# define LLVM_PACKED_START __pragma(pack(push, 1)) -# define LLVM_PACKED_END __pragma(pack(pop)) +#define LLVM_PACKED(d) __pragma(pack(push, 1)) d __pragma(pack(pop)) +#define LLVM_PACKED_START __pragma(pack(push, 1)) +#define LLVM_PACKED_END __pragma(pack(pop)) #else -# define LLVM_PACKED(d) d __attribute__((packed)) -# define LLVM_PACKED_START _Pragma("pack(push, 1)") -# define LLVM_PACKED_END _Pragma("pack(pop)") +#define LLVM_PACKED(d) d __attribute__((packed)) +#define LLVM_PACKED_START _Pragma("pack(push, 1)") +#define LLVM_PACKED_END _Pragma("pack(pop)") #endif /// \macro LLVM_PTR_SIZE @@ -403,47 +405,47 @@ /// Generally used in combination with alignas or when doing computation in the /// preprocessor. #ifdef __SIZEOF_POINTER__ -# define LLVM_PTR_SIZE __SIZEOF_POINTER__ +#define LLVM_PTR_SIZE __SIZEOF_POINTER__ #elif defined(_WIN64) -# define LLVM_PTR_SIZE 8 +#define LLVM_PTR_SIZE 8 #elif defined(_WIN32) -# define LLVM_PTR_SIZE 4 +#define LLVM_PTR_SIZE 4 #elif defined(_MSC_VER) -# error "could not determine LLVM_PTR_SIZE as a constant int for MSVC" +#error "could not determine LLVM_PTR_SIZE as a constant int for MSVC" #else -# define LLVM_PTR_SIZE sizeof(void *) +#define LLVM_PTR_SIZE sizeof(void *) #endif /// \macro LLVM_MEMORY_SANITIZER_BUILD /// Whether LLVM itself is built with MemorySanitizer instrumentation. #if __has_feature(memory_sanitizer) -# define LLVM_MEMORY_SANITIZER_BUILD 1 -# include -# define LLVM_NO_SANITIZE_MEMORY_ATTRIBUTE __attribute__((no_sanitize_memory)) +#define LLVM_MEMORY_SANITIZER_BUILD 1 +#include +#define LLVM_NO_SANITIZE_MEMORY_ATTRIBUTE __attribute__((no_sanitize_memory)) #else -# define LLVM_MEMORY_SANITIZER_BUILD 0 -# define __msan_allocated_memory(p, size) -# define __msan_unpoison(p, size) -# define LLVM_NO_SANITIZE_MEMORY_ATTRIBUTE +#define LLVM_MEMORY_SANITIZER_BUILD 0 +#define __msan_allocated_memory(p, size) +#define __msan_unpoison(p, size) +#define LLVM_NO_SANITIZE_MEMORY_ATTRIBUTE #endif /// \macro LLVM_ADDRESS_SANITIZER_BUILD /// Whether LLVM itself is built with AddressSanitizer instrumentation. #if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__) -# define LLVM_ADDRESS_SANITIZER_BUILD 1 -# include +#define LLVM_ADDRESS_SANITIZER_BUILD 1 +#include #else -# define LLVM_ADDRESS_SANITIZER_BUILD 0 -# define __asan_poison_memory_region(p, size) -# define __asan_unpoison_memory_region(p, size) +#define LLVM_ADDRESS_SANITIZER_BUILD 0 +#define __asan_poison_memory_region(p, size) +#define __asan_unpoison_memory_region(p, size) #endif /// \macro LLVM_THREAD_SANITIZER_BUILD /// Whether LLVM itself is built with ThreadSanitizer instrumentation. #if __has_feature(thread_sanitizer) || defined(__SANITIZE_THREAD__) -# define LLVM_THREAD_SANITIZER_BUILD 1 +#define LLVM_THREAD_SANITIZER_BUILD 1 #else -# define LLVM_THREAD_SANITIZER_BUILD 0 +#define LLVM_THREAD_SANITIZER_BUILD 0 #endif #if LLVM_THREAD_SANITIZER_BUILD @@ -464,21 +466,21 @@ // This marker is used to define a happens-before arc. The race detector will // infer an arc from the begin to the end when they share the same pointer // argument. -# define TsanHappensBefore(cv) AnnotateHappensBefore(__FILE__, __LINE__, cv) +#define TsanHappensBefore(cv) AnnotateHappensBefore(__FILE__, __LINE__, cv) // This marker defines the destination of a happens-before arc. -# define TsanHappensAfter(cv) AnnotateHappensAfter(__FILE__, __LINE__, cv) +#define TsanHappensAfter(cv) AnnotateHappensAfter(__FILE__, __LINE__, cv) // Ignore any races on writes between here and the next TsanIgnoreWritesEnd. -# define TsanIgnoreWritesBegin() AnnotateIgnoreWritesBegin(__FILE__, __LINE__) +#define TsanIgnoreWritesBegin() AnnotateIgnoreWritesBegin(__FILE__, __LINE__) // Resume checking for racy writes. -# define TsanIgnoreWritesEnd() AnnotateIgnoreWritesEnd(__FILE__, __LINE__) +#define TsanIgnoreWritesEnd() AnnotateIgnoreWritesEnd(__FILE__, __LINE__) #else -# define TsanHappensBefore(cv) -# define TsanHappensAfter(cv) -# define TsanIgnoreWritesBegin() -# define TsanIgnoreWritesEnd() +#define TsanHappensBefore(cv) +#define TsanHappensAfter(cv) +#define TsanIgnoreWritesBegin() +#define TsanIgnoreWritesEnd() #endif /// \macro LLVM_NO_SANITIZE