[libc-commits] [libc] 2e4ef9b - [libc][NFC] Add a few compiler warning flags.

Siva Chandra Reddy via libc-commits libc-commits at lists.llvm.org
Thu Aug 4 16:46:53 PDT 2022


Author: Siva Chandra Reddy
Date: 2022-08-04T23:46:38Z
New Revision: 2e4ef9b6efcaacd5556e8c0ddf659550d3a089a0

URL: https://github.com/llvm/llvm-project/commit/2e4ef9b6efcaacd5556e8c0ddf659550d3a089a0
DIFF: https://github.com/llvm/llvm-project/commit/2e4ef9b6efcaacd5556e8c0ddf659550d3a089a0.diff

LOG: [libc][NFC] Add a few compiler warning flags.

A bunch of cleanup to supress the new warnings is also done.

Reviewed By: abrachet

Differential Revision: https://reviews.llvm.org/D130723

Added: 
    

Modified: 
    libc/cmake/modules/LLVMLibCObjectRules.cmake
    libc/src/__support/CPP/stringstream.h
    libc/src/__support/FPUtil/PolyEval.h
    libc/src/__support/str_to_float.h
    libc/src/pthread/pthread_attr_destroy.cpp
    libc/src/pthread/pthread_create.cpp
    libc/src/pthread/pthread_mutexattr_destroy.cpp
    libc/src/stdio/fopencookie.cpp
    libc/src/string/memory_utils/elements.h
    libc/src/threads/mtx_destroy.cpp
    libc/test/src/time/asctime_test.cpp

Removed: 
    


################################################################################
diff  --git a/libc/cmake/modules/LLVMLibCObjectRules.cmake b/libc/cmake/modules/LLVMLibCObjectRules.cmake
index 9e825144bfda2..e3919ec71f6c6 100644
--- a/libc/cmake/modules/LLVMLibCObjectRules.cmake
+++ b/libc/cmake/modules/LLVMLibCObjectRules.cmake
@@ -18,14 +18,25 @@ function(_get_common_compile_options output_var flags)
   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
index 2fb467061f27a..fbd057226c31b 100644
--- a/libc/src/__support/CPP/stringstream.h
+++ b/libc/src/__support/CPP/stringstream.h
@@ -63,7 +63,7 @@ class StringStream {
   }
 
   template <typename T, enable_if_t<is_floating_point_v<T>, 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<T>,

diff  --git a/libc/src/__support/FPUtil/PolyEval.h b/libc/src/__support/FPUtil/PolyEval.h
index 4a4ab0da0e084..b6faa0f897880 100644
--- a/libc/src/__support/FPUtil/PolyEval.h
+++ b/libc/src/__support/FPUtil/PolyEval.h
@@ -21,7 +21,7 @@
 namespace __llvm_libc {
 namespace fputil {
 
-template <typename T> static inline T polyeval(T x, T a0) { return a0; }
+template <typename T> static inline T polyeval(T, T a0) { return a0; }
 
 template <typename T, typename... Ts>
 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
index 3b043ec1222b3..a385a7f415d15 100644
--- a/libc/src/__support/str_to_float.h
+++ b/libc/src/__support/str_to_float.h
@@ -67,9 +67,7 @@ static inline uint64_t high64(const UInt128 &num) {
   return static_cast<uint64_t>(num >> 64);
 }
 
-template <class T> inline void set_implicit_bit(fputil::FPBits<T> &result) {
-  return;
-}
+template <class T> inline void set_implicit_bit(fputil::FPBits<T> &) { 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
index 592d002483d89..f51b056ad030d 100644
--- 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
index ec1e0e331ae04..706412559aadc 100644
--- a/libc/src/pthread/pthread_create.cpp
+++ b/libc/src/pthread/pthread_create.cpp
@@ -20,10 +20,10 @@ static_assert(sizeof(pthread_t) == sizeof(__llvm_libc::Thread),
               "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
index ed338b4e07600..cedfbe31c2ba5 100644
--- 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
index 64177ebeb8ab3..6facc969a2e5e 100644
--- a/libc/src/stdio/fopencookie.cpp
+++ b/libc/src/stdio/fopencookie.cpp
@@ -56,7 +56,7 @@ int close_func(File *f) {
   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
index 68718cd607170..a5aa30de97cb7 100644
--- a/libc/src/string/memory_utils/elements.h
+++ b/libc/src/string/memory_utils/elements.h
@@ -145,7 +145,7 @@ template <typename Element, size_t ElementCount> struct Repeated {
 };
 
 template <typename Element> struct Repeated<Element, 0> {
-  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 <typename Head, typename... Tail> struct Chained<Head, Tail...> {
 
 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 <Arg arg> struct ArgSelector {};
 
 template <> struct ArgSelector<Arg::_1> {
   template <typename T1, typename T2>
-  static T1 *__restrict &Select(T1 *__restrict &p1ref, T2 *__restrict &p2ref) {
+  static T1 *__restrict &Select(T1 *__restrict &p1ref, T2 *__restrict &) {
     return p1ref;
   }
 };
 
 template <> struct ArgSelector<Arg::_2> {
   template <typename T1, typename T2>
-  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
index 773db20759c31..6285b2c60a2d3 100644
--- 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
index 0b0c159eb53a6..93591de9422b7 100644
--- a/libc/test/src/time/asctime_test.cpp
+++ b/libc/test/src/time/asctime_test.cpp
@@ -28,60 +28,58 @@ TEST(LlvmLibcAsctime, Nullptr) {
 // 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);
 }
 


        


More information about the libc-commits mailing list