Skip to content

Commit 708e050

Browse files
author
Yuanke Luo
committed
[CUDA] Remove sema check of function declaration with variadic argument
Variadic argument for NVPTX has been support in 486d00e We can remove the sema check in front-end.
1 parent aa42b64 commit 708e050

File tree

3 files changed

+6
-32
lines changed

3 files changed

+6
-32
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8729,7 +8729,7 @@ def fcuda_include_gpubinary : Separate<["-"], "fcuda-include-gpubinary">,
87298729
HelpText<"Incorporate CUDA device-side binary into host object file.">,
87308730
MarshallingInfoString<CodeGenOpts<"CudaGpuBinaryFileName">>;
87318731
def fcuda_allow_variadic_functions : Flag<["-"], "fcuda-allow-variadic-functions">,
8732-
HelpText<"Allow variadic functions in CUDA device code.">,
8732+
HelpText<"Deprecated; Allow variadic functions in CUDA device code.">,
87338733
MarshallingInfoFlag<LangOpts<"CUDAAllowVariadicFunctions">>;
87348734
def fno_cuda_host_device_constexpr : Flag<["-"], "fno-cuda-host-device-constexpr">,
87358735
HelpText<"Don't treat unattributed constexpr functions as __host__ __device__.">,

clang/lib/Sema/SemaDecl.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11041,17 +11041,6 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC,
1104111041
<< CUDA().getConfigureFuncName();
1104211042
Context.setcudaConfigureCallDecl(NewFD);
1104311043
}
11044-
11045-
// Variadic functions, other than a *declaration* of printf, are not allowed
11046-
// in device-side CUDA code, unless someone passed
11047-
// -fcuda-allow-variadic-functions.
11048-
if (!getLangOpts().CUDAAllowVariadicFunctions && NewFD->isVariadic() &&
11049-
(NewFD->hasAttr<CUDADeviceAttr>() ||
11050-
NewFD->hasAttr<CUDAGlobalAttr>()) &&
11051-
!(II && II->isStr("printf") && NewFD->isExternC() &&
11052-
!D.isFunctionDefinition())) {
11053-
Diag(NewFD->getLocation(), diag::err_variadic_device_fn);
11054-
}
1105511044
}
1105611045

1105711046
MarkUnusedFileScopedDecl(NewFD);

clang/test/SemaCUDA/vararg.cu

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
// REQUIRES: x86-registered-target
22
// REQUIRES: nvptx-registered-target
33
// RUN: %clang_cc1 -triple nvptx64-nvidia-cuda -fcuda-is-device -fsyntax-only \
4-
// RUN: -verify -DEXPECT_VA_ARG_ERR -DEXPECT_VARARG_ERR %s
4+
// RUN: -verify -DEXPECT_VA_ARG_ERR %s
55
// RUN: %clang_cc1 -triple nvptx64-nvidia-cuda -fcuda-is-device -fsyntax-only \
66
// RUN: -fcuda-allow-variadic-functions -verify -DEXPECT_VA_ARG_ERR %s
7-
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fsyntax-only -verify \
8-
// RUN: -DEXPECT_VARARG_ERR %s
97

108
#include <stdarg.h>
119
#include "Inputs/cuda.h"
@@ -30,28 +28,15 @@ __device__ void baz() {
3028
#endif
3129
}
3230

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

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

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

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

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

0 commit comments

Comments
 (0)