-Wsuggest-attribute=cold issue?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,

If I have the following simple code:

// foo.hpp
struct foo {
__attribute__((cold)) int bar(void);
};
// foo.cpp
#include "foo.hpp"
int foo::bar(void) { return 0; }

And I compile with gcc-9 with optimizations on:

gcc-9 -O2 -Wsuggest-attribute=cold -c foo.cpp -o foo.o

I get the following warning message (also happens for gcc-8):

foo.cpp:32:5: warning: function might be candidate for attribute
‘cold’ [-Wsuggest-attribute=cold]
   2 | int foo::bar(void) { return 0;}

My experience with the other function attributes (pure, const,
format), is that once I added the suggested attribute to a that
gcc/g++ had deduced it was a candidate for the warning went away.
gcc/g++ does not suggest the cold attribute unless I'm also compiling
with -fprofile-use, which makes sense as it could not in general know
if a function is likely to be called or not.

But I as the programmer know functions/execution paths that only
happen once on program start up, and can tag them with the "cold"
attribute. What I'm hoping gcc/g++ will then do is to propagate my
"cold" tag of a leaf routine (one that does not call any other
functions) up the call stack and suggest additional functions that
call the function I tagged as being candidates for the "cold"
attribute as well. This *does* happen, but the functions that I have
already tagged with the "cold" attribute still generate the warning
(with or without -fprofile-use), and as I result I have a very hard
time separating the functions that I've already tagged from the ones
that I haven't, since the warning message shows the function
definition line in the source file, and the attribute tag is in the
header file.

Am I missing something, or is this an issue with gcc/g++ ?

Possibly related, I've found that when compiling with -flto, all
functions I've tagged with (pure, const, cold) generate spurious
warnings after the link step is complete for a library/executable. My
guess is that that is because the attribute information has already
been used/removed from the AST nodes at this point, though I don't
know for sure.

Any insights are greatly appreciated!
- John




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux