Eliminate duplication of building panic langcall in codegen
This commit is contained in:
parent
1f631e8e93
commit
d735aa6810
2 changed files with 16 additions and 24 deletions
|
@ -2,7 +2,6 @@
|
|||
|
||||
use rustc_errors::struct_span_err;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_hir::LangItem;
|
||||
use rustc_middle::mir::interpret::ConstValue;
|
||||
use rustc_middle::ty::{self, layout::TyAndLayout, Ty, TyCtxt};
|
||||
|
@ -10,7 +9,6 @@ use rustc_session::Session;
|
|||
use rustc_span::Span;
|
||||
|
||||
use crate::base;
|
||||
use crate::traits::BuilderMethods;
|
||||
use crate::traits::*;
|
||||
|
||||
pub enum IntPredicate {
|
||||
|
@ -118,14 +116,22 @@ mod temp_stable_hash_impls {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn langcall(tcx: TyCtxt<'_>, span: Option<Span>, msg: &str, li: LangItem) -> DefId {
|
||||
tcx.lang_items().require(li).unwrap_or_else(|s| {
|
||||
pub fn build_langcall<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
|
||||
bx: &Bx,
|
||||
span: Option<Span>,
|
||||
msg: &str,
|
||||
li: LangItem,
|
||||
) -> (Bx::FnAbiOfResult, Bx::Value) {
|
||||
let tcx = bx.tcx();
|
||||
let def_id = tcx.lang_items().require(li).unwrap_or_else(|s| {
|
||||
let msg = format!("{} {}", msg, s);
|
||||
match span {
|
||||
Some(span) => tcx.sess.span_fatal(span, &msg),
|
||||
None => tcx.sess.fatal(&msg),
|
||||
}
|
||||
})
|
||||
});
|
||||
let instance = ty::Instance::mono(tcx, def_id);
|
||||
(bx.fn_abi_of_instance(instance, ty::List::empty()), bx.get_fn_addr(instance))
|
||||
}
|
||||
|
||||
// To avoid UB from LLVM, these two functions mask RHS with an
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue