<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Jan 5, 2022 at 7:58 PM Jessica Clarke <<a href="mailto:jrtc27@jrtc27.com">jrtc27@jrtc27.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On 5 Jan 2022, at 22:32, Augie Fackler via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br>
> Proposal<br>
> =======<br>
> We add two attributes to LLVM IR:<br>
> <br>
>  * `allocator(FAMILY)`: Marks a function as part of an allocator family, named by the “primary” allocation function (e.g. `allocator(“malloc”)`, `allocator(“_Znwm”)`, or `allocator(“__rust_alloc”)`).<br>
<br>
Why do you need a family? What’s insufficient about just using allocsize(idx), as used by __attribute__((alloc_size(...)) in GNU C? (Which you acknowledge the existence of, but don’t justify why you need your own attribute.) What to use as the allocator “family” string for C++ operator new seems pretty unclear too, so I’m not sure how good an idea this free-form string argument is in your proposal.<br></blockquote><div><br></div><div>For C++ new we'd use the mangled form of ::operator::new, aka _Znwm. The reason for the family is so that we can track which allocations are related, so that incorrect code like</div><div><br></div><div>{</div><div>  auto *foo = new Foo();</div><div>  free(foo);</div><div>}</div><div><br></div><div>doesn't get optimized away. I believe others I talked to while designing this might have had more interesting ideas for how the family could be used, but it's easy to put in today, and roughly impossible to add via an IR upgrade if we don't put it in, so it seems sensible to try and track the family now. I actually initially argued against the family argument, but was won over by the limitation that we'd be unable to upgrade it in the future.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
>  * `releaseptr(idx)`: Indicates that the function releases the pointer that is its Nth argument.<br>
<br>
This should probably just be free(idx)/frees(idx)/willfree(idx) (we already have nofree as an attribute for arguments), or an attribute on the argument itself. Talking about releasing makes it sound like reference counting semantics.<br></blockquote><div><br></div><div>Sure, that seems reasonable. I'll update my prototype to use that name instead. Thanks!</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
Jess<br><br>
</blockquote></div></div>