[PATCH] D18438: Calculate __builtin_object_size when pointer depends on a condition

George Burgess IV via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 28 15:22:57 PDT 2016


In clang's lib/AST/ExprConstant.cpp, it seems that we always return 0 if
our offset from the object's start is negative (or if the offset is greater
than the size of the object). I think this behavior is sane, and that it
would be odd if LLVM and clang acted differently here, so I'd just hand
back 0 bytes if our offset is negative.

On Mon, Mar 28, 2016 at 3:29 AM, Strahinja Petrovic <
strahinja.petrovic at rt-rk.com> wrote:

> spetrovic added a comment.
>
> Ok, I will resolve offset problem in this revision. Handling Phis will be
> different patch after this is committed.
> So, I have question about offset problem. For this  example:
>
> int foo(int N) {
>
>   char Small[10];
>   char Large[20];
>
>   char *Ptr = N ? Small : Large - 19;
>   return __builtin_object_size(Ptr,0);
>
> }
>
> int main() {
>
>   size_t ret;
>   ret = foo(0);
>   printf("\n%d\n", ret);
>   return 0;
>
> }
>
> gcc gives 39 as result, I don't think that is correct value, what is your
> opinion about this case and similar cases ?
>
>
> Repository:
>   rL LLVM
>
> http://reviews.llvm.org/D18438
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160328/b0ecdd04/attachment.html>


More information about the llvm-commits mailing list