From a27f3e3fd1e4d16160f8885b6b06665b5319f56c Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 21 Jul 2025 14:34:12 +0200 Subject: Rename `tests/codegen` into `tests/codegen-llvm` --- tests/codegen-llvm/skip-mono-inside-if-false.rs | 41 +++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 tests/codegen-llvm/skip-mono-inside-if-false.rs (limited to 'tests/codegen-llvm/skip-mono-inside-if-false.rs') diff --git a/tests/codegen-llvm/skip-mono-inside-if-false.rs b/tests/codegen-llvm/skip-mono-inside-if-false.rs new file mode 100644 index 00000000000..8b95de99dd3 --- /dev/null +++ b/tests/codegen-llvm/skip-mono-inside-if-false.rs @@ -0,0 +1,41 @@ +//@ compile-flags: -Cno-prepopulate-passes -Copt-level=0 + +#![crate_type = "lib"] + +#[no_mangle] +pub fn demo_for_i32() { + generic_impl::(); +} + +// Two important things here: +// - We replace the "then" block with `unreachable` to avoid linking problems +// - We neither declare nor define the `big_impl` that said block "calls". + +// CHECK-LABEL: ; skip_mono_inside_if_false::generic_impl +// CHECK: start: +// CHECK-NEXT: br label %[[ELSE_BRANCH:bb[0-9]+]] +// CHECK: [[ELSE_BRANCH]]: +// CHECK-NEXT: call skip_mono_inside_if_false::small_impl +// CHECK: bb{{[0-9]+}}: +// CHECK-NEXT: ret void +// CHECK: bb{{[0-9+]}}: +// CHECK-NEXT: unreachable + +fn generic_impl() { + trait MagicTrait { + const IS_BIG: bool; + } + impl MagicTrait for T { + const IS_BIG: bool = std::mem::size_of::() > 10; + } + if T::IS_BIG { + big_impl::(); + } else { + small_impl::(); + } +} + +#[inline(never)] +fn small_impl() {} +#[inline(never)] +fn big_impl() {} -- cgit 1.4.1-3-g733a5