diff --git a/libc/cmake/modules/LLVMLibCObjectRules.cmake b/libc/cmake/modules/LLVMLibCObjectRules.cmake --- a/libc/cmake/modules/LLVMLibCObjectRules.cmake +++ b/libc/cmake/modules/LLVMLibCObjectRules.cmake @@ -18,14 +18,25 @@ endif() set(compile_options ${LIBC_COMPILE_OPTIONS_DEFAULT} ${ARGN}) - if(NOT ${LIBC_TARGET_OS} STREQUAL "windows") - set(compile_options ${compile_options} -fpie -ffreestanding -fno-builtin) - endif() if(LLVM_COMPILER_IS_GCC_COMPATIBLE) + list(APPEND compile_options "-fpie") + list(APPEND compile_options "-ffreestanding") + list(APPEND compile_options "-fno-builtin") list(APPEND compile_options "-fno-exceptions") list(APPEND compile_options "-fno-unwind-tables") list(APPEND compile_options "-fno-asynchronous-unwind-tables") list(APPEND compile_options "-fno-rtti") + list(APPEND compile_options "-Wall") + list(APPEND compile_options "-Wextra") + list(APPEND compile_options "-Wimplicit-fallthrough") + list(APPEND compile_options "-Wwrite-strings") + list(APPEND compile_options "-Wextra-semi") + list(APPEND compile_options "-Wstrict-prototypes") + if(NOT CMAKE_COMPILER_IS_GNUCXX) + list(APPEND compile_options "-Wnewline-eof") + list(APPEND compile_options "-Wnonportable-system-include-path") + list(APPEND compile_options "-Wthread-safety") + endif() if(ADD_FMA_FLAG) list(APPEND compile_options "-mfma") endif() diff --git a/libc/src/__support/CPP/stringstream.h b/libc/src/__support/CPP/stringstream.h --- a/libc/src/__support/CPP/stringstream.h +++ b/libc/src/__support/CPP/stringstream.h @@ -63,7 +63,7 @@ } template , int> = 0> - StringStream &operator<<(T val) { + StringStream &operator<<(T) { // If this specialization gets activated, then the static_assert will // trigger a compile error about missing floating point number support. static_assert(!is_floating_point_v, diff --git a/libc/src/__support/FPUtil/PolyEval.h b/libc/src/__support/FPUtil/PolyEval.h --- a/libc/src/__support/FPUtil/PolyEval.h +++ b/libc/src/__support/FPUtil/PolyEval.h @@ -21,7 +21,7 @@ namespace __llvm_libc { namespace fputil { -template static inline T polyeval(T x, T a0) { return a0; } +template static inline T polyeval(T, T a0) { return a0; } template static inline T polyeval(T x, T a0, Ts... a) { diff --git a/libc/src/__support/str_to_float.h b/libc/src/__support/str_to_float.h --- a/libc/src/__support/str_to_float.h +++ b/libc/src/__support/str_to_float.h @@ -67,9 +67,7 @@ return static_cast(num >> 64); } -template inline void set_implicit_bit(fputil::FPBits &result) { - return; -} +template inline void set_implicit_bit(fputil::FPBits &) { return; } #if defined(SPECIAL_X86_LONG_DOUBLE) template <> diff --git a/libc/src/pthread/pthread_attr_destroy.cpp b/libc/src/pthread/pthread_attr_destroy.cpp --- a/libc/src/pthread/pthread_attr_destroy.cpp +++ b/libc/src/pthread/pthread_attr_destroy.cpp @@ -14,7 +14,7 @@ namespace __llvm_libc { -LLVM_LIBC_FUNCTION(int, pthread_attr_destroy, (pthread_attr_t * attr)) { +LLVM_LIBC_FUNCTION(int, pthread_attr_destroy, (pthread_attr_t *)) { // There is nothing to cleanup. return 0; } diff --git a/libc/src/pthread/pthread_create.cpp b/libc/src/pthread/pthread_create.cpp --- a/libc/src/pthread/pthread_create.cpp +++ b/libc/src/pthread/pthread_create.cpp @@ -20,10 +20,10 @@ "Mismatch between pthread_t and internal Thread."); LLVM_LIBC_FUNCTION(int, pthread_create, - (pthread_t *__restrict th, - const pthread_attr_t *__restrict attr, + (pthread_t *__restrict th, const pthread_attr_t *__restrict, __pthread_start_t func, void *arg)) { auto *thread = reinterpret_cast<__llvm_libc::Thread *>(th); + // TODO: Use the attributes parameter to set up thread properties. int result = thread->run(func, arg, nullptr, 0); if (result != 0 && result != EPERM) return EAGAIN; diff --git a/libc/src/pthread/pthread_mutexattr_destroy.cpp b/libc/src/pthread/pthread_mutexattr_destroy.cpp --- a/libc/src/pthread/pthread_mutexattr_destroy.cpp +++ b/libc/src/pthread/pthread_mutexattr_destroy.cpp @@ -15,8 +15,7 @@ namespace __llvm_libc { -LLVM_LIBC_FUNCTION(int, pthread_mutexattr_destroy, - (pthread_mutexattr_t * attr)) { +LLVM_LIBC_FUNCTION(int, pthread_mutexattr_destroy, (pthread_mutexattr_t *)) { return 0; } diff --git a/libc/src/stdio/fopencookie.cpp b/libc/src/stdio/fopencookie.cpp --- a/libc/src/stdio/fopencookie.cpp +++ b/libc/src/stdio/fopencookie.cpp @@ -56,7 +56,7 @@ return cookie_file->ops.close(cookie_file->cookie); } -int flush_func(File *f) { return 0; } +int flush_func(File *) { return 0; } } // anonymous namespace diff --git a/libc/src/string/memory_utils/elements.h b/libc/src/string/memory_utils/elements.h --- a/libc/src/string/memory_utils/elements.h +++ b/libc/src/string/memory_utils/elements.h @@ -145,7 +145,7 @@ }; template struct Repeated { - static void move(char *dst, const char *src) {} + static void move(char *, const char *) {} }; // Chain the operation of several types. @@ -188,11 +188,11 @@ template <> struct Chained<> { static constexpr size_t SIZE = 0; - static void copy(char *__restrict dst, const char *__restrict src) {} - static void move(char *dst, const char *src) {} - static bool equals(const char *lhs, const char *rhs) { return true; } - static int three_way_compare(const char *lhs, const char *rhs) { return 0; } - static void splat_set(char *dst, const unsigned char value) {} + static void copy(char *__restrict, const char *__restrict) {} + static void move(char *, const char *) {} + static bool equals(const char *, const char *) { return true; } + static int three_way_compare(const char *, const char *) { return 0; } + static void splat_set(char *, const unsigned char) {} }; // Overlap ElementA and ElementB so they span Size bytes. @@ -431,14 +431,14 @@ template <> struct ArgSelector { template - static T1 *__restrict &Select(T1 *__restrict &p1ref, T2 *__restrict &p2ref) { + static T1 *__restrict &Select(T1 *__restrict &p1ref, T2 *__restrict &) { return p1ref; } }; template <> struct ArgSelector { template - static T2 *__restrict &Select(T1 *__restrict &p1ref, T2 *__restrict &p2ref) { + static T2 *__restrict &Select(T1 *__restrict &, T2 *__restrict &p2ref) { return p2ref; } }; diff --git a/libc/src/threads/mtx_destroy.cpp b/libc/src/threads/mtx_destroy.cpp --- a/libc/src/threads/mtx_destroy.cpp +++ b/libc/src/threads/mtx_destroy.cpp @@ -13,6 +13,6 @@ namespace __llvm_libc { -LLVM_LIBC_FUNCTION(void, mtx_destroy, (mtx_t * mutex)) {} +LLVM_LIBC_FUNCTION(void, mtx_destroy, (mtx_t *)) {} } // namespace __llvm_libc diff --git a/libc/test/src/time/asctime_test.cpp b/libc/test/src/time/asctime_test.cpp --- a/libc/test/src/time/asctime_test.cpp +++ b/libc/test/src/time/asctime_test.cpp @@ -28,60 +28,58 @@ // Weekdays are in the range 0 to 6. Test passing invalid value in wday. TEST(LlvmLibcAsctime, InvalidWday) { struct tm tm_data; - char *result; // Test with wday = -1. - result = call_asctime(&tm_data, - 1970, // year - 1, // month - 1, // day - 0, // hr - 0, // min - 0, // sec - -1, // wday - 0); // yday + call_asctime(&tm_data, + 1970, // year + 1, // month + 1, // day + 0, // hr + 0, // min + 0, // sec + -1, // wday + 0); // yday ASSERT_EQ(EINVAL, llvmlibc_errno); // Test with wday = 7. - result = call_asctime(&tm_data, - 1970, // year - 1, // month - 1, // day - 0, // hr - 0, // min - 0, // sec - 7, // wday - 0); // yday + call_asctime(&tm_data, + 1970, // year + 1, // month + 1, // day + 0, // hr + 0, // min + 0, // sec + 7, // wday + 0); // yday ASSERT_EQ(EINVAL, llvmlibc_errno); } // Months are from January to December. Test passing invalid value in month. TEST(LlvmLibcAsctime, InvalidMonth) { struct tm tm_data; - char *result; // Test with month = 0. - result = call_asctime(&tm_data, - 1970, // year - 0, // month - 1, // day - 0, // hr - 0, // min - 0, // sec - 4, // wday - 0); // yday + call_asctime(&tm_data, + 1970, // year + 0, // month + 1, // day + 0, // hr + 0, // min + 0, // sec + 4, // wday + 0); // yday ASSERT_EQ(EINVAL, llvmlibc_errno); // Test with month = 13. - result = call_asctime(&tm_data, - 1970, // year - 13, // month - 1, // day - 0, // hr - 0, // min - 0, // sec - 4, // wday - 0); // yday + call_asctime(&tm_data, + 1970, // year + 13, // month + 1, // day + 0, // hr + 0, // min + 0, // sec + 4, // wday + 0); // yday ASSERT_EQ(EINVAL, llvmlibc_errno); }