[PATCH] D12169: Relax constexpr rules to improve __builtin_object_size's accuracy

George Burgess IV via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 19 15:32:41 PDT 2015


george.burgess.iv created this revision.
george.burgess.iv added a reviewer: rsmith.
george.burgess.iv added a subscriber: cfe-commits.

(Hoping the formatting works as one would expect)

Motivating examples:
Pre-patch:

```
__builtin_object_size((char*)&foo, 0) != __builtin_object_size(&foo, 0) // if __builtin_object_size(&foo, 0) != -1
__builtin_object_size(&foo[1].bar[-1].baz, 1) == -1. // Always.
```

Post-patch:
Both act as one would expect. This was accomplished by making three changes:

  - Adding a flag to PointerExprEvaluator that makes it more accepting of reinterpret_casts.
  - Making array index/pointer offset less coupled in PointerExprEvaluator (we now carry around an extra Offset field that denotes how far we are away from an object boundary). 
  - Adding an OutermostMemberEvaluator that ignores `foo[1].bar[-1]` in `foo[1].bar[-1].baz`, and is more relaxed with casts/pointer arithmetic/etc. (Not 100% sold on the name)

http://reviews.llvm.org/D12169

Files:
  lib/AST/ExprConstant.cpp
  test/CXX/expr/expr.const/p2-0x.cpp
  test/CodeGen/object-size.c

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D12169.32624.patch
Type: text/x-patch
Size: 23028 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150819/30f45570/attachment-0001.bin>


More information about the cfe-commits mailing list