File tree Expand file tree Collapse file tree
compiler/rustc_codegen_llvm/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -517,7 +517,16 @@ pub(crate) fn llfn_attrs_from_instance<'ll, 'tcx>(
517517 to_add. push ( llvm:: CreateAllocKindAttr ( cx. llcx , AllocKindFlags :: Free ) ) ;
518518 // applies to argument place instead of function place
519519 let allocated_pointer = AttributeKind :: AllocatedPointer . create_attr ( cx. llcx ) ;
520- attributes:: apply_to_llfn ( llfn, AttributePlace :: Argument ( 0 ) , & [ allocated_pointer] ) ;
520+ let attrs: & [ _ ] = if llvm_util:: get_version ( ) >= ( 21 , 0 , 0 ) {
521+ // "Does not capture provenance" means "if the function call stashes the pointer somewhere,
522+ // accessing that pointer after the function returns is UB". That is definitely the case here since
523+ // freeing will destroy the provenance.
524+ let captures_addr = AttributeKind :: CapturesAddress . create_attr ( cx. llcx ) ;
525+ & [ allocated_pointer, captures_addr]
526+ } else {
527+ & [ allocated_pointer]
528+ } ;
529+ attributes:: apply_to_llfn ( llfn, AttributePlace :: Argument ( 0 ) , attrs) ;
521530 }
522531 if let Some ( align) = codegen_fn_attrs. alignment {
523532 llvm:: set_alignment ( llfn, align) ;
You can’t perform that action at this time.
0 commit comments