Hi Ben,

On Wed, Aug 06, 2025 at 08:52:08PM -0400, Ben Kallus wrote:
> >From `man gcc`:
> > passing 0 as the argument to "__builtin_ctz" or
> > "__builtin_clz" invokes undefined behavior
> 
> This patch fixes an instance of this that occurs when HAProxy processes
> HTTP/1 requests, which may cause UBSan to trip. It also proactively
> fixes a second instance of this that I have not seen trip UBSan.

Thanks but that's typically code I will not change without running an
in-depth benchmark first. Tree traversal's performance highly depends
on the ability for the compiler to compute certain fields early and as
much as possible out of "if" branches so that the CPU can start to
prefetch the data needed to load the next node, and I've already
observed performance variations by more than 30% when just doing
apparently trivial changes like this.

As you've seen, here it's clear that the result is not used in that
case, which was the original purpose of undefined ops that compilers
decided to stupidly abuse and turn to "may make your house catch fire"
while originally it was simply "result depends on the architecture".

Could you please do me a favor an open an issue about this here so
that I don't forget:

   https://github.com/wtarreau/ebtree

You can attach your patch or link to this mail thread in the archives
as you prefer. Also if you can share how to build with such tests in
place so that I can also test alternate variants in case there is an
unacceptable cost, that would be great.

Thanks!
Willy


Reply via email to