-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Fix clang 13 induced runtime issues #62170
Conversation
The clang 13 optimizer started to assume that "this" pointer is always properly aligned. That lead to elimination of some code that was actually needed. It also takes pointer aliasing rules more strictly in one place in jit. That caused the optimizer to falsely assume that a callee with an argument passed by reference is not modifying that argument and used a stale copy of the original value at the caller site. This change fixes both of the issues. With this fix, runtime compiled using clang 13 seems to be fully functional.
I was able to do a full bootstrap with this. Thanks! |
This is part of the C++ language standard, so if clang can't assume that "this" pointer is already aligned, then it means there is bug somewhere else in the program. Just changing the function signature so the alignment information about the pointer is lost may fix the test failure, but I don't think it's solving the underlying problem.
Do you have more information about this? It sounds like it could be a clang bug. |
The difference in this changeset is that we align a void* before casting it to the type with the required alignment. Previously, it was casted and then a member function aligned it.
Let me preface this by saying I believe Clang is in its right to do the optimization it is doing here, and that it is related to strict aliasing (it is fixed with -fno-strict-aliasing). The best reduced example I could come up with is the following: With strict aliasing on, Clang13 is compiling ShortLongRep val = mJumpDestOut[block->bbNum];
DataFlowD(len, mJumpDestOut[block->bbNum], mJumpDestGen[block->bbNum], block->bbAssertionIn);
bool changed = AreDifferent(len, preMergeOut, block->bbAssertionOut, preMergeJumpDestOut, val);
return changed; Note that the second arg to EDIT: It's easier to see if the loop is commented in |
@jakobbotsch thank you for providing the details. |
@janvorli OK, thanks for the explanation, that makes sense. |
@janvorli Do you have any plans to backport this fix to older release branches? We saw this issue first in 6.0, but even 3.1 and 5.0 would be affected, right? |
Right, it makes sense to port it. We will also need to port the change that disables the new warnings coming from clang 13. |
Hey, @janvorli is there a PR for the backport I can follow? Shall I create one? There are requests (eg, dotnet/source-build#2645) for getting this into 6.0.2, if possible. |
…g_dotnetruntime.sh 2. Add the patch dotnet/runtime#62170 into dotnetruntime package to fix SOS exception
@omajid I am sorry for a late response, I was OOF since December 15. I will create a backporting PR. It will need to be combined with a part of another PR that added some compiler warning disabling options for Clang 13. |
The clang 13 optimizer started to assume that "this" pointer is always properly aligned. That lead to elimination of some code that was actually needed. It also takes pointer aliasing rules more strictly in one place in jit. That caused the optimizer to falsely assume that a callee with an argument passed by reference is not modifying that argument and used a stale copy of the original value at the caller site. This change fixes both of the issues. With this fix, runtime compiled using clang 13 seems to be fully functional.
Hey, @janvorli ! No worries, hope you had a great time off! I was off myself. Thanks for doing the 6.0 PR. |
* Fix clang 13 induced runtime issues (#62170) The clang 13 optimizer started to assume that "this" pointer is always properly aligned. That lead to elimination of some code that was actually needed. It also takes pointer aliasing rules more strictly in one place in jit. That caused the optimizer to falsely assume that a callee with an argument passed by reference is not modifying that argument and used a stale copy of the original value at the caller site. This change fixes both of the issues. With this fix, runtime compiled using clang 13 seems to be fully functional. * Fix build with clang 13 (#60328)
The clang 13 optimizer started to assume that "this" pointer is always
properly aligned. That lead to elimination of some code that was actually
needed.
It also takes pointer aliasing rules more strictly in one place in jit.
That caused the optimizer to falsely assume that a callee with an argument
passed by reference is not modifying that argument and used a stale
copy of the original value at the caller site.
This change fixes both of the issues. With this fix, runtime compiled
using clang 13 seems to be fully functional.
Close #61671