-
Notifications
You must be signed in to change notification settings - Fork 12.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
[x86] Clang >= 13 strips optimises function to completely empty label, and allows fallthrough, in generated Assembly #60637
Comments
@llvm/issue-subscribers-clang-codegen |
@llvm/issue-subscribers-c-1 |
See relevant issues: #60622 and #60588 and #48943 (comment) This feels like a duplicate. |
IMO, we should never optimize code such that it results in execution flowing off the end of a function unless someone has concrete performance numbers justifying the shocking behaviors that come out of the optimization. It may be a legal transformation thanks to UB, but it also breaks expectations that are not entirely unreasonable. |
There are two questions here. Is this allowed: Yes. Should we do this: Probably not, I will note that in #48943 (comment) there was a proposal to turn this into |
Given the following (arguably sketchy, because it violates (AFAIK) the "forward progress" assumption) example code:
Clang 13, 14, and 15 are all affected. It seems G++ versions don't "see through" this optimisation "opportunity", even at
-O3
keeping the infinite loop.At optimisation levels
-O1
and higher, the resulting generated Assembly body formain
is completely empty. The label itself is kept, allowing execution to flow immediately to whatever instruction happens to be following the label. It might even be an invalid instruction or an invalid state (such as the body of a function expecting parameters on the stack while an emptied parameter-less function was called).This is problematic because a dangling label remains in the object file whose contents are poorly controlled. Perhaps Clang should, instead, when realising that a function's body is completely emptied, omit even the label (and thus catch such "sketchy codes" with a potential linker error) or leave an instruction in the body that kills the program when reached?
The text was updated successfully, but these errors were encountered: