Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

undefined >>> 0 == 4294967295?

Getting different results on different machines and wonder if this is expected behaviour or a potential error in implementation of '>>>' operation for certain CPUs?

Linux qemux86-64 4.18.41-yocto-standard #1 SMP PREEMPT Tue Oct 8 20:33:31 UTC 2019 x86_64 GNU/Linux
root@qemux86-64:~# node --v8-options|head -n 1
SSE3=1 SSSE3=1 SSE4_1=0 SAHF=1 AVX=0 FMA3=0 BMI1=0 BMI2=0 LZCNT=0 POPCNT=0 ATOM=0
root@qemux86-64:~# node -v             
v8.12.0
root@qemux86-64:~# node -e 'console.log(undefined >>> 0)'
4294967295

(undefined >>> 0) evaluates to 0 on other machines I tested. But, then with CPU features enabled: AVX FMA3 BMI1 BMI2 LZCNT POPCNT

like image 868
Ess Avatar asked Oct 23 '19 06:10

Ess


People also ask

Why can’t I read properties of undefined?

You check the console and see TypeError: Cannot read properties of undefined (reading '0'). What’s going on here? Chances are you are either using an array, a string, or an object literal in your code that you’ve attempted to index using [0].

What does error code 4294967295 mean?

An error occurred while fetching the assigned iteration of the selected issue. Sometimes a build job fails randomly with the exit code 4294967295. It does not happen always, but frequently (maybe 1 out of 3 builds) It always happens at a different time during the build, which is why I provided two different build logs as an example

Why does my windows Docker job fail with exit code 4294967295?

It happened with different windows docker images (python, mcr.microsoft.com/dotnet/framework/sdk:3.5) The windows event log shows that there is a problem with the username/password used in the container The job fails with the exit code 4294967295. The build should succeed. The GitLab runner is running on a Windows VM with Docker-Desktop installed.

What is undefined behavior in C++?

According to draft N1256 (C99) §6.3.1.4, you are invoking undefined behavior: When a finite value of real floating type is converted to an integer type other than _Bool, the fractional part is discarded (i.e., the value is truncated toward zero). If the value of the integral part cannot be represented by the integer type, the behavior is undefined.


1 Answers

V8 developer here. That's clearly a bug (undefined >>> 0 is always supposed to return 0), but it's unclear where that bug might be: could be in V8, could be in the C++ compiler that was used, could be in kernel or system libraries, could even be in the hardware (or emulator? The host name "qemux86-64" sounds like it might be a virtual machine); could also be less of a bug per se and more of an unexpected interaction between any of these components. FWIW, I can't repro.

Node 8 is also fairly old, so the first thing to try would be a newer Node/V8. Maybe whatever it was has been fixed already.

If you can still reproduce with a recent version (say, Node 12 / V8 7.7 or newer), then please file a bug at crbug.com/v8/new and include instructions on how to reproduce. Feel free to leave the bug number in a comment here.

like image 57
jmrk Avatar answered Sep 19 '22 12:09

jmrk