Repository navigation
Resolve MSVC C4146 Warning in php_random_uint128.h - #19342
KaseyJenkins wants to merge 1 commit into
Conversation
|
Thank you, @TimWolla! Have I understood it correctly that the decision has been made and cannot be reversed? :)
The reasoning behind this particular change in this public header is that building a PHP extension with MSVC gives out this warning and usually requires additional measures to circumvent it (e.g. patching this particular file with |
No. It's certainly not up to me (or any other individual) to make final decisions regarding php-src. So this is up for debate. However, AFAIK this is well-defined behavior, so I don't understand why MSVC raises a warning (level 2, with |
|
Thank you @cmb69 for your reply! In terms of compiler optimization issues it's rather interesting that uint32_t s = 1;
uint32_t t = -s;
uint32_t u = ~s + 1;
main:
pushq %rbp
movq %rsp, %rbp
movl $1, -4(%rbp)
# uint32_t t = -s;
movl -4(%rbp), %eax
negl %eax
movl %eax, -8(%rbp)
# uint32_t u = ~s + 1;
movl -4(%rbp), %eax
negl %eax
movl %eax, -12(%rbp)
movl $0, %eax
popq %rbp
ret
s$ = 0
t$ = 4
u$ = 8
main PROC
$LN3:
sub rsp, 24
mov DWORD PTR s$[rsp], 1
# uint32_t t = -s;
mov eax, DWORD PTR s$[rsp]
neg eax
mov DWORD PTR t$[rsp], eax
# uint32_t u = ~s + 1;
mov eax, DWORD PTR s$[rsp]
not eax
inc eax
mov DWORD PTR u$[rsp], eax
xor eax, eax
add rsp, 24
ret 0
main ENDP |
The following code in
php_random_uint128.hgives out MSVC's C4146 warning (unary minus operator applied to unsigned type, result still unsigned):This PR resolves it with substituting
(-s)with(~s + 1)