llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

Add a way to avoid calls to noreturn functions from being merged

Open jrmuizel opened this issue 7 years ago • 6 comments

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()

jrmuizel avatar Jul 26 '19 17:07 jrmuizel

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

ZequanWu avatar Jun 09 '20 21:06 ZequanWu

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.

rnk avatar Apr 06 '20 20:04 rnk

It seems to be here: https://cs.chromium.org/chromium/src/base/immediate_crash.h?l=10&rcl=92d78c90964200453b80fe098b367e0838681d09

jrmuizel avatar Jul 26 '19 21:07 jrmuizel

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?

jrmuizel avatar Jul 26 '19 21:07 jrmuizel

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.

rnk avatar Jul 26 '19 21:07 rnk

assigned to @ZequanWu

jrmuizel avatar Jul 26 '19 17:07 jrmuizel