[PATCH] D68030: [CUDA][HIP] Initial kernel return type relaxing.
Michael Liao via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Sep 25 08:31:51 PDT 2019
hliao created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
hliao abandoned this revision.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D68030
Files:
clang/lib/Sema/SemaDeclAttr.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaStmt.cpp
clang/lib/Sema/SemaTemplateDeduction.cpp
Index: clang/lib/Sema/SemaTemplateDeduction.cpp
===================================================================
--- clang/lib/Sema/SemaTemplateDeduction.cpp
+++ clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -3093,6 +3093,13 @@
Function->getTypeSpecStartLoc(), Function->getDeclName());
if (ResultType.isNull() || Trap.hasErrorOccurred())
return TDK_SubstitutionFailure;
+ // CUDA: Kernel function must have 'void' return type.
+ if (getLangOpts().CUDA)
+ if (Function->hasAttr<CUDAGlobalAttr>() && !ResultType->isVoidType()) {
+ Diag(Function->getLocation(), diag::err_kern_type_not_void_return)
+ << Function->getType() << Function->getSourceRange();
+ return TDK_SubstitutionFailure;
+ }
}
// Instantiate the types of each of the function parameters given the
Index: clang/lib/Sema/SemaStmt.cpp
===================================================================
--- clang/lib/Sema/SemaStmt.cpp
+++ clang/lib/Sema/SemaStmt.cpp
@@ -3500,6 +3500,14 @@
return true;
}
+ // CUDA: Kernel function must have 'void' return type.
+ if (getLangOpts().CUDA)
+ if (FD->hasAttr<CUDAGlobalAttr>() && !Deduced->isVoidType()) {
+ Diag(FD->getLocation(), diag::err_kern_type_not_void_return)
+ << FD->getType() << FD->getSourceRange();
+ return true;
+ }
+
// If a function with a declared return type that contains a placeholder type
// has multiple return statements, the return type is deduced for each return
// statement. [...] if the type deduced is not the same in each deduction,
Index: clang/lib/Sema/SemaExpr.cpp
===================================================================
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -5891,7 +5891,9 @@
<< FDecl << Fn->getSourceRange());
// CUDA: Kernel function must have 'void' return type
- if (!FuncT->getReturnType()->isVoidType())
+ if (!FuncT->getReturnType()->isVoidType() &&
+ !FuncT->getReturnType()->getAs<AutoType>() &&
+ !FuncT->getReturnType()->isInstantiationDependentType())
return ExprError(Diag(LParenLoc, diag::err_kern_type_not_void_return)
<< Fn->getType() << Fn->getSourceRange());
} else {
Index: clang/lib/Sema/SemaDeclAttr.cpp
===================================================================
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -4223,7 +4223,9 @@
return;
}
const auto *FD = cast<FunctionDecl>(D);
- if (!FD->getReturnType()->isVoidType()) {
+ if (!FD->getReturnType()->isVoidType() &&
+ !FD->getReturnType()->getAs<AutoType>() &&
+ !FD->getReturnType()->isInstantiationDependentType()) {
SourceRange RTRange = FD->getReturnTypeSourceRange();
S.Diag(FD->getTypeSpecStartLoc(), diag::err_kern_type_not_void_return)
<< FD->getType()
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D68030.221778.patch
Type: text/x-patch
Size: 2909 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190925/25078be1/attachment.bin>
More information about the cfe-commits
mailing list