On Tue, Aug 5, 2014 at 4:54 AM, Dmitry Antipov <dmanti...@yandex.ru> wrote: > > it it possible to get a kind of diagnostics if the variable > is totally optimized away? For example, in: > > void foo (struct some_type *obj) { > ... some code where 'obj' is not used ... > bar (obj->some_member); > ... some code where 'obj' is not used again ... > baz (obj->some_member); > } > > 'obj' is likely to be optimized away so only 'obj->some_member' really > exists (in a register or stack location). Getting diagnostics > or preserving 'obj' may be important if there is a GC which scans > C stack and registers conservatively - if there is no direct reference > to 'obj', it's likely to be reclaimed and so 'obj->some_member' > becomes garbage.
This question would be more appropriate on gcc-h...@gcc.gnu.org. The gcc@gcc.gnu.org list is for discussion about the development of GCC. Please take any followups to gcc-help. Thanks. There are no diagnostics for a variable being optimized away. That is a normal occurrence. If obj->some_member is loaded into a register, then it doesn't matter whether obj is collected. If obj->some_member is not loaded into a register, then there must be some pointer into obj, and a conservative GC will not collect the memory. Ian