https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101279
Martin Sebor <msebor at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Ever confirmed|0 |1 Last reconfirmed| |2021-07-02 CC| |msebor at gcc dot gnu.org Status|UNCONFIRMED |NEW --- Comment #2 from Martin Sebor <msebor at gcc dot gnu.org> --- Compiling the test case with -Winline shows the problem: pr101279.c: In function ‘foo’: pr101279.c:2:19: warning: inlining failed in call to ‘wrapped_add’: optimization level attribute mismatch [-Winline] 2 | static inline int wrapped_add(int a, int b) { | ^~~~~~~~~~~ pr101279.c:7:12: note: called from here 7 | return wrapped_add(wrapped_add(x, y), z); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ pr101279.c:2:19: warning: inlining failed in call to ‘wrapped_add’: optimization level attribute mismatch [-Winline] 2 | static inline int wrapped_add(int a, int b) { | ^~~~~~~~~~~ pr101279.c:7:12: note: called from here 7 | return wrapped_add(wrapped_add(x, y), z); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Declaring wrapped_add() with attribute always_inline avoids the warning but also loses the -fwrapv option. This also seems somewhat surprising and could stand be made clearer in the manual. The manual says "this attribute inlines the function independent of any restrictions that otherwise apply to inlining." but I see no such restrictions discussed under the optimize attribute or in the inlining setion (https://gcc.gnu.org/onlinedocs/gcc/Inline.html). But this report isn't just about attribute optimize but rather about the general inconsistency of the interplay between inlining and each function attribute, and the lack of documentation of it. Confirmed. I'll see if I can add a few words to the manual for now.