在 2024-04-10 17:19, Xi Ruoyao via Gcc-help 写道:
$ cc t.c -O2 -fsanitize=undefined $ ./a.out t.c:7:15: runtime error: signed integer overflow: 65535 * 65535 cannot be represented in type 'int' fffe0001
Undefined behavior is not a valid point, as it never happens. It's a real bug. There are many PRs on bugzilla.
The sign extension could have been eliminated completely: movzx eax, si movzx edi, di imul eax, edi ret And here is a similar issue: typedef unsigned long long int u64; typedef unsigned int u32; u64 foo(u64 a) { return (u32) __builtin_ctzll(a); } which results in xor eax, eax rep bsf rax, rdi // effectively `tzcnt rax, rdi` cdqe // unnecessary sign-extension ret -- Best regards, LIU Hao
Attachment:
OpenPGP_signature.asc
Description: OpenPGP digital signature