@@ -1102,18 +1102,24 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
11021102 val : RValue < ' gcc > ,
11031103 ptr : RValue < ' gcc > ,
11041104 align : Align ,
1105- _flags : MemFlags ,
1105+ flags : MemFlags ,
11061106 ) -> RValue < ' gcc > {
11071107 let ptr = self . check_store ( val, ptr) ;
11081108 let destination = ptr. dereference ( self . location ) ;
11091109 // NOTE: libgccjit does not support specifying the alignment on the assignment, so we cast
11101110 // to type so it gets the proper alignment.
11111111 let destination_type = destination. to_rvalue ( ) . get_type ( ) . unqualified ( ) ;
1112- let aligned_type = destination_type. get_aligned ( align. bytes ( ) ) . make_pointer ( ) ;
1113- let aligned_destination = self . cx . context . new_bitcast ( self . location , ptr, aligned_type) ;
1114- let aligned_destination = aligned_destination. dereference ( self . location ) ;
1115- self . llbb ( ) . add_assignment ( self . location , aligned_destination, val) ;
1116- // TODO(antoyo): handle align and flags.
1112+ let align = if flags. contains ( MemFlags :: UNALIGNED ) { 1 } else { align. bytes ( ) } ;
1113+ let mut modified_destination_type = destination_type. get_aligned ( align) ;
1114+ if flags. contains ( MemFlags :: VOLATILE ) {
1115+ modified_destination_type = modified_destination_type. make_volatile ( ) ;
1116+ }
1117+
1118+ let modified_ptr =
1119+ self . cx . context . new_cast ( self . location , ptr, modified_destination_type. make_pointer ( ) ) ;
1120+ let modified_destination = modified_ptr. dereference ( self . location ) ;
1121+ self . llbb ( ) . add_assignment ( self . location , modified_destination, val) ;
1122+ // TODO(antoyo): handle `MemFlags::NONTEMPORAL`.
11171123 // NOTE: dummy value here since it's never used. FIXME(antoyo): API should not return a value here?
11181124 // When adding support for NONTEMPORAL, make sure to not just emit MOVNT on x86; see the
11191125 // LLVM backend for details.
@@ -1236,13 +1242,13 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
12361242 }
12371243
12381244 fn ptrtoint ( & mut self , value : RValue < ' gcc > , dest_ty : Type < ' gcc > ) -> RValue < ' gcc > {
1239- let usize_value = self . cx . const_bitcast ( value, self . cx . type_isize ( ) ) ;
1245+ let usize_value = self . cx . context . new_cast ( None , value, self . cx . type_isize ( ) ) ;
12401246 self . intcast ( usize_value, dest_ty, false )
12411247 }
12421248
12431249 fn inttoptr ( & mut self , value : RValue < ' gcc > , dest_ty : Type < ' gcc > ) -> RValue < ' gcc > {
12441250 let usize_value = self . intcast ( value, self . cx . type_isize ( ) , false ) ;
1245- self . cx . const_bitcast ( usize_value, dest_ty)
1251+ self . cx . context . new_cast ( None , usize_value, dest_ty)
12461252 }
12471253
12481254 fn bitcast ( & mut self , value : RValue < ' gcc > , dest_ty : Type < ' gcc > ) -> RValue < ' gcc > {
0 commit comments