Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/test/codegen/track_caller_inlined.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// This test makes sure that calls to std::panic::Location::caller()
// don't result in an actual function call. The caller location is
// known at compile time so the call can always be optimized away.

// compile-flags: -Copt-level=2

#![crate_type = "lib"]
#![feature(bench_black_box)]

// The first check makes sure that the caller location is used at all,
// i.e. that std::hint::black_box() works.
// CHECK: %0 = alloca %"core::panic::location::Location"*

// This check makes sure that no call to `std::panic::Location::caller()`
// is emitted. The sequence of characters is valid for both v0 and legacy
// mangling.
// CHECK-NOT: call {{.*}}8Location6caller

// CHECK: call void asm sideeffect {{.*}}(%"core::panic::location::Location"** nonnull %0)

#[track_caller]
fn foo() {
std::hint::black_box(std::panic::Location::caller());
}

pub fn bar() {
foo();
}