https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101167

            Bug ID: 101167
           Summary: Miscompilation of task_reduction
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: jakub at gcc dot gnu.org
          Reporter: jakub at gcc dot gnu.org
  Target Milestone: ---

struct S { int a, b, c[2]; };

void
init (struct S *x)
{
  x->a = 0;
  x->b = 0;
  x->c[0] = 0;
  x->c[1] = 0;
}

void
merge (struct S *x, struct S *y)
{
  x->a += y->a;
  x->b += y->b;
}

#pragma omp declare reduction (+: struct S : merge (&omp_out, &omp_in))
initializer (init (&omp_priv))

void
foo (struct S x)
{
  #pragma omp taskgroup task_reduction (+: x)
  {
    #pragma omp task in_reduction (+: x)
    {
      x.a++;
      x.b++;
    }
    #pragma omp task in_reduction (+: x)
    {
      x.a += 4;
      x.b += 14;
    }
    #pragma omp task in_reduction (+: x)
    {
      x.a += 9;
      x.b += 19;
    }
  }
  if (x.a != 56 || x.b != 86)
    __builtin_abort ();
}

int
main ()
{
  struct S x = { 42, 52 };
  #pragma omp parallel master
  foo (x);
  return 0;
}

is miscompiled, merge is called with the same argument twice instead of merging
from the task privatized variable(s) into the PARM_DECL.

Reply via email to