Skip to content

Commit 3df0dc8

Browse files
the8472RalfJung
andcommitted
mark rust_dealloc as captures(address)
Co-authored-by: Ralf Jung <post@ralfj.de>
1 parent c9af9c1 commit 3df0dc8

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

compiler/rustc_codegen_llvm/src/attributes.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff 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);

0 commit comments

Comments
 (0)