-
Notifications
You must be signed in to change notification settings - Fork 258
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
[BUG] Invalid ARMv7 assembly generated by clang r19b with optimizations (-Os) enabled #914
Comments
I've managed to get a somewhat reasonably sized repro case, although it's still a bit large at 135 lines of code. It might still be able to be trimmed down further, so I'll try again tomorrow. Here's a link to the repo: https://github.com/Falken42/ndk-r19b-armv7-asm-repro Running
Trimming the code down resulted in a different offset (4048 here, compared to 4016 earlier), which occurred while removing member variables in the Array template class. While integrating the repro case with ndk-build, I remembered the earlier discussions from #579 and #573 and on a whim decided to try building with |
It also works if you remove |
Here's a more minified version: https://gist.github.com/jmgao/c7d5c8d2c582eb6acb4a2cbf23861324 |
There's some weirdness going on (obviously...):
It seems like we're just horribly miscompiling atomics in structs??? This code seems to turn into this assembly, which seems to be using an obviously wrong offset for the atomic. This seems to only happen with the NDK clang? r346389c and r349610 from the platform seems less broken. |
@rprichard found https://reviews.llvm.org/D51678. Atomic loads of variables on your local stack frame when using thumb have apparently been broken in clang for a pretty long time, and was only somewhat recently fixed. As a workaround, try specifying |
Good find. The master branch (r20) already has a Clang newer than that patch and the problem doesn't repro with that Clang. |
Big thanks for minifying the repro case down even further and finding the source of the bug! It appears that as long as the atomic is the first member in a struct, the correct assembly is generated without any need for an immediate offset:
I've added a quick patch to our codebase that moves the atomic to the base of the Thanks once again! |
Description
After changing some code in our cross-platform engine which makes use of atomics, our Android builds began failing. Here's the full compile command line and output from clang:
The assembly at the line causing the error is:
We were originally using r16b, so this seemed like a good time to update to r19b, unfortunately it still resulted in this exact same error. I haven't changed or updated any of the command line parameters yet, so some things might be outdated or unnecessary.
Trying without
-fno-integrated-as
results in mostly the same error:A build pass without optimizations (
-O0
) compiles fine without problems.I'm currently going through and trimming down a 2.2MB preprocessed source file to provide a repro case, and will comment again once I have something more.
Environment Details
Not all of these will be relevant to every bug, but please provide as much
information as you can.
The text was updated successfully, but these errors were encountered: