<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/96702>96702</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Fences need to be considered as forward progress
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
neldredge
</td>
</tr>
</table>
<pre>
The C++ forward progress rules say that a program has UB unless it eventually does one of a certain list of things, one of which is "atomic operations".
By my reading, this should include fences. However, the following code:
```
#include <atomic>
void foo() {
bool b = true;
while (b) {
std::atomic_thread_fence(std::memory_order_seq_cst);
}
}
```
is compiled by `clang -O3` into `unreachable`, i.e. no code at all. https://clang.godbolt.org/z/oWPo7738x
I believe this is wrong. Even though for all practical purposes this loop is making no progress, and perhaps under the spirit of the rule it should be UB, by the letter of the rule it should be legal, and should actually execute an infinite loop.
Related is #62057, where a similar thing happens when the loop contains an atomic load with no effect.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx0VEGP4zYP_TXKhRhDkeN4cvBhM7PB951aFF30OKAl2lIri64kJ5v--kJ2ZraDokAQ2yL5-EQ-ElNyYyDqRHMWzesOl2w5doG8iWRG2vVs7t2vluBFqLNQZxg43jAamCOPkVKCuHhKkPAO2WIG3Cw4gcUE386wBF_cXAa6UsgLen8Hw5SAAwEPgKApZnQBvEu5nGTrwpiEenl3uVmnLbgEQinMPDkNPFPE7DgkoVQl5KuQX7b_8x2mO0RC48JYQLJ1CZLlxRtwQfvFEAwUNKUK4H98oyvFzY9gYO_55sIImg2J-oEpjvLx2z5V_Q4k6peNkai_bsYrOwMDs1DPQp1AtOftHACgZ_bQg6hfIceFRP0P2806TyDUc_85LGVTeNRftjxv2Za7va03EOr5wzzRxPH-xtFQfEv055tOWajTjxyifX3Q_3j5fC2XQPM0O08G-juIo9QewwhPP9XiKMGFzOVwCZFQW-w9lVD1Aq6iCgKvNYMiAu8rAJvznAo3dRHqskJVI5uefa44jkJd_hLqwr_9zG1bP3_fOPwfevKOrrS1zSW4RQ5jBV-vFCBbXkZbRFhywBxRZ6fRw7zEmROlLcozzyV0wj9KKwN_yLWwxWBgpmhxTrAEQ3HtfJpddA_50arqotmHbHqCb-cS299Xs6ecKf63s6cR_XuuxzHqh_jpO-klE2AAFwYXXKaV8ScV_0IeM5lN9PVRyaYteDdLkQAhucl5jNuogMV5ppCKNWz8SgE0hzJWqSR6TI1nNHBz2Zaa0DCQztXOdLU51SfcUbdv96e62Ut53NnucGxaddJmjwdJ-8ZoamQjTa-wPWIz9DvXKakO8qgata-lbCpl-mY_nOpG7ht6bg_iIGlC5yvvr1Pp-c6ltFB3OrZS7Tz25NO6epQKdIPVKJQqmyh2JeapX8YkDrJshvQDJbvsqbusMwyByEDmUnbNITlDkQxg-teq2i3Rd59FObpsl77SPAl1KfCPx9Mc-XfSWajLSioJddlIXzv1dwAAAP__uVWwDA">