diff options
| author | Mark Rousskov <mark.simulacrum@gmail.com> | 2025-06-14 10:22:49 -0400 |
|---|---|---|
| committer | Mark Rousskov <mark.simulacrum@gmail.com> | 2025-06-21 18:59:36 -0400 |
| commit | 1f405735078ac34be300fd2bd7c532aaa0bb6fc5 (patch) | |
| tree | d2dfd248ba63e00af91cb952f5e32c0dfb4bd30a /tests | |
| parent | d4e1159b8c97478778b09a4cc1c7adce5653b8bf (diff) | |
| download | rust-1f405735078ac34be300fd2bd7c532aaa0bb6fc5.tar.gz rust-1f405735078ac34be300fd2bd7c532aaa0bb6fc5.zip | |
Skip collecting no-op DropGlue in vtables
Since 122662 this no longer gets used in vtables, so we're safe to fully drop generating these empty functions. Those are eventually cleaned up by LLVM, but it's wasteful to produce them in the first place. This also adds a missing test for fn-ptr casts, which do still need to generate no-op drop glue. It's possible a future optimization could point all of those at the same drop glue (e.g., for *mut ()) rather than for each separate type, but that would require extra work for CFI and isn't particularly easy to do anyway.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/codegen-units/item-collection/drop-glue-noop.rs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/codegen-units/item-collection/drop-glue-noop.rs b/tests/codegen-units/item-collection/drop-glue-noop.rs new file mode 100644 index 00000000000..604ba883bb2 --- /dev/null +++ b/tests/codegen-units/item-collection/drop-glue-noop.rs @@ -0,0 +1,23 @@ +//@ compile-flags:-Clink-dead-code -Zmir-opt-level=0 + +#![deny(dead_code)] +#![crate_type = "lib"] + +//~ MONO_ITEM fn start +#[no_mangle] +pub fn start(_: isize, _: *const *const u8) -> isize { + // No item produced for this, it's a no-op drop and so is removed. + unsafe { + std::ptr::drop_in_place::<u32>(&mut 0); + } + + // No choice but to codegen for indirect drop as a function pointer, since we have to produce a + // function with the right signature. In vtables we can avoid that (tested in + // instantiation-through-vtable.rs) because we special case null pointer for drop glue since + // #122662. + // + //~ MONO_ITEM fn std::ptr::drop_in_place::<u64> - shim(None) @@ drop_glue_noop-cgu.0[External] + std::ptr::drop_in_place::<u64> as unsafe fn(*mut u64); + + 0 +} |
