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

    <tr>
        <th>Summary</th>
        <td>
            [clang][OpenMP] omp scan code gen does not initialize allocas
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang
      </td>
    </tr>

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

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

<pre>
    We stumbled over an issue in the code gen for `omp scan`. For a simple example like the following, the "inscan variable" is not properly initialized.

```
int curr_scan = 0;
#pragma omp parallel shared(thread_data, scan, curr_scan)
{
    int n = omp_get_num_threads();
    #pragma omp for reduction(inscan, + : curr_scan)
    for (int i = 0; i < n; ++i) {
        scan[i] = curr_scan;
        #pragma omp scan exclusive(curr_scan)
 curr_scan += thread_data[i];
    }
}
```

For a properly initialized `thread_data`, `scan` is filled up with random data. 
Looking at the generated IR shows that there are a few basic blocks in the outlined function that are unreachable, which seems suspicious.

Full example w: https://godbolt.org/z/rna6K8T6Y
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJxsVF2P6jYQ_TXmZXRRmJAQHvKwLIpUtVWrqlLVJ-TEQzJdx478sdx7f31lh7u7XC2C2MDMOTPHxyO959EQtaI6ieq8kTFM1rVnNuyDs5veqm_tPwQ-xLnXpMC-kgNpgL2PBGwgTASDVQQjGbhaB6Iu7LyAH6QRdbGFzjqQ4HleNAF9lXnV_EI59Wq1tjc2o8Dn_INAZJOS4VU6lr0mgQjswdgAi7MLOf0N2HBgqfk7qa0ozqJ4uj_r4v7OX9kEGKJzlwwoyjMUojzdQ7FcnBxnCancRTqpNWnwk3SkBDZhciTVRckgU225H3x-hxN4vAMd7ogAAIlxZbLzchkpXEycLyuWF9ikrPJD_GMVST9HKg6BrRHYrEokWoEnEOXTJ_QJJeuewgPwW5t5-wwmbQWeBJ5Y4BEeyk2vjFadWFTnnPtOUf4U-Vhs1pS-Djp6fiWBzSe1fRAfTwn8o6or56Mch_MPUc-fnuj6XD31mRuS_T5y1EVWry7ufkxOurJOVo4L3DhM4KRRdoYUvoUV_zdrX9iMIEP25EiGnAyk4Je_wE_25iFM63-OQKYPXOkGvfQ8QK_t8OJ_3A0bg2ZDCq7R5GNdU1NSNI7kMK0ef4bbxMMEnmj24KNfeGAb_YO9u6j12x26JT9MISxelE8CO4HdaFVvddhaNwrsvgvsnJH1r83f9b8b1ZbqWB7lhtrdYYe7cn844mZqq6qhUlZ1tacSd6h2NQ6yULTf9T0Wx2rDLRa4L_ZFWTTVscKtPJSojleU1bWsmsNV7AuaJeut1q9z4t7k6dA2h31db7TsSfs8YBAHLdNVxzRrXJviv_Rx9GJfaPbBvyMEDjpPpTWjOovq9MdC5vc_k03f7Pc2eZSldUS8ewGk1naQfhOdbn_SicMU--1gZ4Fd4rwvXxZn_6MhCOxyC15gl7v4PwAA__-YupuL">