[UBSan] Consider zero input to __builtin_clz/ctz to be undefined independent of the...
authorCraig Topper <craig.topper@sifive.com>
Fri, 2 Jun 2023 19:51:42 +0000 (12:51 -0700)
committerCraig Topper <craig.topper@sifive.com>
Fri, 2 Jun 2023 20:01:05 +0000 (13:01 -0700)
commit18ccca4da8dec5fbfd1072a1c1544ce25f528627
tree6c0c66dc166bf7b60903ec124f2ea331be939da8
parent2831a271c8beee7bc0a5b8ea1421de606358207b
[UBSan] Consider zero input to __builtin_clz/ctz to be undefined independent of the target.

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

Reviewed By: nikic

Differential Revision: https://reviews.llvm.org/D152023
clang/lib/CodeGen/CGBuiltin.cpp
clang/test/CodeGen/ubsan-builtin-checks.c