<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/234164>234164</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [OpenMP] Build failure if optional OMPT support is disabled
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          Thyre
      </td>
    </tr>
</table>

<pre>
    When trying to build LLVM's OpenMP runtime with the optional OMPT support disabled, the build runs into a failure when building `kmp_barrier.cpp`. I'm using the Clang 23.1.3 provided by Arch Linux here, but assume that the same failure occurs with a trunk build.

**Build command:**
```console
$ cmake -S runtimes -B reprod -G Ninja -DLLVM_ENABLE_RUNTIMES=openmp -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_BUILD_TYPE=Release -DLIBOMP_OMPT_SUPPORT=ON -DLIBOMP_OMPT_OPTIONAL=OFF
[...]
$ ninja -C reprod omp
```

**Build failure:**
```
FAILED: [code=1] openmp/runtime/src/CMakeFiles/obj.omp.dir/kmp_barrier.cpp.o
/usr/bin/clang++ -DKMP_SPEC_DATE=201611 -DKMP_SPEC_VERSION=5.0 -D_GLIBCXX_NO_ASSERTIONS -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/jreuter/Projects/Compilers/llvm-project/reprod/openmp/runtime/src -I/home/jreuter/Projects/Compilers/llvm-project/openmp/runtime/src -I/home/jreuter/Projects/Compilers/llvm-project/openmp/runtime/src/i18n -I/home/jreuter/Projects/Compilers/llvm-project/openmp/runtime/src/include -I/home/jreuter/Projects/Compilers/llvm-project/openmp/runtime/src/thirdparty/ittnotify -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wno-pass-failed -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -Xclang -fno-pch-timestamp -Wall -fcolor-diagnostics -Wcast-qual -Wformat-pedantic -Wimplicit-fallthrough -Wsign-compare -Wno-extra -Wno-pedantic -fno-semantic-interposition -fdata-sections -O3 -DNDEBUG -std=c++17 -fPIC   -D _GNU_SOURCE -D _REENTRANT -U_GLIBCXX_ASSERTIONS -fno-exceptions -fno-rtti -Wno-covered-switch-default -Wno-frame-address -Wno-strict-aliasing -Wno-switch -Wno-uninitialized -Wno-return-type-c-linkage -Wno-cast-qual -Wno-int-to-void-pointer-cast -MD -MT openmp/runtime/src/CMakeFiles/obj.omp.dir/kmp_barrier.cpp.o -MF openmp/runtime/src/CMakeFiles/obj.omp.dir/kmp_barrier.cpp.o.d -o openmp/runtime/src/CMakeFiles/obj.omp.dir/kmp_barrier.cpp.o -c /home/jreuter/Projects/Compilers/llvm-project/openmp/runtime/src/kmp_barrier.cpp
/home/jreuter/Projects/Compilers/llvm-project/openmp/runtime/src/kmp_barrier.cpp:1863:13: error: unknown type name 'barrier_kind'; did you mean 'barrier_type'?
 1863 |     switch (barrier_kind) {
      |             ^~~~~~~~~~~~
      | barrier_type
/home/jreuter/Projects/Compilers/llvm-project/openmp/runtime/src/kmp.h:2152:6: note: 'barrier_type' declared here
 2152 | enum barrier_type {
      | ^
/home/jreuter/Projects/Compilers/llvm-project/openmp/runtime/src/kmp_barrier.cpp:1863:25: error: expected unqualified-id
 1863 |     switch (barrier_kind) {
      | ^
/home/jreuter/Projects/Compilers/llvm-project/openmp/runtime/src/kmp_barrier.cpp:2309:43: error: use of undeclared identifier 'ompt_state'; did you mean 'ompd_state'?
 2309 |     this_thr->th.ompt_thread_info.state = ompt_state;
      |                                           ^~~~~~~~~~
 | ompd_state
/home/jreuter/Projects/Compilers/llvm-project/openmp/runtime/src/ompd-specific.h:34:17: note: 'ompd_state' declared here
   34 | extern uint64_t ompd_state;
 | ^
/home/jreuter/Projects/Compilers/llvm-project/openmp/runtime/src/kmp_barrier.cpp:2309:43: error: assigning to 'ompt_state_t' (aka 'enum ompt_state_t') from incompatible type 'uint64_t' (aka 'unsigned long')
 2309 | this_thr->th.ompt_thread_info.state = ompt_state;
      | ^~~~~~~~~~
4 errors generated.
[35/41] Building CXX object openmp/runtime/src/CMakeFiles/obj.omp.dir/kmp_affinity.cpp.o
```

Looking into the failures, they were likely introduced in #95602 (7a72856af8b30f50e546b8368596fdc5f44cbca9). Here, a differentiation between different barrier types was implemented. The evaluation is only done if `OMPT_OPTIONAL` is set, but the result is also used without this macro being set, leading to the build failures above.

Depending on if the state changes should be reported even if `OMPT_OPTIONAL` is unset, the state change either needs to be moved into the `OMPT_OPTIONAL` block, or the state evaluation into the more general `OMPT_SUPPORT`.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzMWM1z4joS_2uUS5cosDEfhxwAwyz1wkcl5GX2RMlWG2tiS15JJsMe9m_fkmwSSGbeYd9kal1UCOrvX7dacjNjxEEi3pJoSqL4htU2V_p2l5803iSKn26fcpRg9UnIA1gFSS0KDnd3f65IMDSwqVCutqBraUWJ8CJsDjZHUJUVSrICNqvtDkxdVUpb4MKwpEBOgpnnapTpWhoQ0ipgkDFR1BrhxVn1ZGeXDLrPZbVPmNYCdSetKjLodmBJgmEJtfGu5QizgskDBGGn1wmh0uooOHJITjDRaQ53QtbfIUeNznxSW2DG1CWCzZn18oaV-OqBStNamyYiBlbX8rlxqEO6E_cJ3GfqI0hVWTLJSdiuOvKg23xSJY0q0Ev0IS3ZMwJ9OCNmgE5BY6UVB_oF1kJ-Y0Bjh-9-vp5M7-b7-8f1brmaP5AwVhXKsgIaz1aTP-b72X62WW2Xd_N7EsapD_6V9PXrByIJpiSYvrJMH5d38X73z-2chPE9FsgMOtPL6Wa13bu87R8et9vN_Y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