<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/154830>154830</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Improve ASan & HWASan handling of pre-split coroutines to disable stack UAR instrumentation
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            compiler-rt:asan,
            compiler-rt:hwasan
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          rnk
      </td>
    </tr>
</table>

<pre>
    ASan & HWASan instrumentation passes both contain logic to move all static allocas over to a dynamically allocated stack frame which can be used to support stack use-after-return detection. In the entry block, it introduces a runtime check if/else pattern to select between dynamically allocated stack memory and heap allocated memory when UAR detection is enabled.

This conflicts with the CoroSplit pass logic, which emits a fatal error for dynamic allocas, which would have to be heap allocated (i.e. rewrite to malloc) to live across suspend points.

There's something obvious here: The passes are both fundamentally doing the same thing. They are moving all stack allocations to the heap.

Normally the pass sequence is corosplit, then sanitizer instruentation. However, to be resilient to odd pass reorderings, it would be better if sanitizer passes simply didn't do UAR detection on pre-split coroutines. This eliminates the pass ordering requirement completely.

Right now, ASan is blind to bugs in coroutine functions in LTO configurations, because we just skip instrumenting pre-split coroutines. Fixing this would improve its defect detection capability.

References:
* https://github.com/llvm/llvm-project/pull/154803
* https://github.com/llvm/llvm-project/pull/99415
* https://github.com/llvm/llvm-project/commit/aa0776de464984e78ae1cc329bf541e9dd43631f

cc @thurstond @vitalybuka 

One thing I'm not clear on is whether we can retain redzone poisoning in all coro / sanitizer pass sequencings.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJykVd-P2zYM_mucF-ICR7Yvl4c83FoELTCsQNthz7JEx2xkyRXpZOlfP9BxesWtGLDtyRb4Q-TH76MsMx0j4r5ofimatys7SZ_yPsfTqk3-un_-ZCMU5hHe_TH_UmTJ04BRrFCKMFpmZGiT9OBSFEsRQjqSA0kwpDO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