> On Tue, 10 Dec 2024, Jan Hubicka wrote: > > > Hi, > > int: > > struct foo > > { > > int a; > > void bar() const; > > ~foo() > > { > > if (a != 42) > > __builtin_abort (); > > } > > }; > > __attribute__ ((noinline)) > > void test(const struct foo a) > > { > > int b = a.a; > > a.bar(); > > if (a.a != b) > > __builtin_printf ("optimize me away"); > > } > > struct foo is passed by invisible reference. As discussed in the PR, > > since it is declared const, it can not change before function test > > returns. This makes it possible to optimize out the conditional. > > Doesn't this break the case where 'a' is declared mutable? Hmm, good point. declaring a mutable definitely lets me to chagne value in bar. I am adding Jason and Jonatan to CC. We could probably special case types containing mutable if such code is valid?
Honza