NVHPC: can't build CMake from source >= 3.25.0

Changes to CMake internal C++ code for try_compile in 3.25 and a couple other places seem to have triggered bugs in NVHPC compiler. I would guess these are actually NVHPC bugs, but over subsequent CMake development, more places in CMake internals trigger NVHPC bugs. The first such bug arose at 77fcb00a2b76518c0db861a96a8f4857a50b140e is the first bad commit

I am not sure that CMake code necessarily needs to be changed but this notes the beginning of the issues, and perhaps can help NVHPC devs iterate as they work to improve their C++ compiler using CMake project as a reference.

NVHPC 2023.1.0 error:

Tests/CMakeLib/CMakeFiles/CMakeLibTests.dir/testArgumentParser.cxx.o
/nvidia/hpc_sdk/Linux_x86_64/2023/compilers/bin/nvc++ -DCURL_STATICLIB -DLIBARCHIVE_STATIC -I/cmake/buildn/Utilities -I/cmake/buildn/Tests/CMakeLib -I/cmake/buildn/Source -I/cmake/Source -I/cmake/Source/CTest -isystem /cmake/Utilities/std -isystem /cmake/Utilities -g -O0 --c++17 --gnu_extensions -MD -MT Tests/CMakeLib/CMakeFiles/CMakeLibTests.dir/testArgumentParser.cxx.o -MF Tests/CMakeLib/CMakeFiles/CMakeLibTests.dir/testArgumentParser.cxx.o.d -o Tests/CMakeLib/CMakeFiles/CMakeLibTests.dir/testArgumentParser.cxx.o -c /cmake/Tests/CMakeLib/testArgumentParser.cxx
Internal error: read_memory_region: not all expected entries were read

nvc++-Fatal-/nvidia/hpc_sdk/Linux_x86_64/23.1/compilers/bin/tools/cpp2 TERMINATED by signal 6
Arguments to /nvidia/hpc_sdk/Linux_x86_64/23.1/compilers/bin/tools/cpp2
/nvidia/hpc_sdk/Linux_x86_64/23.1/compilers/bin/tools/cpp2 /cmake/Tests/CMakeLib/testArgumentParser.cxx -debug -x 120 0x8000 -opt 0 -terse 1 -inform warn -x 119 0xa10000 -x 122 0x40 -x 123 0x1000 -x 127 4 -x 127 17 -x 19 0x400000 -x 28 0x40000 -x 120 0x10000000 -x 70 0x8000 -x 122 1 -x 125 0x20000 -quad -x 59 4 -tp skylake-avx512 -astype 0 -x 121 1 -fn /cmake/Tests/CMakeLib/testArgumentParser.cxx -il /tmp/nvc++RlBmkbOSCt2Px.il -x 117 0x200 -x 123 0x80000000 -x 123 4 -x 119 0x20 -def __pgnu_vsn=80500 -x 70 0x40000000 -x 183 4 -x 121 0x800 -x 6 0x20000 -x 249 140 -x 120 0x200000 -x 70 0x40000000 -x 8 0x40000000 -x 164 0x800000 -x 71 0x2000 -x 71 0x4000 -x 34 0x40000000 -x 83 0x1 -x 85 0x1 -x 206 0x02 -x 120 0x1000000 -x 68 0x1 -x 39 4 -x 56 0x10 -x 26 0x10 -x 26 1 -x 56 0x4000 -x 197 0 -x 175 0 -x 203 0 -x 204 0 -y 163 0xc0000000 -x 163 0x800000 -x 189 0x10 -y 189 0x4000000 -x 60 512 -gnuvsn 80500 -x 69 0x200 -x 123 0x400 -x 119 0x08 -cmdline '+nvc++ /tmp/nvc++RlBmkbOSCt2Px.il -DCURL_STATICLIB -DLIBARCHIVE_STATIC -I/cmake/buildn/Utilities -I/cmake/buildn/Tests/CMakeLib -I/cmake/buildn/Source -I/cmake/Source -I/cmake/Source/CTest -isystem /cmake/Utilities/std -isystem /cmake/Utilities -g -O0 --c++17 --gnu_extensions -MD -MT Tests/CMakeLib/CMakeFiles/CMakeLibTests.dir/testArgumentParser.cxx.o -MF Tests/CMakeLib/CMakeFiles/CMakeLibTests.dir/testArgumentParser.cxx.o.d -o Tests/CMakeLib/CMakeFiles/CMakeLibTests.dir/testArgumentParser.cxx.o -c' -asm /tmp/nvc++BlBmkrPEV9SxJ.ll

Cc: @brad.king @robert.maynard

Using a container started from nvcr.io/nvidia/nvhpc:22.11-devel-cuda_multi-ubuntu22.04, I can reproduce the NVHPC compiler crash in a small test case like this:

$ cat example.cxx
struct A { ~A(); };
template<typename T> struct X { X(int, T, A = A()); };
template<typename T> struct Y : public T { using T::T; };
struct S {
  X<double> x{1, 1.0};
  Y<X<double>> y{1, 1.0};
};

$ nvc++ --version
nvc++ 22.11-0 64-bit target on x86-64 Linux ...

$ nvc++ -c example.cxx
Internal error: read_memory_region: not all expected entries were read

nvc++-Fatal-/opt/nvidia/hpc_sdk/Linux_x86_64/22.11/compilers/bin/tools/cpp2 TERMINATED by signal 6

I get the same error with nvc++ 23.1-0; reported your example snippet to NVHPC dev forum Nvc++ ICE on typical C++ snippet - nvc, nvc++ and nvfortran - NVIDIA Developer Forums

This is fixed in Nvidia HPC SDK 23.5 release. I can build CMake itself on “master” branch now. Nvc++ ICE on typical C++ snippet - #5 by MatColgrove - nvc, nvc++ and nvfortran - NVIDIA Developer Forums