On Thu, Jan 14, 2021 at 09:28:31AM +0100, Jakub Jelinek via Gcc-patches wrote: > I'm afraid yes, because it is not a toplevel routine, but something called > from the c-family pretty-printers, so it can be in the middle of arbitrary > C/C++ expressions. And printing > (3 * (access to a memory object of type 'int' at offset 12 bytes from 't') + > 31) * 42 > would be just weird. > > > We could print, instead of *((int *)t + 3), "access to a memory > > object of type 'int' at offset 12 bytes from 't'", thus explain > > in plain english. > > > > That said, *((int *)t + 3) is exactly what the access is, > > *((int *)&t + 3) actually, the code I haven't touched has multiple bugs. > > The user generally doesn't know the exact layout of the structures, > and especially with C++ templates it is extremely hard to figure that out, > so even when we could print verbose text it would be helpful to give a hint > (in your text something like (which falls into 't.u.b')). > I don't see how we can print both the MEM_REF type and TBAA type in a way > that would be understandable to the user. > > Could we print > t.u.b > if the TBAA type is compatible with the type of the reference and perhaps > *(int*)&t.u.b > if it is incompatible? > >From the aliasing perspective that is still different, but we don't print > the TBAA type anyway.
There is another option I forgot about, but perhaps it is too verbose. Print *(int*)((char*)&t + offsetof (struct T, u.b)) so like *(int*)((char*)&t + 12) but print the offset in a more user-friendly way. Jakub