From b2652ba851833dfc95ecf5675cce280c2bcf2436 Mon Sep 17 00:00:00 2001 From: Jacob Hughes Date: Wed, 16 Mar 2022 22:35:21 -0400 Subject: [PATCH] test for Box LTO issue --- .../ui/lto/auxiliary/lto-box-allocator.rs | 22 +++++++++++++++++++ src/test/ui/lto/lto-box-allocator.rs | 9 ++++++++ 2 files changed, 31 insertions(+) create mode 100644 src/test/ui/lto/auxiliary/lto-box-allocator.rs create mode 100644 src/test/ui/lto/lto-box-allocator.rs diff --git a/src/test/ui/lto/auxiliary/lto-box-allocator.rs b/src/test/ui/lto/auxiliary/lto-box-allocator.rs new file mode 100644 index 0000000000000..d4db2a67ec2a9 --- /dev/null +++ b/src/test/ui/lto/auxiliary/lto-box-allocator.rs @@ -0,0 +1,22 @@ +// no-prefer-dynamic + +#![crate_type = "rlib"] + +#![feature(allocator_api)] +#![feature(bench_black_box)] +use std::alloc::Global; +use std::hint::black_box; + +pub fn f() { + let mut node = Box::new_in(Node { + v: &(), + b: false, + }, &Global); + node.b = true; + black_box(node); +} + +struct Node { + v: &'static (), + b: bool, +} diff --git a/src/test/ui/lto/lto-box-allocator.rs b/src/test/ui/lto/lto-box-allocator.rs new file mode 100644 index 0000000000000..f39f699f1df03 --- /dev/null +++ b/src/test/ui/lto/lto-box-allocator.rs @@ -0,0 +1,9 @@ +// run-pass +// aux-build:lto-box-allocator.rs +// compile-flags: -C lto=thin +// no-prefer-dynamic +extern crate lto_box_allocator; + +fn main() { + lto_box_allocator::f(); +}