<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/61034>61034</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[OpenMP] first private target mapping order can change and cause invalid results
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
jdoerfert
</td>
</tr>
</table>
<pre>
I was looking into a different alignment issue and discovered this.
The result should be 16,16 both times, however for the non-aligned test case y is not aligned properly and we get wrong values:
```
Test aligned firstprivate
rx:16, ry:16
rx:16, ry:16
Test non-aligned firstprivate
rx:16, ry:16
rx:16, ry:1048576
```
```
#include <stdio.h>
template <bool Aligned> void test() {
printf("Test %saligned firstprivate\n", Aligned ? "" : "non-");
char z1[3 + Aligned], z2[3 + Aligned];
int x[4];
int y[4];
y[0] = y[1] = y[2] = y[3] = 4;
x[0] = x[1] = x[2] = x[3] = 4;
int rx = -1, ry = -1;
#pragma omp target firstprivate(z1, y, z2) map(from : ry, rx) map(to : x)
{
ry = (y[0] + y[1] + y[2] + y[3]);
rx = (x[0] + x[1] + x[2] + x[3]);
}
printf(" rx:%i, ry:%i\n", rx, ry);
#pragma omp target firstprivate(z1, y, z2) map(from : ry, rx) map(to : x)
{
z1[2] += 5;
ry = (y[0] + y[1] + y[2] + y[3]);
rx = (x[0] + x[1] + x[2] + x[3]);
z2[2] += 7;
}
printf(" rx:%i, ry:%i\n", rx, ry);
}
int main() {
test<true>();
test<false>();
}
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMVc2uqzYQfhqzGZ0IxvwkCxYnyY3URdUu-gIOGPCtsZFtEnKevrKBE05v2k0rtVJEmBnm45tvBg-zVrSK85JkR5KdIza6Tpvye625abhx0VXXj_InuDMLUuvfhWpBKKeBQS2ahhuuHDApWtX7O2HtyIGpGmphK33jhtfgOmF3JD6T-P23joPhdpQObKdHWcOVQ5IT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