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.