From b14799754e10977ebbe184c80c63b08a49ebc70d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jana=20D=C3=B6nszelmann?= Date: Tue, 27 Jan 2026 12:23:57 +0100 Subject: [PATCH] test backtraces --- compiler/rustc_codegen_llvm/src/mono_item.rs | 2 +- .../auxiliary/decl_with_default_panics.rs | 10 ++++++ tests/ui/eii/default/call_default_panics.rs | 35 +++++++++++++++++++ .../default/call_default_panics.run.stderr | 10 ++++++ 4 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 tests/ui/eii/default/auxiliary/decl_with_default_panics.rs create mode 100644 tests/ui/eii/default/call_default_panics.rs create mode 100644 tests/ui/eii/default/call_default_panics.run.stderr diff --git a/compiler/rustc_codegen_llvm/src/mono_item.rs b/compiler/rustc_codegen_llvm/src/mono_item.rs index 8db334935219..f7e1ca73953e 100644 --- a/compiler/rustc_codegen_llvm/src/mono_item.rs +++ b/compiler/rustc_codegen_llvm/src/mono_item.rs @@ -117,7 +117,7 @@ fn predefine_without_aliases( /// This is not a problem: instead of using LLVM aliases, we can just generate /// a new function symbol (with target architecture!) which effectively comes down to: /// - /// ```rust,ignore + /// ```ignore (illustrative example) /// fn alias_name(...args) { /// original_name(...args) /// } diff --git a/tests/ui/eii/default/auxiliary/decl_with_default_panics.rs b/tests/ui/eii/default/auxiliary/decl_with_default_panics.rs new file mode 100644 index 000000000000..14778a40cde4 --- /dev/null +++ b/tests/ui/eii/default/auxiliary/decl_with_default_panics.rs @@ -0,0 +1,10 @@ +//@ no-prefer-dynamic +//@ needs-unwind +//@ exec-env:RUST_BACKTRACE=1 +#![crate_type = "rlib"] +#![feature(extern_item_impls)] + +#[eii(eii1)] +pub fn decl1(x: u64) { + panic!("{}", x); +} diff --git a/tests/ui/eii/default/call_default_panics.rs b/tests/ui/eii/default/call_default_panics.rs new file mode 100644 index 000000000000..f71fddb71ba2 --- /dev/null +++ b/tests/ui/eii/default/call_default_panics.rs @@ -0,0 +1,35 @@ +//@ no-prefer-dynamic +//@ aux-build: decl_with_default_panics.rs +//@ edition: 2021 +//@ run-pass +//@ needs-unwind +//@ exec-env:RUST_BACKTRACE=1 +//@ ignore-backends: gcc +// FIXME: linking on windows (speciifcally mingw) not yet supported, see tracking issue #125418 +//@ ignore-windows +// A small test to make sure that unwinding works properly. +// +// Functions can have target-cpu applied. On apple-darwin this is super important, +// since you can have binaries which mix x86 and aarch64 code that are compatible +// with both architectures. So we can't just reject target_cpu on EIIs since apple +// puts them on by default. The problem: we generate aliases. And aliases cannot +// get target_cpu applied to them. So, instead we should, in the case of functions, +// generate a shim function. For statics aliases should keep working. +// However, to make this work properly, +// on LLVM we generate shim functions instead of function aliases. +// Little extra functions that look like +// ``` +// function alias_symbol(*args) {return (tailcall) aliasee(*args);} +// ``` +// This is a simple test to make sure that we can unwind through these, +// and that this wrapper function effectively doesn't show up in the trace. +#![feature(extern_item_impls)] + +extern crate decl_with_default_panics; + +fn main() { + let result = std::panic::catch_unwind(|| { + decl_with_default_panics::decl1(10); + }); + assert!(result.is_err()); +} diff --git a/tests/ui/eii/default/call_default_panics.run.stderr b/tests/ui/eii/default/call_default_panics.run.stderr new file mode 100644 index 000000000000..3edd72166736 --- /dev/null +++ b/tests/ui/eii/default/call_default_panics.run.stderr @@ -0,0 +1,10 @@ + +thread 'main' ($TID) panicked at $DIR/auxiliary/decl_with_default_panics.rs:14:5: +10 +stack backtrace: + 0: __rustc::rust_begin_unwind + 1: core::panicking::panic_fmt + 2: core::panicking::panic_display:: + 3: decl_with_default_panics::_::decl1 + 4: call_default_panics::main +note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.