[PATCH] D17746: Fix PR26741 -- __builtin_object_size is not consistently conservative with C++ inheritance

George Burgess IV via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 29 17:40:03 PST 2016

george.burgess.iv created this revision.
george.burgess.iv added a reviewer: rsmith.
george.burgess.iv added a subscriber: cfe-commits.

This patch fixes PR26741, and makes us handle inheritance more sanely.

Broken code:

struct Foo { char a[1]; };
struct Bar : Foo {};

int break() {
  Bar *b;
  int size = __builtin_object_size(b->a, 1);
  assert(size == -1); // Fires; size is 1.

Because we're now handling inheritance, this patch has a few fun things in it (see: the new loop at ExprConstant.cpp:6489) so that we aren't overly conservative when inheritance is involved. I'm not entirely thrilled with how we determine if a base class is considered to be at the end of a derived class; better approaches are appreciated.



-------------- next part --------------
A non-text attachment was scrubbed...
Name: D17746.49440.patch
Type: text/x-patch
Size: 8044 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160301/47c9e8c5/attachment-0001.bin>

More information about the cfe-commits mailing list