https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85562
Bug ID: 85562 Summary: -Wsuggest-attribute=malloc misleads about "returning normally" Product: gcc Version: 8.0.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: eggert at cs dot ucla.edu Target Milestone: --- I ran into this problem when compiling Emacs with gcc (GCC) 8.0.1 20180324 (Red Hat 8.0.1-0.20) x86-64. When I use this command: gcc -S -O2 -Wsuggest-attribute=malloc sample.c to compile the following program: #include <stdlib.h> void * xmalloc (size_t n) { if (n == 0) abort (); return malloc (n); } the output is: sample.c: In function ‘xmalloc’: sample.c:4:1: warning: function might be candidate for attribute ‘malloc’ if it is known to return normally [-Wsuggest-attribute=malloc] xmalloc (size_t n) ^~~~~~~ The phrase "if it is known to return normally" is misleading and should be removed from the diagnostic. Although the phrase is borrowed from similar diagnostics for pure functions where the phrase is relevant (see GCC bug 51971), whether a function is known to return normally is irrelevant to how the compiler should optimize the malloc attribute. The GCC manual does not state that the malloc attribute should be applied only to functions that return normally, and GCC's diagnostics should not imply otherwise.