CodeGenFunction::EmitCheckedArgForBuiltin checks getTarget().isCLZForZeroUndef()
so it will only detect errors on targets where __builtin_clz/ctz aren’t defined for zero.
gcc’s documentation for these builtins says 0 is undefined.
The original commit that added isCLZForZeroUndef, Make clz/ctz builtins defined for zero on ARM targets. rdar://10732455 · llvm/llvm-project@a7a61e2 · GitHub seemed to be trying to prevent optimizations where someone assumed __builtin_clz would return 32 on Arm. This pre-dates the UBSan code.
So my question is, should UBSan detect 0 on Arm since the behavior isn’t portable?