Standard parallel algorithm compiles with 22.5 but fails with 22.7

A standard algorithm capturing a vector

#include <vector>
#include <algorithm>
#include <execution>

auto main() -> int
{
  std::vector const a = {1u, 0u};
  std::vector const b = {5., 7.};
  std::vector c = {6., 8.};
  std::vector const expected = {7., 5.};

  std::transform(
    std::execution::par_unseq,
    std::cbegin(a), std::cend(a),
    std::begin(c),
    [b](size_t ind){return b[ind];}
  );
  auto const success = (expected == c);
  if(success) return EXIT_SUCCESS;
  else return EXIT_FAILURE;
}

compiles with NVIDIA HPC SDK 22.5 and gcc-10.2.1 for a target with compute capability 70, but fails to compile with NVIDIA HPC SDK 22.7 and gcc-11.2.0 for a target with compute capability 80, giving error

Bitcasts between pointers of different address spaces is not legal.Use AddrSpaceCast instead.
  %5 = bitcast double* %storemerge.i.i.i to i8 addrspace(1)*

A similar code capturing a span compiles on both the platforms:

#include <vector>
#include <algorithm>
#include <execution>
#include <span>

auto main() -> int
{
  std::vector const a = {1u, 0u};
  std::vector const b = {5., 7.};
  std::vector c = {6., 8.};
  std::vector const expected = {7., 5.};
  auto handleB = std::span(b);

  std::transform(
    std::execution::par_unseq,
    std::cbegin(a), std::cend(a),
    std::begin(c),
    [handleB](size_t ind){return handleB[ind];}
  );
  auto const success = (expected == c);
  if(success) return EXIT_SUCCESS;
  else return EXIT_FAILURE;
}

Is it supposed to compile in the first place, and what is the source of the difference?

Hi SD57,

I’m not able to reproduce the code generation error you show, but do get an undefined reference error to “__throw_bad_array_new_length”. This is likely related, but I can’t be 100% sure. Is there any additional information you can provide such as the compiler flags being used?

For the undefined reference error, it appears GNU added this new throw to the “gcc-11.2.0/Linux_x86_64/include/c++/11.2.0/ext/new_allocator.h” file at line 116. It’s not included in GNU 10.x.

I’ve added a problem report, TPR #32366. I also noticed a different code gen error when using the GNU 12.2 toolchain, which I reported as TPR#32367

% nvc++ -stdpar=gpu test1.cpp -V22.7 --c++20 --gcc-toolchain=/home/sw/thirdparty/gcc/gcc-11.2.0/Linux_x86_64 -fast
nvlink error   : Undefined reference to '_ZSt28__throw_bad_array_new_lengthv' in '/tmp/nvc++16zWmFBHXIyno.o'
pgacclnk: child process exit status 2: /proj/nv/Linux_x86_64/22.7/compilers/bin/tools/nvdd

-Mat

The flags are

-stdpar=gpu -target=gpu -gpu=cc80 -gcc-toolchain=<path to gcc-11.2.0> -O2 -gopt -std=gnu++20

I am able to reproduce your error with your flags.
I found the offending flag -gpu=cc80, cc60 and сс70 fail, too.
The original post should be renamed.

I went back and determined that the original bitcast error can be reproduced, but I needed to be on a system with GNU 11.2 installed natively. Hence, I added a third problem report, TPR #32369.