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

            Bug ID: 105015
           Summary: [OpenMP] wrong results with target link with multiple
                    translation units
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Keywords: missed-optimization, openmp
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: burnus at gcc dot gnu.org
                CC: jakub at gcc dot gnu.org
  Target Milestone: ---

Contrary to PR100059 (nvptx-tools bug), this issue occurs already on the host.
Based on
https://github.com/clang-ykt/omptests/tree/master/t-same-name-definitions but
not exposed there.

Regarding the testcase (-foffload without offloading configured):

* Calling 'one_get_inc3_link_a ()' will return 123 and then increment the
value.
* Calling 'two_get_inc5_link_a ()' returns 126 and within the target region,
the value is 131 after the increment.
* However, the global variable (direct access with host fallback or via
one_get_inc3_link_a()) will still return 126.

Using Clang 11 (also no offloading), the global value is changed to 131 as
expected.

-------- File 1 ------------
int decl_a_link = 123;
#pragma omp declare target link(decl_a_link)

int
one_get_inc3_link_a ()
{
  int res;
#pragma omp target map(from: res)
  {
    res = decl_a_link;
    decl_a_link += 3;
  }
  return res;
}
-------- File 2 ------------
extern int decl_a_link;
#pragma omp declare target link(decl_a_link)
int

two_get_inc5_link_a ()
{
  int res;
#pragma omp target map(from: res)
  {
    res = decl_a_link;
    decl_a_link += 5;
  }
  return res;
}

Reply via email to