This is an archive of the discontinued LLVM Phabricator instance.

[UBSan] Consider zero input to __builtin_clz/ctz to be undefined independent of the target.
ClosedPublic

Authored by craig.topper on Jun 2 2023, 12:25 PM.

Details

Summary

Previously we checked isCLZForZeroUndef and only added UBSan checks
if it returned true.

The builtin should be considered undefined for 0 regardless of
the target so that code using it is portable. The isCLZForZeroUndef
was only intended to disable optimizations in the middle end and
backend.

See https://discourse.llvm.org/t/should-ubsan-detect-0-input-to-builtin-clz-ctz-regardless-of-target/71060

Diff Detail