rust/tests/codegen-llvm/read-only-capture-opt.rs
Nikita Popov d71ed8d19b Tell LLVM about read-only captures
`&Freeze` parameters are not only `readonly` within the function,
but any captures of the pointer can also only be used for reads.
This can now be encoded using the `captures(address, read_provenance)`
attribute.
2025-08-20 19:08:16 +02:00

19 lines
323 B
Rust

//@ compile-flags: -C opt-level=3 -Z mir-opt-level=0
//@ min-llvm-version: 21
#![crate_type = "lib"]
unsafe extern "C" {
safe fn do_something(p: &i32);
}
#[unsafe(no_mangle)]
pub fn test() -> i32 {
// CHECK-LABEL: @test(
// CHECK: ret i32 0
let i = 0;
do_something(&i);
do_something(&i);
i
}