Add a way to avoid calls to noreturn functions from being merged
| Bugzilla Link | 42783 |
| Resolution | FIXED |
| Resolved on | Jun 09, 2020 14:26 |
| Version | unspecified |
| OS | All |
| CC | @DougGregor,@zygoloid,@rnk |
Extended Description
Given the following code it would be nice if there was a way to ensure that each of the callsites to crash() remained unique so that it's possible to distinguish which callsite is triggering a particular crash().
void crash() attribute((noreturn));
void f(int i) { if (i == 5) { crash(); } else if (i == 7) { crash(); } crash(); }
Today this just gets compiled to:
f(int): # @f(int) pushq %rax callq crash()
A new attribute called "nomerge" has been introduced to prevent callsites merging.
You can read more about it on https://clang.llvm.org/docs/AttributeReference.html#nomerge
I remembered this feature request the other day in the context of SEH.
I also know that instrumentation passes such as ASan have to work around LLVM's tail merging here: https://github.com/llvm/llvm-project/blob/427c1dc4f4248ec71e32a8f3832a4e6258446672/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp#L1632-L1635
That seems like a pretty solid in-tree motivation for adding an attribute to let the user adjust this behavior.
I think this could make a good beginner project, so I will assign this bug to Zequan.
It seems to be here: https://cs.chromium.org/chromium/src/base/immediate_crash.h?l=10&rcl=92d78c90964200453b80fe098b367e0838681d09
A similar feature has been requested in Chromium for some time, and might already be in the tracker. Today, the code pattern Chromium uses happens to defeat most tail merging, but it is fragile, and could benefit from this feature.
Can you give a link to Chromium's current solution?
A similar feature has been requested in Chromium for some time, and might already be in the tracker. Today, the code pattern Chromium uses happens to defeat most tail merging, but it is fragile, and could benefit from this feature.
assigned to @ZequanWu