Strahinja Petrovic via llvm-dev
2016-Feb-09 14:37 UTC
[llvm-dev] Question about __builtin_object_size
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
Xinliang David Li via llvm-dev
2016-Feb-09 19:06 UTC
[llvm-dev] Question about __builtin_object_size
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/a57c04a1/attachment.html>
George Burgess IV via llvm-dev
2016-Feb-09 19:32 UTC
[llvm-dev] Question about __builtin_object_size
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> 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> 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>
Possibly Parallel Threads
- Question about __builtin_object_size
- Problem with __builtin_object_size when it depends on a condition
- Problem with __builtin_object_size when it depends on a condition
- RFC: Allowing @llvm.objectsize to be more conservative with null.
- RFC: Allowing @llvm.objectsize to be more conservative with null.