@@ -22,6 +22,7 @@ use rustc_middle::ty::layout::{
2222use rustc_middle:: ty:: { self , Instance , Ty , TyCtxt } ;
2323use rustc_session:: config:: OptLevel ;
2424use rustc_span:: Span ;
25+ use rustc_span:: def_id:: LOCAL_CRATE ;
2526use rustc_target:: callconv:: FnAbi ;
2627use rustc_target:: spec:: { HasTargetSpec , Target } ;
2728use tracing:: { debug, trace} ;
@@ -136,7 +137,14 @@ macro_rules! imath_builder_methods {
136137 ( $( $self_: ident. $name: ident( $( $arg: ident) ,* ) => $llvm_capi: ident => $op: block) +) => {
137138 $( fn $name( & mut $self_, $( $arg: & ' ll Value ) ,* ) -> & ' ll Value {
138139 // Dispatch to i128 emulation when any operand is 128 bits wide.
139- if $( $self_. is_i128( $arg) ) ||*
140+ // When compiling compiler_builtins itself we must avoid emulation that recursively calls
141+ // the same builtins, so fall back to LLVM's native operation.
142+ if $self_. cx. tcx. is_compiler_builtins( LOCAL_CRATE ) {
143+ unsafe {
144+ trace!( "binary expr (builtin crate): {:?} with args {:?}" , stringify!( $name) , [ $( $arg) ,* ] ) ;
145+ llvm:: $llvm_capi( $self_. llbuilder, $( $arg, ) * UNNAMED )
146+ }
147+ } else if $( $self_. is_i128( $arg) ) ||*
140148 $op
141149 else {
142150 unsafe {
0 commit comments