Skip to content

[clang] Rename files that MacOS libtool warns about (NFC) #150054

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jthackray
Copy link
Contributor

As mentioned in https://discourse.llvm.org/t/rfc-rename-source-files-in-clang-lib-codegen-targetbuiltins/87462/ it appears that MacOS's libtool warns about source filenames that are identically named, even if they exist in separate directories.

Sadly, there doesn't appear to be an easy way to disable this warning, so rename these files, as these warnings are annoying for MacOS users.

Fixes #133199.

@llvmbot llvmbot added clang Clang issues not falling into any other category backend:AMDGPU backend:RISC-V clang:codegen IR generation bugs: mangling, exceptions, etc. backend:DirectX labels Jul 22, 2025
@llvmbot
Copy link
Member

llvmbot commented Jul 22, 2025

@llvm/pr-subscribers-clang-codegen
@llvm/pr-subscribers-backend-directx
@llvm/pr-subscribers-backend-amdgpu

@llvm/pr-subscribers-clang

Author: Jonathan Thackray (jthackray)

Changes

As mentioned in https://discourse.llvm.org/t/rfc-rename-source-files-in-clang-lib-codegen-targetbuiltins/87462/ it appears that MacOS's libtool warns about source filenames that are identically named, even if they exist in separate directories.

Sadly, there doesn't appear to be an easy way to disable this warning, so rename these files, as these warnings are annoying for MacOS users.

Fixes #133199.


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

12 Files Affected:

  • (modified) clang/lib/CodeGen/CMakeLists.txt (+11-11)
  • (renamed) clang/lib/CodeGen/TargetBuiltins/BuiltinAMDGPU.cpp (+1-1)
  • (renamed) clang/lib/CodeGen/TargetBuiltins/BuiltinARM.cpp (+1-1)
  • (renamed) clang/lib/CodeGen/TargetBuiltins/BuiltinDirectX.cpp (+1-1)
  • (renamed) clang/lib/CodeGen/TargetBuiltins/BuiltinHexagon.cpp (+1-1)
  • (renamed) clang/lib/CodeGen/TargetBuiltins/BuiltinNVPTX.cpp (+1-1)
  • (renamed) clang/lib/CodeGen/TargetBuiltins/BuiltinPPC.cpp (+1-1)
  • (renamed) clang/lib/CodeGen/TargetBuiltins/BuiltinRISCV.cpp (+1-1)
  • (renamed) clang/lib/CodeGen/TargetBuiltins/BuiltinSPIR.cpp (+1-1)
  • (renamed) clang/lib/CodeGen/TargetBuiltins/BuiltinSystemZ.cpp (+1-1)
  • (renamed) clang/lib/CodeGen/TargetBuiltins/BuiltinWebAssembly.cpp (+1-1)
  • (renamed) clang/lib/CodeGen/TargetBuiltins/BuiltinX86.cpp (+1-1)
diff --git a/clang/lib/CodeGen/CMakeLists.txt b/clang/lib/CodeGen/CMakeLists.txt
index 0f2a352886e7f..38bba115117da 100644
--- a/clang/lib/CodeGen/CMakeLists.txt
+++ b/clang/lib/CodeGen/CMakeLists.txt
@@ -117,17 +117,17 @@ add_clang_library(clangCodeGen
   PatternInit.cpp
   SanitizerMetadata.cpp
   SwiftCallingConv.cpp
-  TargetBuiltins/ARM.cpp
-  TargetBuiltins/AMDGPU.cpp
-  TargetBuiltins/DirectX.cpp
-  TargetBuiltins/Hexagon.cpp
-  TargetBuiltins/NVPTX.cpp
-  TargetBuiltins/PPC.cpp
-  TargetBuiltins/RISCV.cpp
-  TargetBuiltins/SPIR.cpp
-  TargetBuiltins/SystemZ.cpp
-  TargetBuiltins/WebAssembly.cpp
-  TargetBuiltins/X86.cpp
+  TargetBuiltins/BuiltinARM.cpp
+  TargetBuiltins/BuiltinAMDGPU.cpp
+  TargetBuiltins/BuiltinDirectX.cpp
+  TargetBuiltins/BuiltinHexagon.cpp
+  TargetBuiltins/BuiltinNVPTX.cpp
+  TargetBuiltins/BuiltinPPC.cpp
+  TargetBuiltins/BuiltinRISCV.cpp
+  TargetBuiltins/BuiltinSPIR.cpp
+  TargetBuiltins/BuiltinSystemZ.cpp
+  TargetBuiltins/BuiltinWebAssembly.cpp
+  TargetBuiltins/BuiltinX86.cpp
   TargetInfo.cpp
   Targets/AArch64.cpp
   Targets/AMDGPU.cpp
diff --git a/clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp b/clang/lib/CodeGen/TargetBuiltins/BuiltinAMDGPU.cpp
similarity index 99%
rename from clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp
rename to clang/lib/CodeGen/TargetBuiltins/BuiltinAMDGPU.cpp
index 7dccf82b1a7a3..677de2ee898a7 100644
--- a/clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp
+++ b/clang/lib/CodeGen/TargetBuiltins/BuiltinAMDGPU.cpp
@@ -1,4 +1,4 @@
-//===------- AMDCPU.cpp - Emit LLVM Code for builtins ---------------------===//
+//===------- BuiltinAMDCPU.cpp - Emit LLVM Code for builtins --------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/clang/lib/CodeGen/TargetBuiltins/ARM.cpp b/clang/lib/CodeGen/TargetBuiltins/BuiltinARM.cpp
similarity index 99%
rename from clang/lib/CodeGen/TargetBuiltins/ARM.cpp
rename to clang/lib/CodeGen/TargetBuiltins/BuiltinARM.cpp
index 7e6a47fd7c103..327a8f5e29b27 100644
--- a/clang/lib/CodeGen/TargetBuiltins/ARM.cpp
+++ b/clang/lib/CodeGen/TargetBuiltins/BuiltinARM.cpp
@@ -1,4 +1,4 @@
-//===---------- ARM.cpp - Emit LLVM Code for builtins ---------------------===//
+//===---------- BuiltinARM.cpp - Emit LLVM Code for builtins --------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/clang/lib/CodeGen/TargetBuiltins/DirectX.cpp b/clang/lib/CodeGen/TargetBuiltins/BuiltinDirectX.cpp
similarity index 95%
rename from clang/lib/CodeGen/TargetBuiltins/DirectX.cpp
rename to clang/lib/CodeGen/TargetBuiltins/BuiltinDirectX.cpp
index 51202331bb779..32ec59f2ffdc5 100644
--- a/clang/lib/CodeGen/TargetBuiltins/DirectX.cpp
+++ b/clang/lib/CodeGen/TargetBuiltins/BuiltinDirectX.cpp
@@ -1,4 +1,4 @@
-//===--------- DirectX.cpp - Emit LLVM Code for builtins ------------------===//
+//===--------- BuiltinDirectX.cpp - Emit LLVM Code for builtins -----------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/clang/lib/CodeGen/TargetBuiltins/Hexagon.cpp b/clang/lib/CodeGen/TargetBuiltins/BuiltinHexagon.cpp
similarity index 99%
rename from clang/lib/CodeGen/TargetBuiltins/Hexagon.cpp
rename to clang/lib/CodeGen/TargetBuiltins/BuiltinHexagon.cpp
index 26fe69536daa2..6204658b51985 100644
--- a/clang/lib/CodeGen/TargetBuiltins/Hexagon.cpp
+++ b/clang/lib/CodeGen/TargetBuiltins/BuiltinHexagon.cpp
@@ -1,4 +1,4 @@
-//===------ Hexagon.cpp - Emit LLVM Code for builtins ---------------------===//
+//===------ BuiltinHexagon.cpp - Emit LLVM Code for builtins --------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/clang/lib/CodeGen/TargetBuiltins/NVPTX.cpp b/clang/lib/CodeGen/TargetBuiltins/BuiltinNVPTX.cpp
similarity index 99%
rename from clang/lib/CodeGen/TargetBuiltins/NVPTX.cpp
rename to clang/lib/CodeGen/TargetBuiltins/BuiltinNVPTX.cpp
index 6da65b681df1e..34f81e2b2a3d0 100644
--- a/clang/lib/CodeGen/TargetBuiltins/NVPTX.cpp
+++ b/clang/lib/CodeGen/TargetBuiltins/BuiltinNVPTX.cpp
@@ -1,4 +1,4 @@
-//===-------- NVPTX.cpp - Emit LLVM Code for builtins ---------------------===//
+//===-------- BuiltinNVPTX.cpp - Emit LLVM Code for builtins --------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/clang/lib/CodeGen/TargetBuiltins/PPC.cpp b/clang/lib/CodeGen/TargetBuiltins/BuiltinPPC.cpp
similarity index 99%
rename from clang/lib/CodeGen/TargetBuiltins/PPC.cpp
rename to clang/lib/CodeGen/TargetBuiltins/BuiltinPPC.cpp
index 270e9fc976f23..c2bef235ad5a1 100644
--- a/clang/lib/CodeGen/TargetBuiltins/PPC.cpp
+++ b/clang/lib/CodeGen/TargetBuiltins/BuiltinPPC.cpp
@@ -1,4 +1,4 @@
-//===---------- PPC.cpp - Emit LLVM Code for builtins ---------------------===//
+//===---------- BuiltinPPC.cpp - Emit LLVM Code for builtins --------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/clang/lib/CodeGen/TargetBuiltins/RISCV.cpp b/clang/lib/CodeGen/TargetBuiltins/BuiltinRISCV.cpp
similarity index 99%
rename from clang/lib/CodeGen/TargetBuiltins/RISCV.cpp
rename to clang/lib/CodeGen/TargetBuiltins/BuiltinRISCV.cpp
index b08a0588c5ac1..a6f49e9b9106e 100644
--- a/clang/lib/CodeGen/TargetBuiltins/RISCV.cpp
+++ b/clang/lib/CodeGen/TargetBuiltins/BuiltinRISCV.cpp
@@ -1,4 +1,4 @@
-//===-------- RISCV.cpp - Emit LLVM Code for builtins ---------------------===//
+//===-------- BuiltinRISCV.cpp - Emit LLVM Code for builtins --------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/clang/lib/CodeGen/TargetBuiltins/SPIR.cpp b/clang/lib/CodeGen/TargetBuiltins/BuiltinSPIR.cpp
similarity index 99%
rename from clang/lib/CodeGen/TargetBuiltins/SPIR.cpp
rename to clang/lib/CodeGen/TargetBuiltins/BuiltinSPIR.cpp
index 243aad8bf7083..7cd0535b5a319 100644
--- a/clang/lib/CodeGen/TargetBuiltins/SPIR.cpp
+++ b/clang/lib/CodeGen/TargetBuiltins/BuiltinSPIR.cpp
@@ -1,4 +1,4 @@
-//===--------- SPIR.cpp - Emit LLVM Code for builtins ---------------------===//
+//===--------- BuiltinSPIR.cpp - Emit LLVM Code for builtins --------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/clang/lib/CodeGen/TargetBuiltins/SystemZ.cpp b/clang/lib/CodeGen/TargetBuiltins/BuiltinSystemZ.cpp
similarity index 99%
rename from clang/lib/CodeGen/TargetBuiltins/SystemZ.cpp
rename to clang/lib/CodeGen/TargetBuiltins/BuiltinSystemZ.cpp
index a7c25b29d1dba..527d763bb6315 100644
--- a/clang/lib/CodeGen/TargetBuiltins/SystemZ.cpp
+++ b/clang/lib/CodeGen/TargetBuiltins/BuiltinSystemZ.cpp
@@ -1,4 +1,4 @@
-//===------ SystemZ.cpp - Emit LLVM Code for builtins ---------------------===//
+//===------ BuiltinSystemZ.cpp - Emit LLVM Code for builtins --------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/clang/lib/CodeGen/TargetBuiltins/WebAssembly.cpp b/clang/lib/CodeGen/TargetBuiltins/BuiltinWebAssembly.cpp
similarity index 99%
rename from clang/lib/CodeGen/TargetBuiltins/WebAssembly.cpp
rename to clang/lib/CodeGen/TargetBuiltins/BuiltinWebAssembly.cpp
index b7fd70e855d40..e5f4f2c6e57c2 100644
--- a/clang/lib/CodeGen/TargetBuiltins/WebAssembly.cpp
+++ b/clang/lib/CodeGen/TargetBuiltins/BuiltinWebAssembly.cpp
@@ -1,4 +1,4 @@
-//===-- WebAssembly.cpp - Emit LLVM Code for builtins ---------------------===//
+//===-- BuiltinWebAssembly.cpp - Emit LLVM Code for builtins --------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/clang/lib/CodeGen/TargetBuiltins/X86.cpp b/clang/lib/CodeGen/TargetBuiltins/BuiltinX86.cpp
similarity index 99%
rename from clang/lib/CodeGen/TargetBuiltins/X86.cpp
rename to clang/lib/CodeGen/TargetBuiltins/BuiltinX86.cpp
index e23d19d2f6b6b..4bcf572bc9025 100644
--- a/clang/lib/CodeGen/TargetBuiltins/X86.cpp
+++ b/clang/lib/CodeGen/TargetBuiltins/BuiltinX86.cpp
@@ -1,4 +1,4 @@
-//===---------- X86.cpp - Emit LLVM Code for builtins ---------------------===//
+//===---------- BuiltinX86.cpp - Emit LLVM Code for builtins --------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.

@jthackray jthackray requested review from yronglin and erichkeane July 22, 2025 16:24
Copy link

⚠️ undef deprecator found issues in your code. ⚠️

You can test this locally with the following command:
git diff -U0 --pickaxe-regex -S '([^a-zA-Z0-9#_-]undef[^a-zA-Z0-9_-]|UndefValue::get)' 'HEAD~1' HEAD clang/lib/CodeGen/TargetBuiltins/BuiltinAMDGPU.cpp clang/lib/CodeGen/TargetBuiltins/BuiltinARM.cpp clang/lib/CodeGen/TargetBuiltins/BuiltinDirectX.cpp clang/lib/CodeGen/TargetBuiltins/BuiltinHexagon.cpp clang/lib/CodeGen/TargetBuiltins/BuiltinNVPTX.cpp clang/lib/CodeGen/TargetBuiltins/BuiltinPPC.cpp clang/lib/CodeGen/TargetBuiltins/BuiltinRISCV.cpp clang/lib/CodeGen/TargetBuiltins/BuiltinSPIR.cpp clang/lib/CodeGen/TargetBuiltins/BuiltinSystemZ.cpp clang/lib/CodeGen/TargetBuiltins/BuiltinWebAssembly.cpp clang/lib/CodeGen/TargetBuiltins/BuiltinX86.cpp

The following files introduce new uses of undef:

  • clang/lib/CodeGen/TargetBuiltins/BuiltinARM.cpp

Undef is now deprecated and should only be used in the rare cases where no replacement is possible. For example, a load of uninitialized memory yields undef. You should use poison values for placeholders instead.

In tests, avoid using undef and having tests that trigger undefined behavior. If you need an operand with some unimportant value, you can add a new argument to the function and use that instead.

For example, this is considered a bad practice:

define void @fn() {
  ...
  br i1 undef, ...
}

Please use the following instead:

define void @fn(i1 %cond) {
  ...
  br i1 %cond, ...
}

Please refer to the Undefined Behavior Manual for more information.

@farzonl
Copy link
Member

farzonl commented Jul 22, 2025

This change will absolutely fix the issue, I was advised on my few attempts that we want to be able to keep the same name and the fix should be in cmake and not a file rename.

For example We have many AMDGPU.cpp

  • clang/lib/Basic/Targets/AMDGPU.cpp
  • clang/lib/CodeGen/Targets/AMDGPU.cpp
  • clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp

And we want to be able to keep reusing the AMDGPU.cpp name but it requires us to not reuse that name in the same cmake file and to have one cmake file per directory.

@jthackray
Copy link
Contributor Author

This change will absolutely fix the issue, I was advised on my few attempts that we want to be able to keep the same name and the fix should be in cmake and not a file rename.

For example We have many AMDGPU.cpp

  • clang/lib/Basic/Targets/AMDGPU.cpp
  • clang/lib/CodeGen/Targets/AMDGPU.cpp
  • clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp

And we want to be able to keep reusing the AMDGPU.cpp name but it requires us to not reuse that name in the same cmake file and to have one cmake file per directory.

Ah, I see you tried a CMake change in #133619 and then reverted it. It appears that MacOS libtool only warns because we're using a common CMakelists.txt file? I will see if I can fix this without the file rename, but without also breaking the build.

As mentioned in https://discourse.llvm.org/t/rfc-rename-source-files-in-clang-lib-codegen-targetbuiltins/87462/
it appears that MacOS's libtool warns about source filenames that
are identically named, even if they exist in separate directories.

Sadly, there doesn't appear to be an easy way to disable this warning,
so rename these files, as these warnings are annoying for MacOS users.

Fixes #133199.
@jthackray jthackray force-pushed the users/jthackray/rename-files branch from e82eaa7 to 6e750e5 Compare July 23, 2025 21:12
@jthackray
Copy link
Contributor Author

jthackray commented Jul 23, 2025

@farzonl I see you've tried to fix this twice before, and twice reverted CMake changes.

Looking through the man page for libtool, it says:

-s  Produce the preferred type of table of contents, which results in faster link editing when linking with the archive.  The order of the table of
    contents is sorted by symbol name.  The library member name of this type of table of contents is ``__.SYMDEF SORTED''.  This type of table of
    contents can only be produced when the library does not have multiple members that define the same symbol.  This is the default.

-a  Produce the original type of table of contents, whose order is based on the order of the members in the archive.  The library member name of
    this type of table of contents is ``__.SYMDEF''.  This type of table of contents must be used when the library has multiple members that define
    the same symbol.

Is it possible that adding -a to llvm's libtool invocation would remove this warning. Currently, it must be defaulting to -s which warns. I don't usually build on a Mac (I build on Graviton4) but I will try building overnight on a Mac to replicate the warning, and see if adding -a causes the warning to go away.

@yronglin
Copy link
Contributor

Should we just use ar/ranlib instead of libtool on Apple platform? I'm not sure how much performance difference there is between ar and libtool.

@farzonl
Copy link
Member

farzonl commented Jul 31, 2025

Should we just use ar/ranlib instead of libtool on Apple platform? I'm not sure how much performance difference there is between ar and libtool.

I'm pretty sure if you use an entirely llvm based toolchain that is what is happening and you won't see this error. The problem I and other users are reporting is when you want to build llvm now with the AppleClang toolchain. That being the case I don't think the right change os to swap out libtool, but instead to fix the cmake files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:AMDGPU backend:DirectX backend:RISC-V clang:codegen IR generation bugs: mangling, exceptions, etc. clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[MacOS 15][AppleClang] libtool duplicate member name warnings
4 participants