[PATCH] D47299: [CodeGenCXX] Emit strip.invariant.group with -fstrict-vtable-pointers

Piotr Padlewski via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Jun 16 10:56:36 PDT 2018


Prazek added inline comments.


================
Comment at: clang/lib/CodeGen/CGExprScalar.cpp:1647
+      }
+    }
+
----------------
rjmccall wrote:
> Prazek wrote:
> > rjmccall wrote:
> > > Incidentally, how do you protect against code like this?
> > > 
> > >   A *ptr;
> > >   reinterpret_cast<B *&>(ptr) = new B();
> > >   ptr->foo();
> > > 
> > > Presumably there needs to be a launder/strip here, but I guess it would have to be introduced by the middle-end when forwarding the store?  The way I've written this is an aliasing violation, but (1) I assume your pass isn't disabled whenever strict-aliasing is disabled and (2) you can do this with a memcpy and still pretty reliably expect that LLVM will be able to eventually forward the store.
> > Can you add more info on what is A and B so I can make sure I understand it correctly?
> > Is the prefix of the layout the same for both, but they are not in the hierarchy?
> > 
> > I haven't thought about the strict aliasing. I think the only sane way would be to require strict aliasing for the strict vtable pointers.
> It's whatever case you're worried about such that you have to launder member accesses and bitcasts.
> 
> And like I mentioned, relying on strict aliasing isn't enough because you can do it legally with memcpy.  Maybe it's okay to consider it UB?  I'm not sure about that.
AFAIK reinterpreting one class as another is UB if they are not in hierarchy (especially calling virtual function on reinterpreted class), not sure if strict aliasing should allow it anyway (if it would be a hand written custom vptr then it should be ok with strict aliasing turned off, but with vptr I don't think it is legal).
@rsmith Can you comment on that?


Repository:
  rL LLVM

https://reviews.llvm.org/D47299





More information about the llvm-commits mailing list