https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81568
Bug ID: 81568 Summary: attribute always_inline honored even after attribute noinline Product: gcc Version: 8.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: msebor at gcc dot gnu.org Target Milestone: --- GCC detects and warns about the obviously nonsensical combination of attribute always_inline and noinline on the same function. That's good so far as it goes but there are a couple of minor problems with how GCC treats this situation: When the conflicting attributes appear on distinct declarations of the same function (the more likely case of the problem) it doesn't indicate which of the two GCC accepts. When the conflicting attributes appear the same declaration of a function the warning makes it clear that it's the second of the two attributes that's ignored. Based on this one would expect the same to be true in the first case (distinct declarations) but, as it turns out (and as the test case below shows), that doesn't appear to be the case. $ cat x.c && gcc -O2 -S -Wall -Wextra -Wpedantic -o/dev/stdout x.c int __attribute__ ((noinline)) f (int); int __attribute__ ((always_inline)) f (int); int f (int i) { return i > 1 ? i * f (i - 1) * f (i - 2) : i > 0 ? i * f (i - 1) : 1; } int f1 (void) { return f (123); } int __attribute__ ((always_inline, noinline)) g (int); .file "x.c" x.c:2:37: warning: declaration of ‘f’ with attribute ‘always_inline’ follows declaration with attribute ‘noinline’ [-Wattributes] int __attribute__ ((always_inline)) f (int); ^ x.c:1:32: note: previous declaration of ‘f’ was here int __attribute__ ((noinline)) f (int); ^ x.c:11:1: warning: ‘noinline’ attribute ignored due to conflict with attribute ‘always_inline’ [-Wattributes] int __attribute__ ((always_inline, noinline)) g (int); ^~~ x.c: In function ‘f1’: x.c:4:5: error: inlining failed in call to always_inline ‘f’: function not inlinable int f (int i) { return i > 1 ? i * f (i - 1) * f (i - 2) : i > 0 ? i * f (i - 1) : 1; } ^ x.c:8:10: note: called from here return f (123); ^~~~~~~