[llvm-dev] Question about __builtin_object_size
Strahinja Petrovic via llvm-dev
llvm-dev at lists.llvm.org
Wed Feb 10 02:46:14 PST 2016
Thank you for replies. I'm using trunk version. I have problem in some
tests with this behaviour. I also have fix for this problem just need an
opinion if this should be fixed in clang. I can post patch on
phabricator if you want to take a look.
Thanks,
Strahinja
On 09.02.2016. 20:32, George Burgess IV wrote:
> Hi!
>
> 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!
> George
>
> On Tue, Feb 9, 2016 at 11:06 AM, Xinliang David Li
> <xinliangli at gmail.com <mailto:xinliangli at gmail.com>> wrote:
>
> 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 <mailto: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 <mailto: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/20160210/bc09d4bf/attachment.html>
More information about the llvm-dev
mailing list