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

    <tr>
        <th>Summary</th>
        <td>
            [clang][openmp] declare target + threadprivate crashes compiler
        </td>
    </tr>

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

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

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

<pre>
    I stumbled upon this while trying to understand threadprivate and implementing some checks for the flang compiler. The reproducer for the crash:
```
void foo(int);
int x;

#pragma omp declare target(x)
#pragma omp threadprivate(x)

int main() {
    #pragma omp parallel
    {
        foo(x);
    }
}
```
```
$ clang -S -emit-llvm -O3 sample.cpp
```
Expected behavior:
An valid semantic error is reported if the order of threadprivate and declare target is reversed. This is the expected behavior.
```
sample.cpp:3:5: error: threadprivate variables cannot be used in target constructs
    3 | int x;
      |     ^
sample.cpp:5:27: note: defined as threadprivate or thread local
    5 | #pragma omp threadprivate(x)
      | ^
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMVMGy4ioQ_Rqy6dJKIBhdZKHPa9VbzWLmBwh0EmYIUEAc799PER2vWi7GsgI03fTp06daxKgHi9gSfiD8WIg5jS60cQxCf8ax6Jz6bP-HmOapM6hg9s5CGnWE36M2CCl8ajtAcjBbhSEmYRWkMaBQPuizSAjZoidvcEKbsnN0E4IcUf6K0LsAaUTojbADSDd5bTCs4ceIENAHp2aJ4e4mg4gjYXtSHkm5J5vy9l-OZ6cV9M4RutU2Eboj7HC90TbB5X66fSnzQQyTADd5UCiNCAhJhAETodtLjn_j-FTbs9891SS0JXRL6A5Ic0sKAPD8khdBGIPm4f7ROf-uxVweS7n6HW8p75tnJl6PtAa5ELz6DiucdFoZc55g9Y1BFLk1a-n929CPi0eZUEGHozhrF-7k7y2chdEKIk7CJi0BQ3ABdMyNcyEH6X7pmgsKA7j-jTCeeb8GnzFEVFkDOmZLfgJfcazfwn2ohu0ZYXtO2P4KLG-e859F0KIzGEEKa12CDmGOGbb9i0c6G1OYZYpf7DMgzX_wLKlru7J9WfnHGzgZCm0yDOsS5lVhry0qEPEF2aL2bADjpHhQCF9y_Ksiv1DdEd35KlTL1I7tRIFttdntyqZivCzGFpuu31R021AmBN3yumPYlxVvaCW7boOFbmlJWVWVdVlXnJfrTV9zXu3qHquOcdySusRJaLPOIlu7MBQ6xhnbpqJNVRjRoYnLvKF0USVhe-fRTp5QmmdQaHPgqpuHSOrS6Jji11NJJ7NMq2soPxJ-uEXz46ucCD28MLsMkNzx26Qp5mDaMSUfs7DpidDToNM4d2vpJkJPOe9tWfngfqJMhJ6WeiKhp6WkPwEAAP__5XuelA">