<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=http://email.email.llvm.org/c/eJylVk1zozgQ_TX4ogoFwsbxwQfnc6Y2zqQyM5Xak0tAY7QREiUJO9lfP92COE4m2cNOihAkWt39Xr9uUpjqefnQgGZFL1Ul9Zb5BlhtlDJ7WpWmAiY16zvnLYiWlUrobZStouQiSlZRnozXsORXeLGTE2baLi6HzZ2RFSuFUhE_rUxfKGARX4mIL1g0PxtsGP5EPOus2LaCDjMv3CMG3lio-tJLo_F0xM8wMhPR7CyJZhfo4ej0savB3RleB9vsONL8Ysz38BDuUnvWCjmEepfdmLlgUXbBkjipDx4_Q9AJi6BBffbeIb8K_gv_1pp-ePqYhmP8I8ERz8P-IbkDwreVepC-YbgK5WQn3zg7qU0HGiMPpUNDfs5kzYRzYCmyY8ICAy2Qh4peklJKtJYKLKuFVI7tye1bBR3OM7DW2M-kcwGluof68qlDX8YyWjNtPAb0gOhJhDcGUdKLteii7Go4-PP2_nJ1_mV1dnPJ4AnK3qOx8EjnlTXG4x-ldu1JZ80_UNJyUDBuywLv5yjwa9D0dE3B47JD3ys-X8wjnn6Y6g_C1yvFnBflo7eiRB4EthCwnYT9EL7xvnMENrTE1lSFUT42liL_i79a_J2uH-Z318ci-vob3ZV0B76RQsHuQYFwMPTraxWwS_cSU8IcWunGqmAiuiIDHay-YX3Xd8z22st2tC-tcA3bkwnu65cBgGxtrWg_7_MpixGEiE3vh61v6zsS5SXVmKScZrRcHYpP-ugREFLz2HYbEjUGC2zzU84XOao2fuPqC7Xj3YDW9UUrPcIv-i2z0BnrX7QmHWvBObEFYmNEHoAjIFq3-OxY7wYS6UUrykZqok3XcttbETKUujZ4K1Uf5qDG3d2RwOkgdggZ41v37Dy0bAfWUa1idiVww2JursP1azVM4XGiYCmK5yPn2KwvHDNnelsCuUDmKAnbDgnhNeD2Q1kQqXSuDzi7kReAd0pDglxMih-1NnK6KpAyzALJLg3pqm87ImTx8XRoZNkgdDvAQfq8CboY1EmD46_13Wb1_fvl_Q8a68LjYMR2wdl4-_PmhvzmCbVs3eswtujIZoOVLzdv59lmC37jmw25QJv4uB1ujQcMi5J5BY93nJytVMJSUu_aDCXRFzHWbGz737s_OHH4MEunPA9V_f8-pjnPcipH0Xv2FcutJOwgMNXrCqwSz-EjKlB9lHgl6xqHmabpdFrAsL-nC0viwYVC1_IJXJiB5AeERad2AO_GhkZXBvWL9qijRnTY2I76Z1Its2qRLcRE9L4xdlmJHSzySW_V8g-YytJZOmmWCS8KKBbAM36azovZdJbni6ws8tl0ms6S-UQJZMAt8ZMbca5h_yJXjh_gyZ9nIJc84TxJU57i33Qe59NFmp6W07ycpWlSV9E0Afx-q4P-J3YZXFJT4EslnX9tjgmKWW41QEgYM_TSq7AYPoS4xdYvs3TsSJzP1opn7LtB1eG_lIOWJyHhZcj2F927-UA>53151</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [openmp] Miscompilation of array section task reduction
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

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

<pre>
    When building the following code in upstream clang:
```
// -- omp.c
void call(double *a) {
    #pragma omp task in_reduction(+: a[0])
    {
        ++a[0];
    }
}

int main() {
    double a = 0.0f;

    #pragma omp parallel
    #pragma omp single
    #pragma omp taskgroup task_reduction(+: a)
    call(&a);
}
```
With `clang -O2 -fopenmp omp.c`, if assertions are enabled, the compiler fails with the following assertion error:
```
DeclRefExpr for Decl not entered in LocalDeclMap?
UNREACHABLE executed at /root/llvm-project/clang/lib/CodeGen/CGExpr.cpp:2797!
```
The full stacktrace can be viewed at https://godbolt.org/z/naY1MW7PG

If assertions are disabled, on a Release build, the code will be miscompiled and then the OpenMP runtime will crash when running the program:
```
$ ./a.out
OMP: Error #13: Assertion failure at kmp_tasking.cpp(2296).
OMP: Hint Please submit a bug report with this message, compile and run commands used, and machine configuration info including native compiler and operating system versions. Faster response will be obtained by including all program sources. For information on submitting this issue, please see https://bugs.llvm.org/.
Aborted (core dumped)
```
Which corresponds to the assert `KMP_ASSERT(data != NULL)` in function `__kmpc_task_reduction_get_th_data`.

Note that this issue is similar to https://github.com/llvm/llvm-project/issues/51426 and https://github.com/llvm/llvm-project/issues/46236, but I believe the underlaying cause is different (because we were testing fixes for the earlier issues and this one still happens).
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJylVdtyozgQ_Rr8ogoFwtcHPzjXmdo4SWVmKrVPLgGN0UZIlC52sl-_3YAdJ5Psw26KYCRa3X1On25yU74un2rQLA9SlVJvma-BVUYps6dVYUpgUrPQOm9BNKxQQm-jbBUll1GyiqbJcPVLfo0XOztjpmnjot_cGVmyQigV8XlpQq6ARXwlIr5g0ey8t2H4F_GstWLbCDrMvHDPGHhjoQyFl0bj6YifY2Qmosl5Ek0u0cPJ6VNXvbtzvI622Wmk2eWQ7_Ghu0vtWSNkH-pDdkPmgkXZJUvipDp6_ApBKyyCBvXVe4f8Kvg3_FtrQv_0OQ2n-AeCIz7t9o_JHRG-r9ST9DXDVVdOdnbP2VllWtAYuS8dGvILJismnANLkR0TFhhogTyU9JKUUqC1VGBZJaRybE9u3yvoeJ6BtcZ-JZ1LKNQjVFcvLfoyltGaaeMxoAdETyK8NYiSXqxFG2XX_cFfd49Xq4tvq_PbKwYvUASPxsIjndfWGI8_Su2as9aav6CgZa9g3JY53i9Q4Deg6emGgsdFi75XfLaYRTz9NNWfhC8oxZwXxbO3okAeBLYQsJ2EfR--9r51BLZria0pc6N8bCxF_hv_tfgzXT_NHm5ORfT9N7pL6Y58I4WCPYIC4aDv17cqYJfuJaaEOTTSDVXBRHRJBrqzusf6rh-YDdrLZrAvrHA125MJ7uvDAEC2tlY0X_f5mMUIQsQm-H7rfv1AoryiGpOU04yWq2PxSR8BASE1z027IVFjsI5tPud8MUXVxu9cfaN2fOjRupA30iP8P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