Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Negative value is being left-shifted (undefined behavior) #7

Closed
kcgen opened this issue Mar 11, 2021 · 6 comments
Closed

Negative value is being left-shifted (undefined behavior) #7

kcgen opened this issue Mar 11, 2021 · 6 comments

Comments

@kcgen
Copy link

kcgen commented Mar 11, 2021

Flagged by GCC 10.2 when code is instrumented with UBSAN:

../../src/libs/nuked/opl3.c:478:40: runtime error: left shift of negative value -512
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ../../src/libs/nuked/opl3.c:478:40 in

2021-03-11_07-13

@Gradius2
Copy link

Please check it again with GCC 10.3.

Also, the last one is GCC 11.1 (as today).

@nukeykt
Copy link
Owner

nukeykt commented May 17, 2021

does 85d96d1 resolve this issue?

@kcgen
Copy link
Author

kcgen commented May 18, 2021

Confirmed under GCC 10.3

../../src/libs/nuked/opl3.c:478:40: runtime error: left shift of negative value -512
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ../../src/libs/nuked/opl3.c:478:40 in 
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 10.3.0-1ubuntu1' --with-bugurl=file:///usr/share/doc/gcc-10/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-10 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-10-gDeRY6/gcc-10-10.3.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-10-gDeRY6/gcc-10-10.3.0/debian/tmp-gcn/usr,hsa --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu --with-build-config=bootstrap-lto-lean --enable-link-mutex
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 10.3.0 (Ubuntu 10.3.0-1ubuntu1) 

Thanks @nukeykt - will retry w/ 85d96d1!

@kcgen
Copy link
Author

kcgen commented May 18, 2021

UBSAN is still reporting the problem with 85d96d1 applied.

../../src/libs/nuked/opl3.c:478:40: runtime error: left shift of negative value -512
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ../../src/libs/nuked/opl3.c:478:40 in 

In this line:

eg_inc = ((~slot->eg_rout) << shift) >> 4;

The (~slot->eg_rout) variable holds -512, which is then left-shifted by the shift value (whatever it might be).

@nukeykt
Copy link
Owner

nukeykt commented May 19, 2021

got rid of left shift in d9d6eea altogether

@nukeykt nukeykt closed this as completed May 19, 2021
@kcgen
Copy link
Author

kcgen commented May 19, 2021

Confirmed fixed. Tested:

  • Blues Bros
  • Kult
  • Adventures of Moktar
  • Lord of the Realm
  • Super Cauldron
  • Wolf 3D

Thank you @nukeykt!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants