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

Michael Liao via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 12 11:32:56 PST 2019


hliao updated this revision to Diff 228924.
hliao added a comment.

This patch is revived with more changes addressing the previous concerns.

Back to Justin's example:

  __host__ float bar();
  __device__ int bar();
  __host__ __device__ auto foo() -> decltype(bar()) { return bar(); }

Even without this patch, that example already passed the compilation without
either errors or warnings. Says

  clang -std=c++11 -x cuda -nocudainc -nocudalib --cuda-gpu-arch=sm_60 --cuda-device-only -S -emit-llvm -O3 foo.cu

In c++14, that example could be even simplified without `decltype` but the same ambiguity.

  __host__ float bar();
  __device__ int bar();
  __host__ __device__ auto foo() { return bar(); }

Without any change, clang also compiles the code as well and uses different return types between host-side and device-side compilation.[^1]

[^1]: The first example has the same return type between host-side and device-side but that seems incorrect or unreasonable to me.

The ambiguity issue is in fact not introduced by relaxing `decltype`. That's an inherent one as we allow overloading over target attributes. Issuing warnings instead of errors seems more reasonable to me for such cases.

In this patch, besides relaxing the CUDA call rule under `decltype`, it also generates warning during function overloading if there are more than candidates with different return types.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61458

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaOverload.cpp
  clang/test/CodeGenCUDA/function-overload.cu
  clang/test/Misc/warning-flags.c
  clang/test/SemaCUDA/function-overload.cu

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D61458.228924.patch
Type: text/x-patch
Size: 8773 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191112/f53da13d/attachment-0001.bin>


More information about the cfe-commits mailing list