[PATCH] D12821: Allow for C's "writing off the end" idiom in __builtin_object_size
George Burgess IV via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 11 16:29:44 PDT 2015
george.burgess.iv created this revision.
george.burgess.iv added a reviewer: rsmith.
george.burgess.iv added subscribers: cfe-commits, mzolotukhin.
In C, a common idiom is:
```
struct Foo { int a; char cs[1] };
struct Foo *F = (struct Foo *)malloc(sizeof(Foo) + strlen(SomeString));
strcpy(F->cs, SomeString);
```
Currently, __builtin_object_size does not allow for this, which breaks some existing code. This patch makes us answer conservatively in Clang if the following conditions are met:
- Type is 1 or 3
- The Base is invalid/can't be determined
- The subobject we're referencing is the last subobject in the struct
- The subobject we're referencing is an array with 0 or 1 elements (for 0 elements, both `char foo[]` and `char foo[0]` syntaxes are supported)
http://reviews.llvm.org/D12821
Files:
lib/AST/ExprConstant.cpp
test/CodeGen/object-size.c
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D12821.34601.patch
Type: text/x-patch
Size: 11509 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150911/f4bc1636/attachment-0001.bin>
More information about the cfe-commits
mailing list