craig.topper added a comment. In D151867#4401952 <https://reviews.llvm.org/D151867#4401952>, @Yunzezhu wrote:
> In D151867#4400255 <https://reviews.llvm.org/D151867#4400255>, @craig.topper > wrote: > >> From the C language perspective with this change, __builtin_clz/ctz is still >> considered undefined for 0 and code that uses it is ill-formed. >> `isCLZForZeroUndef` is only intended to prevent the middle end from >> optimizing based on the undefinedness and creating surprises. See also >> https://discourse.llvm.org/t/should-ubsan-detect-0-input-to-builtin-clz-ctz-regardless-of-target/71060 > > I see __builtin_clz/ctz returning an undefined value for 0 input matches > gcc's document, but when I test __builtin_clz/ctz with 0 input on gcc, it > returns a valid value rather than an undefined value. It looks gcc does not > follow gcc's document. I'm not sure which one is better that match document > to return undefined for 0, or match gcc's behavior to return defined value? From what I can see in the assembly here https://godbolt.org/z/s4qqz83EK, gcc's undefined behavior sanitizer does consider an input of 0 to be undefined. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D151867/new/ https://reviews.llvm.org/D151867 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits