https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89082
Bug ID: 89082
Summary: Feature request: provide annotation for code that's
unlikely to be executed
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: Hi-Angel at yandex dot ru
Target Milestone: ---
In most projects a definite pattern that's unlikely to be executed is a
PRINT_ERR macro which is basically a wrapper around fprintf() call. E.g.
if (some_error) {
PRINT_ERR("ERR");
// do cleanup
return;
}
It would be great if GCC provided an attribute or something to make a hint,
that whenever PRINT_ERR appears, whatever branch was prior to that is unlikely
to be taken.
------------------
This follows the original question here
https://gcc.gnu.org/ml/gcc-help/2019-01/msg00016.html TL;DR of the discussion
is that currently GCC provides α) __builtin_expect(), but it requires to be
inserted inside an if-condition; and β) `__attribute__((cold))` which requires
macro to be converted to a function, and even then it does something completely
different from being just a "branch hint" — instead it produces a very slow
code.