]> granicus.if.org Git - clang/commit
Make __builtin_object_size more conservative
authorGeorge Burgess IV <george.burgess.iv@gmail.com>
Fri, 16 Oct 2015 01:49:01 +0000 (01:49 +0000)
committerGeorge Burgess IV <george.burgess.iv@gmail.com>
Fri, 16 Oct 2015 01:49:01 +0000 (01:49 +0000)
commitff21e1767dcae28628e2f8d7a5e71fe7dcb1db99
treea488b36e2e2d0a9cd3083462d6ab899e4a299b88
parent3947fa32ce1130020e7cd76a725d5b7f744a1ccd
Make __builtin_object_size more conservative

r246877 made __builtin_object_size substantially more aggressive with
unknown bases if Type=1 or Type=3, which causes issues when we encounter
code like this:

struct Foo {
  int a;
  char str[1];
};

const char str[] = "Hello, World!";
struct Foo *f = (struct Foo *)malloc(sizeof(*f) + strlen(str));
strcpy(&f->str, str);

__builtin_object_size(&f->str, 1) would hand back 1, which is
technically correct given the type of Foo, but the type of Foo lies to
us about how many bytes are available in this case.

This patch adds support for this "writing off the end" idiom -- we now
answer conservatively when we're given the address of the very last
member in a struct.

Differential Revision: http://reviews.llvm.org/D12169

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@250488 91177308-0d34-0410-b5e6-96231b3b80d8
lib/AST/ExprConstant.cpp
test/CodeGen/object-size.c
test/CodeGen/object-size.cpp