Skip to content

[libc] -Wimplicit-fallthrough, -Wwrite-strings and non-GCC warnings #124036

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Feb 7, 2025

Conversation

vinay-deshmukh
Copy link
Contributor

@vinay-deshmukh vinay-deshmukh commented Jan 23, 2025

  • Enabled -Wimplicit-fallthrough
  • Enabled -Wwrite-strings
  • Enabled non-GCC warnings
  • Fix non-GCC to mean clang
  • Move -Wstrict-prototypes to common section

See: #122835 (comment)

Relates to #119281

Copy link

⚠️ We detected that you are using a GitHub private e-mail address to contribute to the repo.
Please turn off Keep my email addresses private setting in your account.
See LLVM Discourse for more information.

Copy link

github-actions bot commented Jan 23, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

@vinay-deshmukh vinay-deshmukh changed the title [libc] -Wunused-parameter and few NOOPs [libc] -Wwrite-strings and -Wextra -> -Wunused-parameter Jan 23, 2025
@vinay-deshmukh vinay-deshmukh changed the title [libc] -Wwrite-strings and -Wextra -> -Wunused-parameter [libc] -Wimplicit-fallthrough and -Wwrite-strings Jan 23, 2025
@vinay-deshmukh vinay-deshmukh force-pushed the vinay-issue-119281-misc branch from ca5a280 to 1c5c871 Compare January 23, 2025 02:00
@vinay-deshmukh vinay-deshmukh changed the title [libc] -Wimplicit-fallthrough and -Wwrite-strings [libc] -Wimplicit-fallthrough, -Wwrite-strings and non-GCC warnings Jan 23, 2025
@vinay-deshmukh vinay-deshmukh marked this pull request as ready for review January 23, 2025 02:27
@llvmbot llvmbot added the libc label Jan 23, 2025
@llvmbot
Copy link
Member

llvmbot commented Jan 23, 2025

@llvm/pr-subscribers-libc

Author: Vinay Deshmukh (vinay-deshmukh)

Changes
  • Enabled -Wimplicit-fallthrough
  • Enabled -Wwrite-strings
  • Enabled non-GCC warnings

See: #122835 (comment)

Relates to #119281


Full diff: https://github.com/llvm/llvm-project/pull/124036.diff

1 Files Affected:

  • (modified) libc/cmake/modules/LLVMLibCTestRules.cmake (+9-9)
diff --git a/libc/cmake/modules/LLVMLibCTestRules.cmake b/libc/cmake/modules/LLVMLibCTestRules.cmake
index 96fa6c3a707e47..e676130c6b9a81 100644
--- a/libc/cmake/modules/LLVMLibCTestRules.cmake
+++ b/libc/cmake/modules/LLVMLibCTestRules.cmake
@@ -33,8 +33,8 @@ function(_get_common_test_compile_options output_var c_test flags)
     endif()
     # list(APPEND compile_options "-Wconversion")
     # list(APPEND compile_options "-Wno-sign-conversion")
-    # list(APPEND compile_options "-Wimplicit-fallthrough")
-    # list(APPEND compile_options "-Wwrite-strings")
+    list(APPEND compile_options "-Wimplicit-fallthrough")
+    list(APPEND compile_options "-Wwrite-strings")
     list(APPEND compile_options "-Wextra-semi")
     # Silence this warning because _Complex is a part of C99.
     if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
@@ -46,13 +46,13 @@ function(_get_common_test_compile_options output_var c_test flags)
       list(APPEND compile_options "-Wno-gnu-imaginary-constant")
     endif()
     list(APPEND compile_options "-Wno-pedantic")
-    # if(NOT CMAKE_COMPILER_IS_GNUCXX)
-    #   list(APPEND compile_options "-Wnewline-eof")
-    #   list(APPEND compile_options "-Wnonportable-system-include-path")
-    #   list(APPEND compile_options "-Wstrict-prototypes")
-    #   list(APPEND compile_options "-Wthread-safety")
-    #   list(APPEND compile_options "-Wglobal-constructors")
-    # endif()
+    if(NOT CMAKE_COMPILER_IS_GNUCXX)
+      list(APPEND compile_options "-Wnewline-eof")
+      list(APPEND compile_options "-Wnonportable-system-include-path")
+      list(APPEND compile_options "-Wstrict-prototypes")
+      list(APPEND compile_options "-Wthread-safety")
+      # list(APPEND compile_options "-Wglobal-constructors")
+    endif()
   endif()
   set(${output_var} ${compile_options} PARENT_SCOPE)
 endfunction()

@vinay-deshmukh
Copy link
Contributor Author

Add @nickdesaulniers as reviewer

Context: #122835 (comment)

Copy link
Member

@nickdesaulniers nickdesaulniers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the patch!

@nickdesaulniers
Copy link
Member

Sorry, I'm hitting some pre-existing build breakages with newer versions of gcc (#120427). I'd like to wait to get that resolved first, so that I can re-test this PR with both clang and gcc.

@nickdesaulniers
Copy link
Member

Ok, I had to hack around a few issues (linked from this PR) to get our gcc-14 build working. But I'm confident this PR can land (once -Wextra-semi and -Wstrict-prototypes are moved back to clang-only for now).

nickdesaulniers added a commit to nickdesaulniers/llvm-project that referenced this pull request Jan 28, 2025
Fixes the diagnostic observed with gcc-14:

    llvm-project/libc/include/llvm-libc-macros/containerof-macro.h:17:13:
    error: cast from type ‘const char*’ to type ‘void*’ casts away qualifiers
    [-Werror=cast-qual]
     17 |     (type *)(void *)((const char *)__ptr - offsetof(type, member));
        |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

We're trying to turn on more warnings for the tests in llvm#124036, so enable
-Wcast-qual for GCC while we're at it.
@vinay-deshmukh
Copy link
Contributor Author

@nickdesaulniers This PR should be good to go

# Remove -fno-math-errno if it was added.
if(LIBC_ADD_FNO_MATH_ERRNO)
list(REMOVE_ITEM compile_options "-fno-math-errno")
endif()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you intend to remove this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRFC yes, Oh I just realized that's removing -fno-math-error

let me revert that change

Copy link
Member

@nickdesaulniers nickdesaulniers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the patch! Need us to merge this for you?

@vinay-deshmukh
Copy link
Contributor Author

@nickdesaulniers Yes please merge it for me. Thank you!

For the next work item, if I understand correctly, the plan is to uncomment these one by one and hence, patch each warning in it's own PR, right?

# list(APPEND compile_options "-Wall")
# list(APPEND compile_options "-Wextra")
# -DLIBC_WNO_ERROR=ON if you can't build cleanly with -Werror.
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 "-Wimplicit-fallthrough")
# list(APPEND compile_options "-Wwrite-strings")

@nickdesaulniers nickdesaulniers merged commit dee2092 into llvm:main Feb 7, 2025
14 checks passed
@nickdesaulniers
Copy link
Member

For the next work item, if I understand correctly, the plan is to uncomment these one by one and hence, patch each warning in it's own PR, right?

Exactly, thank you!

Icohedron pushed a commit to Icohedron/llvm-project that referenced this pull request Feb 11, 2025
…warnings (llvm#124036)

* Enabled `-Wimplicit-fallthrough`
* Enabled `-Wwrite-strings`
* Enabled non-GCC warnings
* Fix non-GCC to mean `clang`
* Move `-Wstrict-prototypes` to common section

See:
llvm#122835 (comment)

Relates to llvm#119281
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants