[PATCH] D61458: [hip] Relax CUDA call restriction within `decltype` context.
Michael Liao via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu May 2 13:03:34 PDT 2019
hliao created this revision.
hliao added reviewers: tra, rjmccall, yaxunl.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
- Within `decltype`, expressions are only type-inspected. The restriction on CUDA calls should be relaxed.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D61458
Files:
clang/include/clang/Sema/Sema.h
clang/test/CodeGenCUDA/function-overload.cu
Index: clang/test/CodeGenCUDA/function-overload.cu
===================================================================
--- clang/test/CodeGenCUDA/function-overload.cu
+++ clang/test/CodeGenCUDA/function-overload.cu
@@ -8,6 +8,8 @@
// RUN: | FileCheck -check-prefix=CHECK-BOTH -check-prefix=CHECK-HOST %s
// RUN: %clang_cc1 -triple nvptx64-nvidia-cuda -fcuda-is-device -emit-llvm -o - %s \
// RUN: | FileCheck -check-prefix=CHECK-BOTH -check-prefix=CHECK-DEVICE %s
+// RUN: %clang_cc1 -std=c++11 -DCHECK_DECLTYPE -triple amdgcn -fcuda-is-device -emit-llvm -o - %s \
+// RUN: | FileCheck -check-prefix=CHECK-DECLTYPE %s
#include "Inputs/cuda.h"
@@ -53,3 +55,14 @@
// CHECK-BOTH: define linkonce_odr void @_ZN7s_cd_hdD2Ev(
// CHECK-BOTH: store i32 32,
// CHECK-BOTH: ret void
+
+#if defined(CHECK_DECLTYPE)
+int foo(float);
+// CHECK-DECLTYPE-LABEL: @_Z3barf
+// CHECK-DECLTYPE: fptosi
+// CHECK-DECLTYPE: sitofp
+__device__ float bar(float x) {
+ decltype(foo(x)) y = x;
+ return y + 3.f;
+}
+#endif
Index: clang/include/clang/Sema/Sema.h
===================================================================
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -10406,6 +10406,17 @@
/// semantically correct CUDA programs, but only if they're never codegen'ed.
bool IsAllowedCUDACall(const FunctionDecl *Caller,
const FunctionDecl *Callee) {
+ auto InDecltypeExpr = [this]() {
+ auto I =
+ std::find_if(ExprEvalContexts.rbegin(), ExprEvalContexts.rend(),
+ [](const ExpressionEvaluationContextRecord &C) {
+ return C.ExprContext ==
+ ExpressionEvaluationContextRecord::EK_Decltype;
+ });
+ return I != ExprEvalContexts.rend();
+ };
+ if (InDecltypeExpr())
+ return true;
return IdentifyCUDAPreference(Caller, Callee) != CFP_Never;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D61458.197850.patch
Type: text/x-patch
Size: 1951 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190502/6ba69150/attachment.bin>
More information about the cfe-commits
mailing list