mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2025-01-04 19:19:33 +00:00
BUILD: sched: workaround crazy and dangerous warning in Clang 14
Ilya reported in issue #1638 that Clang 14 has invented a new warning that encourages to modify the code in a way that is not always equivalent, by turning "|" to "||" between some logical operators, except that the first one guarantees that all members of the expression will always be evaluated while the latter will stop at the first one which is true! This warning triggers in thread_has_tasks(), which is not sensitive to such change of behavior but which is built this way because it results in branchless code for something that most often evaluates to false for all terms. As such it was out of question to turn this to less efficient compare-and-jump that needlessly pollute the branch predictor, so the workaround consists in casting each expression to (int). It was verified that the code is the same. Yet another example of how-to-introduce-bugs-by-fixing-valid-code through warnings invented around a beer without thinking longer! This may need to be backported to a few older branches in case this compiler lands in recent distros or if gcc finds it wise to imitate it.
This commit is contained in:
parent
5d774dee55
commit
e1efd2a2d7
@ -187,10 +187,10 @@ static inline int task_in_wq(struct task *t)
|
||||
/* returns true if the current thread has some work to do */
|
||||
static inline int thread_has_tasks(void)
|
||||
{
|
||||
return (!!(global_tasks_mask & tid_bit) |
|
||||
!eb_is_empty(&th_ctx->rqueue) |
|
||||
!!th_ctx->tl_class_mask |
|
||||
!MT_LIST_ISEMPTY(&th_ctx->shared_tasklet_list));
|
||||
return ((int)!!(global_tasks_mask & tid_bit) |
|
||||
(int)!eb_is_empty(&th_ctx->rqueue) |
|
||||
(int)!!th_ctx->tl_class_mask |
|
||||
(int)!MT_LIST_ISEMPTY(&th_ctx->shared_tasklet_list));
|
||||
}
|
||||
|
||||
/* puts the task <t> in run queue with reason flags <f>, and returns <t> */
|
||||
|
Loading…
Reference in New Issue
Block a user