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]

Question about sizeof after struct change


Hi,

I am working on an LTO pass which drops unused fields on structs. On my
tests, I found that the gimple generated for `sizeof` is a constant. For
example, for the following C code:

```
struct astruct_s { _Bool c; _Bool a; _Bool b; };
struct astruct_s astruct;

int
main()
{
  int size = sizeof(astruct);
  return 0;
}
```

Produces the following gimple code:
```
size_1 = 3;
_2 = 0;
<L0>:
return _2;
```

Is there a way to determine where the value assigned to size_1 is
obtained from? I would like to 
1. inspect sizeof statements
2. determine whether the argument of sizeof is struct astruct_s
3. substitute struct astruct_s with a modified version of struct
astruct_s which has field `a` removed.

Therefore, at the end of this transformation we would have size_1 = 2;
Similary, I would like pointer arithmetic to be affected. For example:

```
struct astruct_s { _Bool c; _Bool a; _Bool b; };
struct astruct_s astruct;

int
main()
{
  _Bool *c = &astruct.c;
  _Bool *b = &astruct.b;
  ptrdiff_t d = b - c;
  printf("%d\n", d);
}
```

Produces the following gimple code:
```
c_3 = &astruct.c;
b_4 = &astruct.b;
d_5 = b_4 - c_3;
```

Running the code results in the value 2 being printed . After running
the transformation, the result should be 1.

Can anyone point me in the right direction?

So far I have tried changing the TYPE_FIELDS to drop field a, but that
doesn't work and it is not general. I also have some code which
creates a copy of RECORD_TYPE tree and modifies the tree and creates a
new identifier for this modified RECORD_TYPE tree. However, I believe
this may still not produce the intended behaviour.

Any help is appreciated. Thanks!

-Erick


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