[PATCH] D61458: [hip] Relax CUDA call restriction within `decltype` context.

Michael Liao via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri May 3 05:26:33 PDT 2019


hliao added a comment.

In D61458#1488970 <https://reviews.llvm.org/D61458#1488970>, @jlebar wrote:

> Here's one for you:
>
>   __host__ float bar();
>   __device__ int bar();
>   __host__ __device__ auto foo() -> decltype(bar()) {}
>
>
> What is the return type of `foo`?  :)
>
> I don't believe the right answer is, "float when compiling for host, int when compiling for device."
>
> I'd be happy if we said this was an error, so long as it's well-defined what exactly we're disallowing.  But I bet @rsmith can come up with substantially more evil testcases than this.


This patch is introduced to allow function or template function from `std` library to be used with device function. By allowing different-side candidates with a context only caring type inspection, we have new issue as there are extra beyond the regular rule for C++ overloadable resolution. We need an extra policy to figure out which is one the best candidate by considering CUDA attributes. Says the case you proposed, we may consider the following order to choose an overloadable candidate, e.g.

  SAME-SIDE (with the same CUDA attribute)
  NATIVE (without any CUDA attribute)
  WRONG-SIDE (with the opposite CUDA attribute)

or just

  SAME-SIDE
  NATIVE

It that a reasonable change?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D61458/new/

https://reviews.llvm.org/D61458





More information about the cfe-commits mailing list