[libc-commits] [libc] [libc] Add `-Wsign-conversion` & un-reverts `-Wconversion` (PR #129811)

via libc-commits libc-commits at lists.llvm.org
Fri Mar 7 21:50:28 PST 2025


================
@@ -36,8 +36,8 @@ function(_get_common_test_compile_options output_var c_test flags)
     if(NOT LIBC_WNO_ERROR)
       # list(APPEND compile_options "-Werror")
     endif()
-    # list(APPEND compile_options "-Wconversion")
-    # list(APPEND compile_options "-Wno-sign-conversion")
+    list(APPEND compile_options "-Wconversion")
+    list(APPEND compile_options "-Wsign-conversion")
----------------
lntue wrote:

I tried this PR and there are still many warnings from `-Wsign-conversion`:
```
$ ninja check-libc &> test.txt
$ grep -c "Wsign-conversion" test.txt
12651
```
Some example:
```
In file included from /usr/local/google/home/lntue/experiment/llvm-project/libc/src/__support/FPUtil/FEnvImpl.h:31:
/usr/local/google/home/lntue/experiment/llvm-project/libc/src/__support/FPUtil/x86_64/FEnvImpl.h:169:12: warning: implicit conversion changes signedness: 'int' to 'uint32_t' (aka 'unsigned int') [-Wsign-conversion]
  mxcsr &= ~(bit_mask << internal::MXCSR_EXCEPTION_CONTOL_BIT_POISTION);
        ~~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/google/home/lntue/experiment/llvm-project/libc/src/__support/FPUtil/x86_64/FEnvImpl.h:193:22: warning: implicit conversion changes signedness: 'int' to 'uint32_t' (aka 'unsigned int') [-Wsign-conversion]
  mxcsr |= (bit_mask << internal::MXCSR_EXCEPTION_CONTOL_BIT_POISTION);
        ~~  ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/google/home/lntue/experiment/llvm-project/libc/src/__support/FPUtil/x86_64/FEnvImpl.h:341:26: warning: implicit conversion changes signedness: 'int' to 'uint32_t' (aka 'unsigned int') [-Wsign-conversion]
                         << internal::MXCSR_ROUNDING_CONTROL_BIT_POSITION;
                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/google/home/lntue/experiment/llvm-project/libc/src/__support/FPUtil/x86_64/FEnvImpl.h:344:20: warning: implicit conversion changes signedness: 'int' to 'uint32_t' (aka 'unsigned int') [-Wsign-conversion]
                   ~(0x3 << internal::MXCSR_ROUNDING_CONTROL_BIT_POSITION)) |
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/google/home/lntue/experiment/llvm-project/libc/src/__support/FPUtil/x86_64/FEnvImpl.h:610:14: warning: implicit conversion changes signedness: 'int' to 'uint32_t' (aka 'unsigned int') [-Wsign-conversion]
    mxcsr &= ~uint16_t(0x3F);        // Clear exception flags.
          ~~ ^~~~~~~~~~~~~~~
/usr/local/google/home/lntue/experiment/llvm-project/libc/src/__support/FPUtil/x86_64/FEnvImpl.h:611:14: warning: implicit conversion changes signedness: 'int' to 'uint32_t' (aka 'unsigned int') [-Wsign-conversion]
    mxcsr &= ~(uint16_t(0x1) << 6);  // Reset denormals-are-zero
          ~~ ^~~~~~~~~~~~~~~~~~~~~
/usr/local/google/home/lntue/experiment/llvm-project/libc/src/__support/FPUtil/x86_64/FEnvImpl.h:613:14: warning: implicit conversion changes signedness: 'int' to 'uint32_t' (aka 'unsigned int') [-Wsign-conversion]
    mxcsr &= ~(uint16_t(0x3) << 13); // Round to nearest.
          ~~ ^~~~~~~~~~~~~~~~~~~~~~
/usr/local/google/home/lntue/experiment/llvm-project/libc/src/__support/FPUtil/x86_64/FEnvImpl.h:614:14: warning: implicit conversion changes signedness: 'int' to 'uint32_t' (aka 'unsigned int') [-Wsign-conversion]
    mxcsr &= ~(uint16_t(0x1) << 15); // Reset flush-to-zero
          ~~ ^~~~~~~~~~~~~~~~~~~~~~
```
Probably you should change to `-Wno-sign-conversion` in this PR, add a TODO comment to clean it up, and then fix the remaining `-Wsign-conversion` in a followup PR.

https://github.com/llvm/llvm-project/pull/129811


More information about the libc-commits mailing list