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

    <tr>
        <th>Summary</th>
        <td>
            printf("") needs 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 "make a call to a library I/O function".  Certainly `printf` should qualify.  However, clang optimizes out `printf("")` and does not treat it as providing forward progress.

The following code:
```
#include <cstdio>
void foo() {
    bool b = true;
 while (b) {
        printf("");
    }
}
```
is compiled by `clang -O3` into `unreachable`, i.e. no code at all. https://clang.godbolt.org/z/6cP9vxsh7
I believe this is wrong.  By the letter of the rule it should be legal, and should actually execute an infinite loop (though it does not need to actually call `printf`, since that is indeed a no-op).

Related is #62057, where a similar thing happens when the loop contains an atomic load with no effect, and #96702, for atomic fences.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJxsVE2P4zYM_TXyhRjDkSYfPvjQTBp0T1sU7Q-QLdpmq4iuJCeb_fUF7WQ7g9nASCJRj3p8fLRNiYaA2KjtUW1PhZ3zyLEJ6F1EN2DRsrs3f44Ib0oflT5Cz_Fmo4Mp8hAxJYizxwTJ3iGPNoNdI_YCo03w1xHm4OUYZcArhjxb7-_gGBNwQOAeLHQYs6UAnlKWnTxSGJLSb88jt5G6ESiB0vpi_0HBWO8hM1jw1EYb7_BF6fNX6OfQZeKgtC4B3tbM_g5qV02RQu7VroI08uwd_DtbT_29BPiNb3jFKFd23oYBeMp0oe_Ccs7vwPqgtF6eWhLZ4NZaAmfIEW2WQm0SEa7kKAyfBCtVdVLVL-u3KNuz93yTox07VOYRUrvq8axLbSh0fnYIyrx1KTtiZX5dg1cmBz3zQq8GtT-u-wA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