diff options
author | Yaxun (Sam) Liu <yaxun.liu@amd.com> | 2020-04-24 16:41:24 -0400 |
---|---|---|
committer | Yaxun (Sam) Liu <yaxun.liu@amd.com> | 2020-05-12 08:27:50 -0400 |
commit | e03394c6a6ff5832aa43259d4b8345f40ca6a22c (patch) | |
tree | 3b327b64ef9abddc3fc6a43fd9a1e298ef1eae9c /clang/lib/Sema/SemaCUDA.cpp | |
parent | f1f8cffce49fe56817e25f648b29e1a8cfcfac8a (diff) | |
download | llvm-e03394c6a6ff5832aa43259d4b8345f40ca6a22c.zip llvm-e03394c6a6ff5832aa43259d4b8345f40ca6a22c.tar.gz llvm-e03394c6a6ff5832aa43259d4b8345f40ca6a22c.tar.bz2 |
[CUDA][HIP] Workaround for resolving host device function against wrong-sided function
recommit c77a4078e01033aa2206c31a579d217c8a07569b with fix
https://reviews.llvm.org/D77954 caused regressions due to diagnostics in implicit
host device functions.
For now, it seems the most feasible workaround is to treat implicit host device function and explicit host
device function differently. Basically in device compilation for implicit host device functions, keep the
old behavior, i.e. give host device candidates and wrong-sided candidates equal preference. For explicit
host device functions, favor host device candidates against wrong-sided candidates.
The rationale is that explicit host device functions are blessed by the user to be valid host device functions,
that is, they should not cause diagnostics in both host and device compilation. If diagnostics occur, user is
able to fix them. However, there is no guarantee that implicit host device function can be compiled in
device compilation, therefore we need to preserve its overloading resolution in device compilation.
Differential Revision: https://reviews.llvm.org/D79526
Diffstat (limited to 'clang/lib/Sema/SemaCUDA.cpp')
-rw-r--r-- | clang/lib/Sema/SemaCUDA.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaCUDA.cpp b/clang/lib/Sema/SemaCUDA.cpp index 73d1908..eecea94 100644 --- a/clang/lib/Sema/SemaCUDA.cpp +++ b/clang/lib/Sema/SemaCUDA.cpp @@ -211,6 +211,20 @@ Sema::IdentifyCUDAPreference(const FunctionDecl *Caller, llvm_unreachable("All cases should've been handled by now."); } +template <typename AttrT> static bool hasImplicitAttr(const FunctionDecl *D) { + if (!D) + return false; + if (auto *A = D->getAttr<AttrT>()) + return A->isImplicit(); + return D->isImplicit(); +} + +bool Sema::IsCUDAImplicitHostDeviceFunction(const FunctionDecl *D) { + bool IsImplicitDevAttr = hasImplicitAttr<CUDADeviceAttr>(D); + bool IsImplicitHostAttr = hasImplicitAttr<CUDAHostAttr>(D); + return IsImplicitDevAttr && IsImplicitHostAttr; +} + void Sema::EraseUnwantedCUDAMatches( const FunctionDecl *Caller, SmallVectorImpl<std::pair<DeclAccessPair, FunctionDecl *>> &Matches) { |