[openmp] Annotate tmp variables with omp_thread_mem_alloc
authorJon Chesterfield <jonathanchesterfield@gmail.com>
Thu, 19 Aug 2021 01:22:10 +0000 (02:22 +0100)
committerJon Chesterfield <jonathanchesterfield@gmail.com>
Thu, 19 Aug 2021 01:22:11 +0000 (02:22 +0100)
commitdbd7bad9ad9bc32538e324417c23387bf4ac7747
tree01ec06a4ceef452a6fea925f78bfb05d1828990a
parent829616c24119f000132913616a7cd4ad930ca84a
[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
clang/test/Headers/Inputs/include/omp.h [new file with mode: 0644]