11use std:: assert_matches;
2+ use std:: fmt:: Write ;
23
3- use rustc_abi:: { BackendRepr , Float , Integer , Primitive , Scalar } ;
4+ use rustc_abi:: { BackendRepr , Float , Integer , Primitive , Scalar , Size } ;
45use rustc_ast:: { InlineAsmOptions , InlineAsmTemplatePiece } ;
56use rustc_codegen_ssa:: mir:: operand:: OperandValue ;
67use rustc_codegen_ssa:: traits:: * ;
78use rustc_data_structures:: fx:: FxHashMap ;
8- use rustc_middle:: mir:: interpret:: Scalar as ConstScalar ;
9+ use rustc_middle:: mir:: interpret:: { PointerArithmetic , Scalar as ConstScalar } ;
910use rustc_middle:: ty:: Instance ;
1011use rustc_middle:: ty:: layout:: TyAndLayout ;
1112use rustc_middle:: { bug, span_bug} ;
@@ -161,8 +162,7 @@ impl<'ll, 'tcx> AsmBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
161162 InlineAsmOperandRef :: Const { value, ty : _ } => match value {
162163 ConstScalar :: Int ( _) => ( ) ,
163164 ConstScalar :: Ptr ( ptr, _) => {
164- let ( prov, offset) = ptr. prov_and_relative_offset ( ) ;
165- assert_eq ! ( offset. bytes( ) , 0 ) ;
165+ let ( prov, _) = ptr. prov_and_relative_offset ( ) ;
166166 let global_alloc = self . tcx . global_alloc ( prov. alloc_id ( ) ) ;
167167 let value = self . cx . alloc_to_backend ( global_alloc, false ) . unwrap ( ) ;
168168 inputs. push ( value) ;
@@ -226,11 +226,16 @@ impl<'ll, 'tcx> AsmBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
226226 }
227227 ConstScalar :: Ptr ( ptr, _) => {
228228 let ( _, offset) = ptr. prov_and_relative_offset ( ) ;
229- assert_eq ! ( offset. bytes( ) , 0 ) ;
230229
231230 // Only emit the raw symbol name
232231 template_str
233232 . push_str ( & format ! ( "${{{}:c}}" , op_idx[ & operand_idx] ) ) ;
233+
234+ if offset != Size :: ZERO {
235+ let offset =
236+ self . sign_extend_to_target_isize ( offset. bytes ( ) ) ;
237+ write ! ( template_str, "{offset:+}" ) . unwrap ( ) ;
238+ }
234239 }
235240 }
236241 }
@@ -446,7 +451,6 @@ impl<'tcx> AsmCodegenMethods<'tcx> for CodegenCx<'_, 'tcx> {
446451
447452 ConstScalar :: Ptr ( ptr, _) => {
448453 let ( prov, offset) = ptr. prov_and_relative_offset ( ) ;
449- assert_eq ! ( offset. bytes( ) , 0 ) ;
450454 let global_alloc = self . tcx . global_alloc ( prov. alloc_id ( ) ) ;
451455 let llval = self . alloc_to_backend ( global_alloc, true ) . unwrap ( ) ;
452456
@@ -457,6 +461,12 @@ impl<'tcx> AsmCodegenMethods<'tcx> for CodegenCx<'_, 'tcx> {
457461 . expect ( "symbol is not valid UTF-8" ) ;
458462 template_str
459463 . push_str ( & escape_symbol_name ( self . tcx , & symbol, span) ) ;
464+
465+ if offset != Size :: ZERO {
466+ let offset =
467+ self . sign_extend_to_target_isize ( offset. bytes ( ) ) ;
468+ write ! ( template_str, "{offset:+}" ) . unwrap ( ) ;
469+ }
460470 }
461471 }
462472 }
0 commit comments