llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

ACLE and UBSan disagree about clz with input zero

Open tommat01 opened this issue 3 years ago • 4 comments

D152023 made calls to __builtin_clz and __builtin_ctz with input 0 to be undefined behaviour (RFC here). However we use them in the arm-acle.h to implement __clz:

https://github.com/llvm/llvm-project/blob/c91246b71eec9fc1d4454ddcdc574733a699e190/clang/lib/Headers/arm_acle.h#L143

The ACLE documentation for __clz states:

When x is zero it returns the argument width, i.e. 32 or 64.

The definitions in the header will need to be updated to handle the zero case.

tommat01 avatar Jun 05 '23 11:06 tommat01

@llvm/issue-subscribers-backend-aarch64

llvmbot avatar Jun 05 '23 11:06 llvmbot

@llvm/issue-subscribers-backend-arm

llvmbot avatar Jun 05 '23 11:06 llvmbot

I broke this so I'll fix it.

topperc avatar Jul 10 '23 22:07 topperc

Its look gcc might have the same bug https://godbolt.org/z/YxKab9cMG ? The code appears to instrumented with a zero check.

topperc avatar Jul 11 '23 03:07 topperc