On 08/04/2018 02:52 PM, Martin Sebor wrote: > On 08/03/2018 01:43 AM, Jakub Jelinek wrote: >> On Thu, Aug 02, 2018 at 09:59:13PM -0600, Martin Sebor wrote: >>>> If I call this with foo (2, 1), do you still claim it is not valid C? >>> >>> String functions like strlen operate on character strings stored >>> in character arrays. Calling strlen (&s[1]) is invalid because >>> &s[1] is not the address of a character array. The fact that >>> objects can be represented as arrays of bytes doesn't change >>> that. The standard may be somewhat loose with words on this >>> distinction but the intent certainly isn't for strlen to traverse >>> arbitrary sequences of bytes that cross subobject boundaries. >>> (That is the intent behind the raw memory functions, but >>> the current text doesn't make the distinction clear.) >> >> But the standard doesn't say that right now. > > It does, in the restriction on multi-dimensional array accesses. > Given the array 'char a[2][2];' it's only valid to access a[0][0] > and a[0][1], and a[1][0], and a[1][1]. It's not valid to access > a[2][0] or a[2][1], even though they happen to be located at > the same addresses as a[1][0] and a[1][1]. > > There is no exception for distinct struct members. So in > a struct { char a[2], b[2]; }, even though a and b and laid > out the same way as char[2][2] would be, it's not valid to > treat a as such. There is no distinction between array > subscripting and pointer arithmetic, so it doesn't matter > what form the access takes. Understood WRT what the C language says.
Let's bring it back to GIMPLE though. In GIMPLE we allow those some crossing of subobject boundaries as explained earlier in the thread. It's not ideal, but that's the way things are. So with that in mind, I think we need to reevaluate some of the assumptions we're making in this code. Jeff