]> granicus.if.org Git - clang/commit
[ExprConstant] Fix PR28314 - crash while evluating objectsize.
authorGeorge Burgess IV <george.burgess.iv@gmail.com>
Mon, 27 Jun 2016 19:40:41 +0000 (19:40 +0000)
committerGeorge Burgess IV <george.burgess.iv@gmail.com>
Mon, 27 Jun 2016 19:40:41 +0000 (19:40 +0000)
commit8313f1a0e74a83fef3c2be2e401d5083324126ca
tree50b6bcd3d21cdaafa0e5615f41d388f075176fe0
parent7b4330af6b03cabdb8800fc989f6d01380d7db98
[ExprConstant] Fix PR28314 - crash while evluating objectsize.

This fixes a crash in code like:
```
struct A {
  struct B b;
  char c[1];
}

int foo(struct A* a) { return __builtin_object_size(a->c, 0); }
```

We wouldn't check whether the structs we were examining were invalid,
and getting the layout of an invalid struct is (unsurprisingly) A Bad
Thing. With this patch, we'll always return conservatively if we see an
invalid struct, since I'm assuming the presence of an invalid struct
means that our compilation failed (so having a conservative result isn't
such a big deal).

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