82 lines · plain
1.. _omp113:2 3Could not move globalized variable to the stack. Variable is potentially captured in call. Mark parameter as `__attribute__((noescape))` to override. [OMP113]4==============================================================================================================================================================5 6This missed remark indicates that a globalized value could not be moved to the7stack because it is potentially captured by a call to a function we cannot8analyze. In order for a globalized variable to be moved to the stack, copies to9its pointer cannot be stored. Otherwise it is considered captured and could10potentially be shared between the threads. This can be overridden using a11parameter level attribute as suggested in the remark text.12 13Globalization will occur when a pointer to a thread-local variable escapes the14current scope. In most cases it can be determined that the variable cannot be15shared if a copy of its pointer is never made. However, this remark indicates a16copy of the pointer is present or that sharing is possible because it is used17outside the current translation unit.18 19Examples20--------21 22If a pointer to a thread-local variable is passed to a function not visible in23the current translation unit we need to assume a copy is made of it that can be24shared between the threads. This prevents :ref:`OMP110 <omp110>` from25triggering, which will result in a performance penalty when executing on the26target device.27 28.. code-block:: c++29 30 extern void use(int *x);31 32 void foo() {33 int x;34 use(&x);35 }36 37 int main() {38 #pragma omp target parallel39 foo();40 }41 42.. code-block:: console43 44 $ clang++ -fopenmp -fopenmp-targets=nvptx64 -O2 -Rpass-missed=openmp-opt omp113.cpp45 missed.cpp:4:7: remark: Could not move globalized variable to the stack. Variable is46 potentially captured in call. Mark parameter as `__attribute__((noescape))` to47 override. [OMP113]48 int x;49 ^50 51As the remark suggests, this behaviour can be overridden using the ``noescape``52attribute. This tells the compiler that no reference to the object the pointer53points to that is derived from the parameter value will survive after the54function returns. The user is responsible for verifying that this assertion is55correct.56 57.. code-block:: c++58 59 extern void use(__attribute__((noescape)) int *x);60 61 void foo() {62 int x;63 use(&x);64 }65 66 int main() {67 #pragma omp target parallel68 foo();69 }70 71.. code-block:: console72 73 $ clang++ -fopenmp -fopenmp-targets=nvptx64 -O2 -Rpass=openmp-opt omp113.cpp74 missed.cpp:4:7: remark: Moving globalized variable to the stack. [OMP110]75 int x;76 ^77 78Diagnostic Scope79----------------80 81OpenMP target offloading missed remark.82