@@ -752,33 +752,47 @@ pub fn trans_intrinsic_call<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
752752
753753 match split[ 1 ] {
754754 "cxchg" | "cxchgweak" => {
755- let cmp = from_immediate ( bcx, llargs[ 1 ] ) ;
756- let src = from_immediate ( bcx, llargs[ 2 ] ) ;
757- let ptr = PointerCast ( bcx, llargs[ 0 ] , val_ty ( src) . ptr_to ( ) ) ;
758- let weak = if split[ 1 ] == "cxchgweak" { llvm:: True } else { llvm:: False } ;
759- let val = AtomicCmpXchg ( bcx, ptr, cmp, src, order, failorder, weak) ;
760- let result = ExtractValue ( bcx, val, 0 ) ;
761- let success = ZExt ( bcx, ExtractValue ( bcx, val, 1 ) , Type :: bool ( bcx. ccx ( ) ) ) ;
762- Store ( bcx,
763- result,
764- PointerCast ( bcx, StructGEP ( bcx, llresult, 0 ) , val_ty ( src) . ptr_to ( ) ) ) ;
765- Store ( bcx, success, StructGEP ( bcx, llresult, 1 ) ) ;
755+ let sty = & substs. types . get ( FnSpace , 0 ) . sty ;
756+ if int_type_width_signed ( sty, ccx) . is_some ( ) {
757+ let weak = if split[ 1 ] == "cxchgweak" { llvm:: True } else { llvm:: False } ;
758+ let val = AtomicCmpXchg ( bcx, llargs[ 0 ] , llargs[ 1 ] , llargs[ 2 ] ,
759+ order, failorder, weak) ;
760+ let result = ExtractValue ( bcx, val, 0 ) ;
761+ let success = ZExt ( bcx, ExtractValue ( bcx, val, 1 ) , Type :: bool ( bcx. ccx ( ) ) ) ;
762+ Store ( bcx, result, StructGEP ( bcx, llresult, 0 ) ) ;
763+ Store ( bcx, success, StructGEP ( bcx, llresult, 1 ) ) ;
764+ } else {
765+ span_invalid_monomorphization_error (
766+ tcx. sess , span,
767+ & format ! ( "invalid monomorphization of `{}` intrinsic: \
768+ expected basic integer type, found `{}`", name, sty) ) ;
769+ }
766770 C_nil ( ccx)
767771 }
768772
769773 "load" => {
770- let tp_ty = * substs. types . get ( FnSpace , 0 ) ;
771- let mut ptr = llargs[ 0 ] ;
772- if let Some ( ty) = fn_ty. ret . cast {
773- ptr = PointerCast ( bcx, ptr, ty. ptr_to ( ) ) ;
774+ let sty = & substs. types . get ( FnSpace , 0 ) . sty ;
775+ if int_type_width_signed ( sty, ccx) . is_some ( ) {
776+ AtomicLoad ( bcx, llargs[ 0 ] , order)
777+ } else {
778+ span_invalid_monomorphization_error (
779+ tcx. sess , span,
780+ & format ! ( "invalid monomorphization of `{}` intrinsic: \
781+ expected basic integer type, found `{}`", name, sty) ) ;
782+ C_nil ( ccx)
774783 }
775- to_immediate ( bcx, AtomicLoad ( bcx, ptr, order) , tp_ty)
776784 }
777785
778786 "store" => {
779- let val = from_immediate ( bcx, llargs[ 1 ] ) ;
780- let ptr = PointerCast ( bcx, llargs[ 0 ] , val_ty ( val) . ptr_to ( ) ) ;
781- AtomicStore ( bcx, val, ptr, order) ;
787+ let sty = & substs. types . get ( FnSpace , 0 ) . sty ;
788+ if int_type_width_signed ( sty, ccx) . is_some ( ) {
789+ AtomicStore ( bcx, llargs[ 1 ] , llargs[ 0 ] , order) ;
790+ } else {
791+ span_invalid_monomorphization_error (
792+ tcx. sess , span,
793+ & format ! ( "invalid monomorphization of `{}` intrinsic: \
794+ expected basic integer type, found `{}`", name, sty) ) ;
795+ }
782796 C_nil ( ccx)
783797 }
784798
@@ -809,9 +823,16 @@ pub fn trans_intrinsic_call<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
809823 _ => ccx. sess ( ) . fatal ( "unknown atomic operation" )
810824 } ;
811825
812- let val = from_immediate ( bcx, llargs[ 1 ] ) ;
813- let ptr = PointerCast ( bcx, llargs[ 0 ] , val_ty ( val) . ptr_to ( ) ) ;
814- AtomicRMW ( bcx, atom_op, ptr, val, order)
826+ let sty = & substs. types . get ( FnSpace , 0 ) . sty ;
827+ if int_type_width_signed ( sty, ccx) . is_some ( ) {
828+ AtomicRMW ( bcx, atom_op, llargs[ 0 ] , llargs[ 1 ] , order)
829+ } else {
830+ span_invalid_monomorphization_error (
831+ tcx. sess , span,
832+ & format ! ( "invalid monomorphization of `{}` intrinsic: \
833+ expected basic integer type, found `{}`", name, sty) ) ;
834+ C_nil ( ccx)
835+ }
815836 }
816837 }
817838
0 commit comments