Skip to content

[libc] Enable -Wunused and clean up found instances #96949

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

Closed
wants to merge 1 commit into from

Conversation

Rajveer100
Copy link
Member

Resolves #96689

Updates compile_options in the LLVMLibCObjectRules CMake script.

Resolves llvm#96689

Updates `compile_options` in the `LLVMLibCObjectRules` CMake script.
@llvmbot llvmbot added the libc label Jun 27, 2024
@Rajveer100
Copy link
Member Author

@nickdesaulniers
I am not quite sure about the clean up part.

@llvmbot
Copy link
Member

llvmbot commented Jun 27, 2024

@llvm/pr-subscribers-libc

Author: Rajveer Singh Bharadwaj (Rajveer100)

Changes

Resolves #96689

Updates compile_options in the LLVMLibCObjectRules CMake script.


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

1 Files Affected:

  • (modified) libc/cmake/modules/LLVMLibCObjectRules.cmake (+5)
diff --git a/libc/cmake/modules/LLVMLibCObjectRules.cmake b/libc/cmake/modules/LLVMLibCObjectRules.cmake
index 134c5143d6d61..c53548a1294e4 100644
--- a/libc/cmake/modules/LLVMLibCObjectRules.cmake
+++ b/libc/cmake/modules/LLVMLibCObjectRules.cmake
@@ -50,6 +50,8 @@ function(create_object_library fq_target_name)
   _get_common_compile_options(compile_options "${ADD_OBJECT_FLAGS}")
   list(APPEND compile_options ${ADD_OBJECT_COMPILE_OPTIONS})
 
+  list(APPEND compile_options -Wunused)
+
   add_library(
     ${fq_target_name}
     EXCLUDE_FROM_ALL
@@ -251,6 +253,9 @@ function(create_entrypoint_object fq_target_name)
   endif()
 
   _get_common_compile_options(common_compile_options "${ADD_ENTRYPOINT_OBJ_FLAGS}")
+
+  list(APPEND common_compile_options -Wunused)
+
   list(APPEND common_compile_options ${ADD_ENTRYPOINT_OBJ_COMPILE_OPTIONS})
   get_fq_deps_list(fq_deps_list ${ADD_ENTRYPOINT_OBJ_DEPENDS})
   set(full_deps_list ${fq_deps_list} libc.src.__support.common)

@Rajveer100
Copy link
Member Author

@michaelrj-google
Could you review this, looks like Nick is on leave?

@SchrodingerZhu
Copy link
Contributor

any instances found by the warning?

@Rajveer100
Copy link
Member Author

Rajveer100 commented Jun 29, 2024

Well, I might not be checking the right way, I did not see any warnings show up (apart from -undefined) when doing ninja -C build.

How would you do it @SchrodingerZhu ?

@asudarsa
Copy link
Contributor

asudarsa commented Jul 3, 2024

Well, I might not be checking the right way, I did not see any warnings show up (apart from -undefined) when doing ninja -C build.

How would you do it @SchrodingerZhu ?

One possible way might be to reintroduce the unused variables mentioned in the comment here (#96591 (comment)) and rebuild to see if warnings are emitted with your change.

@michaelrj-google michaelrj-google self-requested a review July 8, 2024 22:36
@michaelrj-google
Copy link
Contributor

hi, yes I can review this. It got lost in my inbox so I just now saw it. For cleanup that's just running a build (probably with ninja check-libc) and finding what errors show up and fixing them. I can give more instruction if you would like.

@Rajveer100
Copy link
Member Author

I have been facing this issue actually (via ninja -C build check-libc):

Undefined symbols for architecture arm64:
  "__llvm_libc_19_0_0_git::internal::exit(int)", referenced from:
      __llvm_libc_19_0_0_git::BlockStore<int, 4ul, false>::pop_back() in blockstore_test.cpp.o
      __llvm_libc_19_0_0_git::BlockStore<int, 4ul, false>::get_last_blocks() in blockstore_test.cpp.o
      __llvm_libc_19_0_0_git::BlockStore<int, 4ul, true>::pop_back() in blockstore_test.cpp.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Undefined symbols for architecture arm64:
  "__llvm_libc_19_0_0_git::internal::exit(int)", referenced from:
      __llvm_libc_19_0_0_git::Block<unsigned long long, 8ul>::allocate(__llvm_libc_19_0_0_git::Block<unsigned long long, 8ul>*, unsigned long, unsigned long) in block_test.cpp.o
      __llvm_libc_19_0_0_git::Block<unsigned long long, 8ul>::allocate(__llvm_libc_19_0_0_git::Block<unsigned long long, 8ul>*, unsigned long, unsigned long) in block_test.cpp.o
      __llvm_libc_19_0_0_git::Block<unsigned long long, 8ul>::allocate(__llvm_libc_19_0_0_git::Block<unsigned long long, 8ul>*, unsigned long, unsigned long) in block_test.cpp.o
      __llvm_libc_19_0_0_git::Block<unsigned long long, 8ul>::allocate(__llvm_libc_19_0_0_git::Block<unsigned long long, 8ul>*, unsigned long, unsigned long) in block_test.cpp.o
      __llvm_libc_19_0_0_git::Block<unsigned short, 2ul>::allocate(__llvm_libc_19_0_0_git::Block<unsigned short, 2ul>*, unsigned long, unsigned long) in block_test.cpp.o
      __llvm_libc_19_0_0_git::Block<unsigned short, 2ul>::allocate(__llvm_libc_19_0_0_git::Block<unsigned short, 2ul>*, unsigned long, unsigned long) in block_test.cpp.o
      __llvm_libc_19_0_0_git::Block<unsigned short, 2ul>::allocate(__llvm_libc_19_0_0_git::Block<unsigned short, 2ul>*, unsigned long, unsigned long) in block_test.cpp.o
      __llvm_libc_19_0_0_git::Block<unsigned short, 2ul>::allocate(__llvm_libc_19_0_0_git::Block<unsigned short, 2ul>*, unsigned long, unsigned long) in block_test.cpp.o
      ...
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

@jhuber6
Copy link
Contributor

jhuber6 commented Jul 9, 2024

I have been facing this issue actually (via ninja -C build check-libc):

This is probably related to #97642

@Rajveer100
Copy link
Member Author

Rajveer100 commented Sep 8, 2024

@michaelrj-google
Just noticed this had been lying around for a while. Regardless of adding the compile flag, -Wunused error is enabled, I checked this by adding few unused instances (like int some_var = 0).

It was not triggered for the the specific case:

  FPBits sk_cy(sin_k_cos_y.hi);
  FPBits ck_sy(cos_k_sin_y.hi);

But works for:

  FPBits sk_cy;

Considering this, I think this PR and the linked issue can be closed?

@michaelrj-google
Copy link
Contributor

I think -Wunused is included in -Wall and -Wextra, so closing this PR and issue SGTM.

@Rajveer100
Copy link
Member Author

Great, closing this one.

@Rajveer100 Rajveer100 closed this Sep 9, 2024
@elchukc elchukc mentioned this pull request Sep 27, 2024
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.

libc: enable -Wunused
6 participants