You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am referring to functions setchkundefinedflags and setchk2undefinedflags in newcpu_common.cpp.
Inside both functions, multiple subtractions are performed such as this one:
if (val > lower && upper - val >= 0)
When running real test cases (e.g., the ones created by cputester), integer underflows may occur which is undefined behavior in C. This is not a problem for MSVC (I think), but it is in clang.
I’ve noticed the issue after porting this code to vAmiga and running cputester. The result was:
Tests CHK and CHK2 pass when compiled with clang and -O0
Tests CHK and CHK2 fail when compiled with clang and -O3
Thing is that clang sometimes uses aggressive optimizations that exploit undefined behavior.
In my code, I’ve fixed the issue by replacing the line above by
As stated above, I think it’s not an issue with MSVC, but if you wish to make your code more robust, you might want to change the troublesome lines by something like:
if (… && (uae_s32)((uae_s64)upper - (uae_s64)val) >= 0)
The text was updated successfully, but these errors were encountered:
Hi Toni,
I am referring to functions
setchkundefinedflags
andsetchk2undefinedflags
innewcpu_common.cpp
.Inside both functions, multiple subtractions are performed such as this one:
When running real test cases (e.g., the ones created by
cputester
), integer underflows may occur which is undefined behavior in C. This is not a problem for MSVC (I think), but it is in clang.I’ve noticed the issue after porting this code to vAmiga and running
cputester
. The result was:-O0
-O3
Thing is that clang sometimes uses aggressive optimizations that exploit undefined behavior.
In my code, I’ve fixed the issue by replacing the line above by
where diff is defined as
As stated above, I think it’s not an issue with MSVC, but if you wish to make your code more robust, you might want to change the troublesome lines by something like:
The text was updated successfully, but these errors were encountered: