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)
array -> array element.