[llvm-dev] Question about __builtin_object_size

George Burgess IV via llvm-dev llvm-dev at lists.llvm.org
Tue Feb 9 11:32:51 PST 2016


This is an artifact of how LLVM works. Essentially, LLVM detects that `var`
is unused and deletes it before it tries to lower the `llvm.objectsize`
(which is what clang lowers `__builtin_object_size` to) call to a constant.
While this isn't ideal, I don't think it realistically a problem, because
`var` must be otherwise unused for this behavior to occur, and the whole
purpose of objectsize functions (so far) is to insert bounds checks when a
variable is used.

If this quirk is causing real problems for you, please let me know and I'll
see what I can do about fixing it. :)

Thanks for pointing this out!

On Tue, Feb 9, 2016 at 11:06 AM, Xinliang David Li <xinliangli at gmail.com>

> What version of clang/LLVM are you using? George (cc'ed ) has improved
> __builtin_object_size support in Clang recently.
> David
> On Tue, Feb 9, 2016 at 6:37 AM, Strahinja Petrovic via llvm-dev <
> llvm-dev at lists.llvm.org> wrote:
>> Hi,
>> I have question about __builtin_object_size behaviour. LLVM for
>> __builtin_object_size function doesn't calculate correct value when pointer
>> is used only in __builtin_object_size function call, and never after that.
>> For this case LLVM as result generates 0 or -1 depends of second argument
>> of __builtin_object_size function. Is this correct behaviour or it should
>> work as gcc (gcc calculates correct value for this case) ?
>> Example for this issue:
>> include <assert.h>
>> int main() {
>> struct V { char buf1[10];
>>            int b;
>>            char buf2[10];
>>           } var;
>>           char *p = &var.buf1[1], *q = &var.b;
>>           assert (__builtin_object_size (p, 0) == sizeof (var) - 1);
>>           return 0;
>> }
>> Thanks,
>> Strahinja
>> _______________________________________________
>> LLVM Developers mailing list
>> llvm-dev at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160209/08e47e6f/attachment.html>

More information about the llvm-dev mailing list