Motivating example:
struct { int v[10]; } t[10]; __builtin_object_size( &t[0].v[11], // access past end of subobject 1 // request remaining bytes of closest surrounding subobject );
In GCC, this returns 0. https://godbolt.org/z/7TeGs7
In current clang, however, this returns 356, the number of bytes remaining in the whole variable, as if the type was 0 instead of 1. https://godbolt.org/z/6Kffox
This patch checks for the specific case where we're requesting a subobject's size (type 1) but the subobject is invalid.
nit: the new part of this condition makes this comment somewhat outdated. should it say something like "outside of" instead of "before"?