External Issue: Clang error compiling included C++ headers with GPU locale model

19754, "milthorpe", "Clang error compiling included C++ headers with GPU locale model", "2022-05-04T10:02:54Z"

Summary of Problem

A Chapel package module (ZMQ) that includes C++ code does not compile with the GPU locale model.

Steps to Reproduce

If I try to compile the arkouda code to check for ZeroMQ, which requires a C library wrapper, it works fine with the regular locale model:

milthorpe@equinox:/noback/milthorpe/chapel[main ?]$ chpl ../arkouda/dep/checkZMQ.chpl -Ispack location -i libzmq%gcc@11.1.0 arch=linux-ubuntu20.04-broadwell/include -Lspack location -i libzmq%gcc@11.1.0 arch=linux-ubuntu20.04-broadwell/lib
milthorpe@equinox:/noback/milthorpe/chapel[main !?]$ ./checkZMQ
Found ZMQ version: 4.3.3


but crashes when compiled with the GPU locale model:

milthorpe@equinox:/noback/milthorpe/chapel[main !?]$ CHPL_LLVM=bundled CHPL_CUDA_PATH=/opt/nvidia/hpc_sdk/Linux_x86_64/21.7/cuda/11.4 CHPL_LOCALE_MODEL=gpu chpl --gpu-arch sm_60 --no-checks ../arkouda/dep/checkZMQ.chpl -Ispack location -i libzmq%gcc@11.1.0 arch=linux-ubuntu20.04-broadwell/include -Lspack location -i libzmq%gcc@11.1.0 arch=linux-ubuntu20.04-broadwell/lib
warning: Unknown CUDA version. cuda.h: CUDA_VERSION=11040. Assuming the latest supported version 10.1
In file included from :3:
In file included from /tmp/chpl-milthorpe.deleteme-aIK9XQ/command-line-includes.h:7:
In file included from /noback/milthorpe/chapel/modules/packages/ZMQHelper/zmq_helper.h:26:
In file included from /noback/milthorpe/chapel/runtime/include/qio/qio.h:26:
In file included from /noback/milthorpe/chapel/runtime/include/qio/qbuffer.h:39:
In file included from /noback/milthorpe/chapel/runtime/include/qio/deque.h:44:
In file included from /noback/milthorpe/chapel/runtime/include/chpl-mem.h:30:
In file included from /noback/milthorpe/chapel/runtime/include/arg.h:24:
In file included from /noback/milthorpe/chapel/runtime/include/chpltypes.h:39:
In file included from /noback/milthorpe/chapel/third-party/llvm/install/linux64-x86_64-clang/lib/clang/13.0.0/include/cuda_wrappers/complex:33:
/noback/milthorpe/spack/opt/spack/linux-ubuntu20.04-broadwell/gcc-9.4.0/gcc-11.1.0-wnfs2uguhyb3qe4tnvgy3ff43hruxwsw/lib/gcc/x86_64-pc-linux-gnu/11.1.0/../../../../include/c++/11.1.0/type_traits:56:3: error: templates must have C++ linkage
template<typename _Tp, _Tp __v>
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/chpl-milthorpe.deleteme-aIK9XQ/command-line-includes.h:2:1: note: extern "C" language linkage specification begins here
extern "C" {
^
...
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated when compiling for sm_60.
error: error running clang during code generation


The clang error indicates that the `extern "C"` in the generated file `command-line-includes.h` is the problem. If I remove the extern declaration, I can compile and run with the GPU locale model, but I'm not sure if this is the correct solution.

From what I can see, `command-line-includes.h` is including a bunch of mostly-C header files, but one include chain runs from `modules/packages/ZMQHelper/zmq_helper.h` down to `runtime/include/chpltypes.h`, which includes a C++ header file `clang/13.0.0/include/cuda_wrappers/complex` that includes templated functions. This won't work in the context of an `extern "C"` include, but I'm not sure of the best solution to ensure C++ code is correctly included as such. The compiler check `isCHeader` just checks whether the filename suffix is `.h`, which won't work for files like the runtime headers `chpltypes.h`, `chplcast.h` which function either as C or C++ headers depending on how they're compiled (`#ifdef __cplusplus`).

### Configuration Information

- Output of `chpl --version`:

chpl version 1.27.0 pre-release (298724cbcb)
built with LLVM version 13.0.0

- Output of `$CHPL_HOME/util/printchplenv --anonymize`:

CHPL_TARGET_PLATFORM: linux64
CHPL_TARGET_COMPILER: llvm
CHPL_TARGET_ARCH: x86_64
CHPL_TARGET_CPU: native
CHPL_LOCALE_MODEL: gpu *
CHPL_COMM: none
CHPL_TASKS: qthreads
CHPL_LAUNCHER: none
CHPL_TIMERS: generic
CHPL_UNWIND: none
CHPL_MEM: jemalloc
CHPL_ATOMICS: cstdlib
CHPL_GMP: bundled
CHPL_HWLOC: bundled
CHPL_RE2: bundled
CHPL_LLVM: bundled
CHPL_AUX_FILESYS: none

- Back-end compiler and version, e.g. `gcc --version` or `clang --version`:

clang version 13.0.0 (git@github.com:milthorpe/chapel.git 298724cbcb3712d300a98d4734d6e233b87ad201)