[llvm-dev] Placement new and TBAA

Mehdi Amini via llvm-dev llvm-dev at lists.llvm.org
Thu Dec 1 08:24:19 PST 2016




> On Dec 1, 2016, at 8:22 AM, Hubert Tong <hubert.reinterpretcast at gmail.com> wrote:
> 
>> On Sat, Nov 26, 2016 at 12:07 AM, Sanjoy Das <sanjoy at playingwithpointers.com> wrote:
>> So if you:
>> 
>>  1. override operator delete to do nothing for that type (so that the
>>     placement new actually has unfreed backing storage to re-use).
>>  2. have an empty destructor.
> So,
> 
> void *operator new(decltype(sizeof 0), void *) noexcept;
> 
> struct MyInt {
>   static void operator delete(void *) { }
>   MyInt() { x = 0; }
>   ~MyInt() { }
>   int x;
> };
> 
> float *qq;
> void foo(void *p, void *q, long unk) {
>   // unk = 1
>   for (long i = 0; i < unk; ++i) {
>     auto pp = new (p) MyInt;
>     delete pp; // or pp->~MyInt();
>     qq = new (static_cast<void *>(&reinterpret_cast<char *>(q)[i])) float(42);
>   }
> }
> 
>> then I suspect we'll have the same problem after the destructor and
>> the operator delete for that type has been inlined away.
> Yes; the same problem occurs.
> 
> So, it sounds like a new intrinsic is in order?

What kind of intrinsic are you thinking about here?

-- 
Mehdi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20161201/b59292be/attachment.html>


More information about the llvm-dev mailing list