[CUDA][HIP] Fix hostness check with -fopenmp
authorYaxun (Sam) Liu <yaxun.liu@amd.com>
Wed, 16 Mar 2022 01:45:02 +0000 (21:45 -0400)
committerYaxun (Sam) Liu <yaxun.liu@amd.com>
Thu, 24 Mar 2022 19:19:47 +0000 (15:19 -0400)
commitd41445113bccaa037e5876659b4fd98d96af03e4
tree10e4729909c6e19af0b3f33d04b89dd844d94868
parent2e44b7872bc638ed884ae4aa86e38b3b47e0b65a
[CUDA][HIP] Fix hostness check with -fopenmp

CUDA/HIP determines whether a function can be called based on
the device/host attributes of callee and caller. Clang assumes the
caller is CurContext. This is correct in most cases, however, it is
not correct in OpenMP parallel region when CUDA/HIP program
is compiled with -fopenmp. This causes incorrect overloading
resolution and missed diagnostics.

To get the correct caller, clang needs to chase the parent chain
of DeclContext starting from CurContext until a function decl
or a lambda decl is reached. Sema API is adapted to achieve that
and used to determine the caller in hostness check.

Reviewed by: Artem Belevich, Richard Smith

Differential Revision: https://reviews.llvm.org/D121765
clang/include/clang/Sema/Sema.h
clang/lib/Sema/Sema.cpp
clang/lib/Sema/SemaCUDA.cpp
clang/lib/Sema/SemaOverload.cpp
clang/test/CodeGenCUDA/openmp-parallel.cu [new file with mode: 0644]
clang/test/SemaCUDA/openmp-parallel.cu [new file with mode: 0644]