This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Question about sizeof after struct change


On Fri, 3 Jan 2020 at 16:09, Erick Ochoa wrote:
> Do you mean something like taking the address of a struct and adding an offset
> to access a field?

Yes, the following code is valid:

struct S { int unused; int used; };
static_assert( sizeof(S) == 8 );
S s[4];
int* s2_used = (int*)((char*)s + 20);

Accessing the field doesn't refer to S::used or S::unused directly,
and doesn't use sizeof(S) or sizeof(int) explicitly.

So if your pass removes S::unused, then you'd need to analyse
((char*)s + 20) to determine that it accesses s[2].used and then
adjust it to ((char*)s + 8) instead.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]