@@ -752,33 +752,47 @@ pub fn trans_intrinsic_call<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
752
752
753
753
match split[ 1 ] {
754
754
"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
+ }
766
770
C_nil ( ccx)
767
771
}
768
772
769
773
"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)
774
783
}
775
- to_immediate ( bcx, AtomicLoad ( bcx, ptr, order) , tp_ty)
776
784
}
777
785
778
786
"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
+ }
782
796
C_nil ( ccx)
783
797
}
784
798
@@ -809,9 +823,16 @@ pub fn trans_intrinsic_call<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
809
823
_ => ccx. sess ( ) . fatal ( "unknown atomic operation" )
810
824
} ;
811
825
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
+ }
815
836
}
816
837
}
817
838
0 commit comments