Repository navigation
release/23.x: [clang][win] Fix __global_delete breaking __attribute__((used)) (#217753) - #218040
Merged
Merged
Conversation
Member
Author
|
@efriedma-quic What do you think about merging this PR to the release branch? |
|
@llvm/pr-subscribers-clang @llvm/pr-subscribers-clang-codegen Author: llvmbot ChangesBackport 061865f Requested by: @dpaoliello 2 Files Affected:
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index de060e31b8800..313a364e80aff 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -9026,7 +9026,7 @@ CodeGenModule::getOrCreateMSVCGlobalDeleteWrapper(const FunctionDecl *GlobOD) {
// uses ::delete that alias is replaced by a real forwarding body, leaving
// the empty otherwise unreferenced, so explicitly mark it used to ensure
// it is always emitted (matching MSVC).
- appendToUsed(M, {EmptyFn});
+ addUsedGlobal(EmptyFn);
}
// The wrapper defaults to a weak alias to the trapping __empty_global_delete
diff --git a/clang/test/CodeGenCXX/msvc-global-delete-llvm-used.cpp b/clang/test/CodeGenCXX/msvc-global-delete-llvm-used.cpp
new file mode 100644
index 0000000000000..07811b0f8eecc
--- /dev/null
+++ b/clang/test/CodeGenCXX/msvc-global-delete-llvm-used.cpp
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -emit-llvm -fms-extensions %s -triple=x86_64-pc-windows-msvc -o - \
+// RUN: | FileCheck %s --implicit-check-not="@llvm.used.1"
+
+// The __empty_global_delete fallback is marked used so it is always emitted.
+// It must join the single llvm.used that CodeGenModule emits at end-of-TU: if
+// it creates its own llvm.used first, the one holding __attribute__((used))
+// globals gets renamed to llvm.used.1, which LLVM ignores.
+
+struct S { virtual ~S(); };
+S::~S() {}
+void del(S *s) { ::delete s; }
+
+__attribute__((used)) static void keep_me() {}
+
+// CHECK: @llvm.used = appending global
+// CHECK-SAME: @"?__empty_global_delete@@YAXPEAX_K@Z"
+// CHECK-SAME: @"?keep_me@@YAXXZ"
|
🐧 Linux x64 Test Results
Failed Tests(click on a test name to see its output) libclibc.src/sys/socket/linux/libc.test.src.sys.socket.linux.sockatmark_test.__build__If these failures are unrelated to your changes (for example tests are broken or flaky at HEAD), please open an issue at https://github.com/llvm/llvm-project/issues and add the |
…#217753) The `__empty_global_delete` fallback introduced in llvm#209585 was marked used via `llvm::appendToUsed()`, which creates a global named "llvm.used" during codegen. `CodeGenModule::emitLLVMUsed()` later unconditionally creates its own global of that same name at end-of-TU, so the name collision renamed the latter to "llvm.used.1" -- a name LLVM ignores. The result was that every `__attribute__((used))` global in the TU silently lost its used semantics whenever a `__global_delete` wrapper was emitted, letting those symbols be dropped. Mark the fallback used via `CodeGenModule::addUsedGlobal()` instead, so it joins the single llvm.used that `emitLLVMUsed()` emits. `emitLLVMUsed()` runs well after `emitGlobalDeleteForwardingBodies()` in `Release()`, so the fallback is still recorded in time. Fixes a regression reported on llvm#209585. (cherry picked from commit 061865f)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backport 061865f
Requested by: @dpaoliello