diff options
| author | SparrowLii <liyuan179@huawei.com> | 2022-04-27 18:58:59 +0800 |
|---|---|---|
| committer | SparrowLii <liyuan179@huawei.com> | 2022-04-27 18:58:59 +0800 |
| commit | d735aa68107bbe4d617903f221088eeef92ee223 (patch) | |
| tree | dc7c9bddae0d59111df3ff64c332ae562dfc897d /compiler/rustc_codegen_ssa/src/common.rs | |
| parent | 1f631e8e93681ddc6e62d6ba6065cac7c449534c (diff) | |
| download | rust-d735aa68107bbe4d617903f221088eeef92ee223.tar.gz rust-d735aa68107bbe4d617903f221088eeef92ee223.zip | |
Eliminate duplication of building panic langcall in codegen
Diffstat (limited to 'compiler/rustc_codegen_ssa/src/common.rs')
| -rw-r--r-- | compiler/rustc_codegen_ssa/src/common.rs | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/compiler/rustc_codegen_ssa/src/common.rs b/compiler/rustc_codegen_ssa/src/common.rs index ae54442e884..94c63b98ff9 100644 --- a/compiler/rustc_codegen_ssa/src/common.rs +++ b/compiler/rustc_codegen_ssa/src/common.rs @@ -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 |
