Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -8729,7 +8729,7 @@ def fcuda_include_gpubinary : Separate<["-"], "fcuda-include-gpubinary">,
HelpText<"Incorporate CUDA device-side binary into host object file.">,
MarshallingInfoString<CodeGenOpts<"CudaGpuBinaryFileName">>;
def fcuda_allow_variadic_functions : Flag<["-"], "fcuda-allow-variadic-functions">,
HelpText<"Allow variadic functions in CUDA device code.">,
HelpText<"Deprecated; Allow variadic functions in CUDA device code.">, Flags<[HelpHidden]>,
MarshallingInfoFlag<LangOpts<"CUDAAllowVariadicFunctions">>;
def fno_cuda_host_device_constexpr : Flag<["-"], "fno-cuda-host-device-constexpr">,
HelpText<"Don't treat unattributed constexpr functions as __host__ __device__.">,
Expand Down
11 changes: 0 additions & 11 deletions clang/lib/Sema/SemaDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11041,17 +11041,6 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC,
<< CUDA().getConfigureFuncName();
Context.setcudaConfigureCallDecl(NewFD);
}

// Variadic functions, other than a *declaration* of printf, are not allowed
// in device-side CUDA code, unless someone passed
// -fcuda-allow-variadic-functions.
if (!getLangOpts().CUDAAllowVariadicFunctions && NewFD->isVariadic() &&
(NewFD->hasAttr<CUDADeviceAttr>() ||
NewFD->hasAttr<CUDAGlobalAttr>()) &&
!(II && II->isStr("printf") && NewFD->isExternC() &&
!D.isFunctionDefinition())) {
Diag(NewFD->getLocation(), diag::err_variadic_device_fn);
}
}

MarkUnusedFileScopedDecl(NewFD);
Expand Down
25 changes: 5 additions & 20 deletions clang/test/SemaCUDA/vararg.cu
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
// REQUIRES: x86-registered-target
// REQUIRES: nvptx-registered-target
// RUN: %clang_cc1 -triple nvptx64-nvidia-cuda -fcuda-is-device -fsyntax-only \
// RUN: -verify -DEXPECT_VA_ARG_ERR -DEXPECT_VARARG_ERR %s
// RUN: -verify -DEXPECT_VA_ARG_ERR %s
// RUN: %clang_cc1 -triple nvptx64-nvidia-cuda -fcuda-is-device -fsyntax-only \
// RUN: -fcuda-allow-variadic-functions -verify -DEXPECT_VA_ARG_ERR %s
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fsyntax-only -verify \
// RUN: -DEXPECT_VARARG_ERR %s

#include <stdarg.h>
#include "Inputs/cuda.h"
Expand All @@ -30,28 +28,15 @@ __device__ void baz() {
#endif
}

__device__ void vararg(const char* x, ...) {}
#ifdef EXPECT_VARARG_ERR
// expected-error@-2 {{CUDA device code does not support variadic functions}}
#endif
__device__ void vararg(const char* x, ...) {} // OK

template <typename T>
__device__ void vararg(T t, ...) {}
#ifdef EXPECT_VARARG_ERR
// expected-error@-2 {{CUDA device code does not support variadic functions}}
#endif
__device__ void vararg(T t, ...) {} // OK

extern "C" __device__ int printf(const char* fmt, ...); // OK, special case.

// Definition of printf not allowed.
extern "C" __device__ int printf(const char* fmt, ...) { return 0; }
#ifdef EXPECT_VARARG_ERR
// expected-error@-2 {{CUDA device code does not support variadic functions}}
#endif
extern "C" __device__ int printf(const char* fmt, ...) { return 0; } // OK

namespace ns {
__device__ int printf(const char* fmt, ...);
#ifdef EXPECT_VARARG_ERR
// expected-error@-2 {{CUDA device code does not support variadic functions}}
#endif
__device__ int printf(const char* fmt, ...); // OK
}