[clang] Change builtin object size when subobject is invalid
authorJeffrey T Mott <jeffrey.t.mott@intel.com>
Thu, 7 Jan 2021 19:56:32 +0000 (11:56 -0800)
committerGeorge Burgess IV <george.burgess.iv@gmail.com>
Thu, 7 Jan 2021 20:34:07 +0000 (12:34 -0800)
commit275f30df8ad6de75e1f29e4b33eaeb67686caf0d
treed70fbf74b5d6129dc17d1b1cba2dbc983c7373e7
parent36c4dc9b42fe2e6af4ab488b7c4013d5082b67f6
[clang] Change builtin object size when subobject is invalid

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.

Differential Revision: https://reviews.llvm.org/D92892
clang/lib/AST/ExprConstant.cpp
clang/test/CodeGen/object-size.c