[llvm-dev] The semantics of nonnull attribute

Jacob Lifshay via llvm-dev llvm-dev at lists.llvm.org
Tue Feb 18 21:35:56 PST 2020


On Tue, Feb 18, 2020, 18:51 Juneyoung Lee via llvm-dev <
llvm-dev at lists.llvm.org> wrote:

> I guess in many cases Rust/Swift functions can be lowered into IR
> functions with not_poison flags attached (though I'm not an Rust/Swift
> expert, so just a guess)
> For C, people may want to allow idioms like below, so further
> investigation is needed:
>
> int x, y;
> if (cond) x = 1; else y = 1;
> f(cond, x, y);
>

The same thing can be done in Rust, though I expect it to be less common:

let mut x = MaybeUninit::<i32>::uninit();
let mut y = MaybeUninit::<i32>::uninit();
unsafe {
    if cond {
        x.as_mut_ptr().write(1);
    } else {
        y.as_mut_ptr().write(1);
    }
}
f(cond, x, y);

Jacob Lifshay
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200218/ca58f60a/attachment.html>


More information about the llvm-dev mailing list