<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - compile-time crash with target enter data on a global struct"
   href="https://bugs.llvm.org/show_bug.cgi?id=48174">48174</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>compile-time crash with target enter data on a global struct
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>OpenMP
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Clang Compiler Support
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>bertoni@anl.gov
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>We see a compile-time error with the code below. It looks like it’s an issue
with `target enter data` on part of a global struct. If we make “objects” a
local variable in main instead of a global one, then this compiles without any
problems. This is from John Tramm at Argonne National Lab.


```
<span class="quote">> cat main.cpp </span >
#include <stdio.h>
#include <stdlib.h>

#pragma omp declare target
typedef struct{
  int * arr;
} MyObject;

MyObject * objects;
#pragma omp end declare target

int main(void)
{
  // if objects is declared here instead, this code compiles
  // MyObject * objects;

  // Allocate and initialize host array
  objects = (MyObject *) malloc(sizeof(MyObject));
  objects[0].arr = (int *) malloc(sizeof(int));
  objects[0].arr[0] = 1024;

#pragma omp target enter data map(to: objects[0:1])
#pragma omp target enter data map(to: objects[0].arr[0:1])

  return 0;
}

<span class="quote">> clang++ -fopenmp -fopenmp-targets=nvptx64 main.cpp</span >
PLEASE submit a bug report to <a href="https://bugs.llvm.org/">https://bugs.llvm.org/</a> and include the crash
backtrace, preprocessed source, and associated run script.
Stack dump:
0.      Program arguments: /soft/compilers/llvm/master-20201029/bin/clang-12
-cc1 -triple x86_64-unknown-linux-gnu -emit-llvm-bc -emit-llvm-uselists
-disable-free -main-file-name main.cpp -mrelocation-model static
-mframe-pointer=all -fmath-errno -fno-\
rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64
-tune-cpu generic -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir
/soft/compilers/llvm/master-20201029/lib/clang/12.0.0 -c-isystem
/soft/compilers/cuda/cuda-10.0.130/in\
...
...
<span class="quote">> clang++ --version</span >
clang version 12.0.0
(/gpfs/jlse-fs0/users/yeluo/opt/llvm-clang/llvm-project/clang
15a68fed111f67293f56e47904dc82d661c9e4d8)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /soft/compilers/llvm/master-latest/bin
```</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>