Is there any case where functions foo()
and optimized_foo()
in the example below are not equivalent?
struct Test
{
int x;
int y;
int z;
};
// Some external function. Implementation unknown.
void bar(int& arg);
void foo()
{
Test t;
t.x = 3;
t.y = 4;
t.z = 5;
bar(t.y);
}
void optimized_foo()
{
int t_y = 4;
bar(t_y);
}
It's just that all major x86_64 compilers (gcc 10.2, clang 10.0, msvc 19.24) keep the initialization of t.x
and t.z
in assembler code generated for foo()
even at the highest optimization level. Even though those members are obviously not used. Do they have a reason?
Am I right assuming that bar()
, being given a reference to one data member of a structure, has no legal way to obtain a pointer/reference to other members? What does the standard say about it?