summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJustin Lebar <jlebar@google.com>2016-01-23 21:28:17 +0000
committerJustin Lebar <jlebar@google.com>2016-01-23 21:28:17 +0000
commit5496a8c53db4003c03e7e1341e4ec9b67e54563a (patch)
tree482763cf2b908bda914a399c4bd31b77a8e039a1 /lib
parente2636ac0bad65451c3eb6272d7ab3abbba96da17 (diff)
downloadclang-5496a8c53db4003c03e7e1341e4ec9b67e54563a.tar.gz
[CUDA] Disallow variadic functions other than printf in device code.
Reviewers: tra Subscribers: cfe-commits, echristo, jhen Differential Revision: http://reviews.llvm.org/D16484 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@258643 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Sema/SemaDecl.cpp32
1 files changed, 20 insertions, 12 deletions
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index 16ad13db90..6adbc3fab6 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -8276,18 +8276,26 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC,
MarkUnusedFileScopedDecl(NewFD);
- if (getLangOpts().CUDA)
- if (IdentifierInfo *II = NewFD->getIdentifier())
- if (!NewFD->isInvalidDecl() &&
- NewFD->getDeclContext()->getRedeclContext()->isTranslationUnit()) {
- if (II->isStr("cudaConfigureCall")) {
- if (!R->getAs<FunctionType>()->getReturnType()->isScalarType())
- Diag(NewFD->getLocation(), diag::err_config_scalar_return);
-
- Context.setcudaConfigureCallDecl(NewFD);
- }
- }
-
+ if (getLangOpts().CUDA) {
+ IdentifierInfo *II = NewFD->getIdentifier();
+ if (II && II->isStr("cudaConfigureCall") && !NewFD->isInvalidDecl() &&
+ NewFD->getDeclContext()->getRedeclContext()->isTranslationUnit()) {
+ if (!R->getAs<FunctionType>()->getReturnType()->isScalarType())
+ Diag(NewFD->getLocation(), diag::err_config_scalar_return);
+
+ Context.setcudaConfigureCallDecl(NewFD);
+ }
+
+ // Variadic functions, other than a *declaration* of printf, are not allowed
+ // in device-side CUDA code.
+ if (NewFD->isVariadic() && (NewFD->hasAttr<CUDADeviceAttr>() ||
+ NewFD->hasAttr<CUDAGlobalAttr>()) &&
+ !(II && II->isStr("printf") && NewFD->isExternC() &&
+ !D.isFunctionDefinition())) {
+ Diag(NewFD->getLocation(), diag::err_variadic_device_fn);
+ }
+ }
+
// Here we have an function template explicit specialization at class scope.
// The actually specialization will be postponed to template instatiation
// time via the ClassScopeFunctionSpecializationDecl node.