This is an archive of the discontinued LLVM Phabricator instance.

Bugfix - Clang handles __builtin_object_size in wrong way
ClosedPublic

Authored by george.burgess.iv on Aug 12 2015, 5:04 PM.

Details

Summary

Attached is a fix for https://llvm.org/bugs/show_bug.cgi?id=15212 .

Summary: Tighten up some of the results for __builtin_object_size(ptr, type) when given type == 1 or type == 3 + fixed a bug where we would report incorrect results for type == 3.

~90% of the patch is courtesy of Richard Smith. :)

Diff Detail

Event Timeline

george.burgess.iv retitled this revision from to Bugfix - Clang handles __builtin_object_size in wrong way.
george.burgess.iv updated this object.
george.burgess.iv added a subscriber: cfe-commits.
rsmith added a subscriber: rsmith.Aug 14 2015, 5:11 PM
rsmith added inline comments.
lib/AST/ExprConstant.cpp
6221–6223

Please add a testcase like this (where the base object is unknown but the designator is known, and thus we can compute the Type == 1 and Type == 3 forms but not the Type == 0 and Type == 2 forms).

6243–6245

Please add testcases for the pointer-to-the-end case:

int n;
static_assert(__builtin_object_size(&n + 1, 1) == 0);

struct X { int a, b, c; } x;
static_assert(__builtin_object_size(&x.a + 1, 1) == 0);
george.burgess.iv updated this object.
george.burgess.iv marked an inline comment as done.

Addressed feedback.

lib/AST/ExprConstant.cpp
6221–6223

EvaluatePointer is stricter than I thought -- this is actually not possible without adding a decent amount of complexity to the current patch. Will replace the comment with a TODO, and add the test case in the next patch that makes us support things like this. :)

rsmith accepted this revision.Aug 17 2015, 1:11 PM
rsmith added a reviewer: rsmith.

LGTM with one more testcase :)

lib/AST/ExprConstant.cpp
6243–6245

I think you now have a testcase for the end-of-array case, but not the end-of-nonarray case.

This revision is now accepted and ready to land.Aug 17 2015, 1:11 PM