@@ -368,88 +368,3 @@ pub fn struct_in_context(
368368fn hi_lo_to_u128 ( lo : u64 , hi : u64 ) -> u128 {
369369 ( ( hi as u128 ) << 64 ) | ( lo as u128 )
370370}
371-
372- pub fn langcall ( tcx : TyCtxt ,
373- span : Option < Span > ,
374- msg : & str ,
375- li : LangItem )
376- -> DefId {
377- tcx. lang_items ( ) . require ( li) . unwrap_or_else ( |s| {
378- let msg = format ! ( "{} {}" , msg, s) ;
379- match span {
380- Some ( span) => tcx. sess . span_fatal ( span, & msg[ ..] ) ,
381- None => tcx. sess . fatal ( & msg[ ..] ) ,
382- }
383- } )
384- }
385-
386- // To avoid UB from LLVM, these two functions mask RHS with an
387- // appropriate mask unconditionally (i.e. the fallback behavior for
388- // all shifts). For 32- and 64-bit types, this matches the semantics
389- // of Java. (See related discussion on #1877 and #10183.)
390-
391- pub fn build_unchecked_lshift < ' a , ' ll : ' a , ' tcx : ' ll , Bx : BuilderMethods < ' a , ' ll , ' tcx > > (
392- bx : & Bx ,
393- lhs : <Bx :: CodegenCx as Backend < ' ll > >:: Value ,
394- rhs : <Bx :: CodegenCx as Backend < ' ll > >:: Value
395- ) -> <Bx :: CodegenCx as Backend < ' ll > >:: Value {
396- let rhs = base:: cast_shift_expr_rhs ( bx, hir:: BinOpKind :: Shl , lhs, rhs) ;
397- // #1877, #10183: Ensure that input is always valid
398- let rhs = shift_mask_rhs ( bx, rhs) ;
399- bx. shl ( lhs, rhs)
400- }
401-
402- pub fn build_unchecked_rshift < ' a , ' ll : ' a , ' tcx : ' ll , Bx : BuilderMethods < ' a , ' ll , ' tcx > > (
403- bx : & Bx ,
404- lhs_t : Ty < ' tcx > ,
405- lhs : <Bx :: CodegenCx as Backend < ' ll > >:: Value ,
406- rhs : <Bx :: CodegenCx as Backend < ' ll > >:: Value
407- ) -> <Bx :: CodegenCx as Backend < ' ll > >:: Value {
408- let rhs = base:: cast_shift_expr_rhs ( bx, hir:: BinOpKind :: Shr , lhs, rhs) ;
409- // #1877, #10183: Ensure that input is always valid
410- let rhs = shift_mask_rhs ( bx, rhs) ;
411- let is_signed = lhs_t. is_signed ( ) ;
412- if is_signed {
413- bx. ashr ( lhs, rhs)
414- } else {
415- bx. lshr ( lhs, rhs)
416- }
417- }
418-
419- fn shift_mask_rhs < ' a , ' ll : ' a , ' tcx : ' ll , Bx : BuilderMethods < ' a , ' ll , ' tcx > > (
420- bx : & Bx ,
421- rhs : <Bx :: CodegenCx as Backend < ' ll > >:: Value
422- ) -> <Bx :: CodegenCx as Backend < ' ll > >:: Value {
423- let rhs_llty = bx. cx ( ) . val_ty ( rhs) ;
424- bx. and ( rhs, shift_mask_val ( bx, rhs_llty, rhs_llty, false ) )
425- }
426-
427- pub fn shift_mask_val < ' a , ' ll : ' a , ' tcx : ' ll , Bx : BuilderMethods < ' a , ' ll , ' tcx > > (
428- bx : & Bx ,
429- llty : <Bx :: CodegenCx as Backend < ' ll > >:: Type ,
430- mask_llty : <Bx :: CodegenCx as Backend < ' ll > >:: Type ,
431- invert : bool
432- ) -> <Bx :: CodegenCx as Backend < ' ll > >:: Value {
433- let kind = bx. cx ( ) . type_kind ( llty) ;
434- match kind {
435- TypeKind :: Integer => {
436- // i8/u8 can shift by at most 7, i16/u16 by at most 15, etc.
437- let val = bx. cx ( ) . int_width ( llty) - 1 ;
438- if invert {
439- bx. cx ( ) . const_int ( mask_llty, !val as i64 )
440- } else {
441- bx. cx ( ) . const_uint ( mask_llty, val)
442- }
443- } ,
444- TypeKind :: Vector => {
445- let mask = shift_mask_val (
446- bx,
447- bx. cx ( ) . element_type ( llty) ,
448- bx. cx ( ) . element_type ( mask_llty) ,
449- invert
450- ) ;
451- bx. vector_splat ( bx. cx ( ) . vector_length ( mask_llty) , mask)
452- } ,
453- _ => bug ! ( "shift_mask_val: expected Integer or Vector, found {:?}" , kind) ,
454- }
455- }
0 commit comments