-
Notifications
You must be signed in to change notification settings - Fork 11.6k
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
Optimizer bitshift bug for ARM v7 #44092
Comments
Hi Brian, I tried reproducing with this command: I do get the correct result for both functions: test_set_unop: |
It reproduces for me using this exact command line: clang -target armv7-none-linux-androideabi19 -fdata-sections -ffunction-sections -fstack-protector-strong -funwind-tables -no-canonical-prefixes --sysroot C:/Users/Work/AppData/Local/Android/Sdk/ndk/20.0.5594570/build//../toolchains/llvm/prebuilt/windows-x86_64/sysroot -g -Wno-invalid-command-line-argument -Wno-unused-command-line-argument -fno-addrsig -fpic -march=armv7-a -DNDEBUG -mfpu=neon -S -DANDROID -fvisibility=hidden -DLLONG_MAX -DUSHRT_MAX=65535 -isystem /usr/include -DHAVE_STDINT_H -DHAVE_UINT64_T -DXP_UNIX -nostdinc++ -Wa,--noexecstack -Wformat -Werror=format-security -O3 -c android.c And running clang -v gives me the following output: Android (5220042 based on r346389c) clang version 8.0.7 (https://android.googlesource.com/toolchain/clang b55f2d4ebfd35bf643d27dbca1bb228957008617) (https://android.googlesource.com/toolchain/llvm 3c393fe7a7e13b0fba4ac75a01aa683d7a5b11cd) (based on LLVM 8.0.7svn) If I run using your command line, I still get the incorrect output as follows (I notice some shift differences in the unoptimized version here as well, but I'm not very well versed in ARM assembly and couldn't say if they are an issue): Command line: clang --target=arm-linux-androideabi -O3 -S -o - -x c - < android.c Assembly: test_set_optimized: |
Hi Brian, I figured out that the actual llvm commit was:
Indeed I confirm that in this version it existed such bug. But it is not present in clang 9.0 or in trunk. Cheers |
Closing based on comment 3. (There's a separate bugtracker for the Android ndk at https://github.com/android/ndk/issues, if you want to report an issue specifically with that version of clang.) |
Extended Description
During our work with the pixman graphics library, we've discovered an optimizer bug that results in incorrect bit shift math. There are no compile time errors, but the output result is completely incorrect at runtime.
My development environment is using Windows 10, Android Studio v3.5.3, Android NDK v20.0.5594570, with Clang v8.0.7. This bug appears to only happen when targeting armeabi-v7a for 32-bit Android with -O1 or higher, and not for arm64-v8a or any x86 variant.
I've attached an Android Studio sample project demonstrating the error, as well as screenshots shots showing the invalid math calculation. Looking at android.c, lines 8 and 10 cause the issue, where lines 17 and 19 do not (since they are not optimized due to the optnone attribute). The data ends up in the wrong byte position.
After looking through the generated assembly, it appears to be generating an orr instruction with an incorrect shift value. I've attached a short review showing some of the assembly differences between optimized and unoptimized versions.
The text was updated successfully, but these errors were encountered: