diff --git a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp --- a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp +++ b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp @@ -1344,8 +1344,8 @@ handleAccess(A, *MI, Ptr, nullptr, AccessKind::AK_WRITE, 0, Changed, nullptr, LengthVal); } else if (ArgNo == 1) { - handleAccess(A, *MI, Ptr, nullptr, AccessKind::AK_READ, 0, Changed, - nullptr, LengthVal); + handleAccess(A, *MI, Ptr, nullptr, AccessKind::AK_READ_WRITE, 0, + Changed, nullptr, LengthVal); } else { LLVM_DEBUG(dbgs() << "[AAPointerInfo] Unhandled memory intrinsic " << *MI << "\n"); diff --git a/openmp/libomptarget/test/offloading/bug51249.cpp b/openmp/libomptarget/test/offloading/bug51249.cpp new file mode 100644 --- /dev/null +++ b/openmp/libomptarget/test/offloading/bug51249.cpp @@ -0,0 +1,28 @@ +// RUN: %libomptarget-compilexx-generic -O3 && %libomptarget-run-generic + +#include +#include + +constexpr int N = 1024; + +std::complex reduce(std::complex *X, int N) { + std::complex Sum = {0, 0}; +#pragma omp target teams distribute parallel for map(to: X[0:N]) reduction(+ : Sum) + for (int i = 0; i < N; ++i) + Sum += X[i]; + + return Sum; +} + +int main() { + std::complex X[N]; + + for (int i = 0; i < N; ++i) + X[i] = {1, -1}; + + std::complex Sum = reduce(X, N); + + // CHECK: PASS + if (std::real(Sum) + std::imag(Sum) == 0.0) + printf("PASS\n"); +}