[openmp] Annotate tmp variables with omp_thread_mem_alloc
authorJon Chesterfield <jonathanchesterfield@gmail.com>
Thu, 12 Aug 2021 16:30:22 +0000 (17:30 +0100)
committerJon Chesterfield <jonathanchesterfield@gmail.com>
Thu, 12 Aug 2021 16:30:22 +0000 (17:30 +0100)
commitb6113548c9217fb8a6d0e9ac5bef5584c1aa614d
treed7b96af6267458f573cf2093b09ba5ae49703f85
parentdd3eea65662a675b78ac2319fd675a22345f5ca3
[openmp] Annotate tmp variables with omp_thread_mem_alloc

Fixes miscompile of calls into ocml. Bug 51445.

The stack variable `double __tmp` is moved to dynamically allocated shared
memory by CGOpenMPRuntimeGPU. This is usually fine, but when the variable
is passed to a function that is explicitly annotated address_space(5) then
allocating the variable off-stack leads to a miscompile in the back end,
which cannot decide to move the variable back to the stack from shared.

This could be fixed by removing the AS(5) annotation from the math library
or by explicitly marking the variables as thread_mem_alloc. The cast to
AS(5) is still a no-op once IR is reached.

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D107971
clang/lib/Headers/__clang_hip_math.h