Skip to content

Commit f612ba1

Browse files
committed
Use existing declaration of rust_eh_personality
If crate declares `rust_eh_personality`, re-use existing declaration as otherwise attempts to set function attributes that follow the declaration will fail (unless it happens to have exactly the same type signature as the one predefined in the compiler).
1 parent ae33a97 commit f612ba1

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

compiler/rustc_codegen_llvm/src/context.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -385,11 +385,16 @@ impl MiscMethods<'tcx> for CodegenCx<'ll, 'tcx> {
385385
} else {
386386
"rust_eh_personality"
387387
};
388-
let fty = self.type_variadic_func(&[], self.type_i32());
389-
self.declare_cfn(name, llvm::UnnamedAddr::Global, fty)
388+
if let Some(llfn) = self.get_declared_value(name) {
389+
llfn
390+
} else {
391+
let fty = self.type_variadic_func(&[], self.type_i32());
392+
let llfn = self.declare_cfn(name, llvm::UnnamedAddr::Global, fty);
393+
attributes::apply_target_cpu_attr(self, llfn);
394+
llfn
395+
}
390396
}
391397
};
392-
attributes::apply_target_cpu_attr(self, llfn);
393398
self.eh_personality.set(Some(llfn));
394399
llfn
395400
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Check that rust_eh_personality can have a different type signature than the
2+
// one hardcoded in the compiler. Regression test for #70117. Used to fail with:
3+
//
4+
// Assertion `isa<X>(Val) && "cast<Ty>() argument of incompatible type!"' failed.
5+
//
6+
// build-pass
7+
// compile-flags: --crate-type=lib -Ccodegen-units=1
8+
#![no_std]
9+
#![panic_runtime]
10+
#![feature(panic_runtime)]
11+
#![feature(rustc_attrs)]
12+
13+
pub struct DropMe;
14+
15+
impl Drop for DropMe {
16+
fn drop(&mut self) {}
17+
}
18+
19+
pub fn test(_: DropMe) {
20+
unreachable!();
21+
}
22+
23+
#[rustc_std_internal_symbol]
24+
pub unsafe extern "C" fn rust_eh_personality() {}

0 commit comments

Comments
 (0)