Debian Codegraph @

clang/test/SemaCUDA/vararg.cu

raw
1 // REQUIRES: x86-registered-target
2 // REQUIRES: nvptx-registered-target
3 // RUN: %clang_cc1 -triple nvptx64-nvidia-cuda -fcuda-is-device -fsyntax-only \
4 // RUN: -verify -DEXPECT_VA_ARG_ERR %s
5 // RUN: %clang_cc1 -triple nvptx64-nvidia-cuda -fcuda-is-device -fsyntax-only \
6 // RUN: -fcuda-allow-variadic-functions -verify -DEXPECT_VA_ARG_ERR %s
7
8 #include <stdarg.h>
9 #include "Inputs/cuda.h"
10
11 __global__ void foo() {
12 va_list list;
13 va_arg(list, int);
14 #ifdef EXPECT_VA_ARG_ERR
15 // expected-error@-2 {{CUDA device code does not support va_arg}}
16 #endif
17 }
18
19 void bar() {
20 va_list list;
21 va_arg(list, int); // OK: host-only
22 }
23
24 __device__ void baz() {
25 #if !defined(__CUDA_ARCH__)
26 va_list list;
27 va_arg(list, int); // OK: only seen when compiling for host
28 #endif
29 }
30
31 __device__ void vararg(const char* x, ...) {} // OK
32
33 template <typename T>
34 __device__ void vararg(T t, ...) {} // OK
35
36 extern "C" __device__ int printf(const char* fmt, ...); // OK, special case.
37
38 extern "C" __device__ int printf(const char* fmt, ...) { return 0; } // OK
39
40 namespace ns {
41 __device__ int printf(const char* fmt, ...); // OK
42 }