[all-commits] [llvm/llvm-project] 275f30: [clang] Change builtin object size when subobject ...

Mott, Jeffrey T via All-commits all-commits at lists.llvm.org
Thu Jan 7 12:38:25 PST 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 275f30df8ad6de75e1f29e4b33eaeb67686caf0d
      https://github.com/llvm/llvm-project/commit/275f30df8ad6de75e1f29e4b33eaeb67686caf0d
  Author: Jeffrey T Mott <jeffrey.t.mott at intel.com>
  Date:   2021-01-07 (Thu, 07 Jan 2021)

  Changed paths:
    M clang/lib/AST/ExprConstant.cpp
    M clang/test/CodeGen/object-size.c

  Log Message:
  -----------
  [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




More information about the All-commits mailing list