diff options
author | Justin Lebar <jlebar@google.com> | 2016-01-23 21:28:17 +0000 |
---|---|---|
committer | Justin Lebar <jlebar@google.com> | 2016-01-23 21:28:17 +0000 |
commit | e48cd6c5304d39d34f584d76ea8e25838be1e942 (patch) | |
tree | 9d65cf2aa1750ac299b2ada00903590e3b432a0b /clang/lib/Sema | |
parent | 3039a593db6f013c374d25b715a56e6098bfe17f (diff) | |
download | bcm5719-llvm-e48cd6c5304d39d34f584d76ea8e25838be1e942.tar.gz bcm5719-llvm-e48cd6c5304d39d34f584d76ea8e25838be1e942.zip |
[CUDA] Disallow variadic functions other than printf in device code.
Reviewers: tra
Subscribers: cfe-commits, echristo, jhen
Differential Revision: http://reviews.llvm.org/D16484
llvm-svn: 258643
Diffstat (limited to 'clang/lib/Sema')
-rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 16ad13db90d..6adbc3fab6f 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/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. |