One last question. Since labelling the variables as volatile has the effect of turning off optimizations related to them, I tried using __attribute__((const)) on the function to ensure IPA, but the function call still happened. Why couldn't the compiler optimize these calls away since anyway the function doesn't cause any external effect? ________________________________________ From: Marc Glisse <marc.glisse@xxxxxxxx> Sent: Sunday, January 23, 2022 11:25 AM To: Vishal Subramanyam Cc: gcc-help@xxxxxxxxxxx Subject: Re: Pure/const function not getting executed as the first operand to logical OR ( || ) (C++) On Sun, 23 Jan 2022, Vishal Subramanyam via Gcc-help wrote: > is there a specific name for the type of optimization where the compiler simply decides to drop the return value. Gcc handles this as part of dead code elimination (among others). A simpler example would be int main(){ 1/0; } which does not crash either. If you want to make your function func opaque to the optimizers, you may be interested in __attribute__((noipa)). Using volatile would also avoid some optimizations. -- Marc Glisse