[llvm-dev] Placement new and TBAA

Hubert Tong via llvm-dev llvm-dev at lists.llvm.org
Thu Dec 1 08:22:04 PST 2016


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?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20161201/8acb8a70/attachment.html>


More information about the llvm-dev mailing list