1 // REQUIRES: x86-registered-target
2 // REQUIRES: nvptx-registered-target
4 // RUN: %clang_cc1 -triple nvptx64-nvidia-cuda -fcuda-is-device -emit-llvm \
5 // RUN: -o - %s | FileCheck %s
7 #include "Inputs/cuda.h"
9 extern "C" __device__ int vprintf(const char*, const char*);
11 // Check a simple call to printf end-to-end.
12 // CHECK: [[SIMPLE_PRINTF_TY:%[a-zA-Z0-9_]+]] = type { i32, i64, double }
13 __device__ int CheckSimple() {
14 // CHECK: [[BUF:%[a-zA-Z0-9_]+]] = alloca [[SIMPLE_PRINTF_TY]]
15 // CHECK: [[FMT:%[0-9]+]] = load{{.*}}%fmt
16 const char* fmt = "%d %lld %f";
17 // CHECK: [[PTR0:%[0-9]+]] = getelementptr inbounds nuw [[SIMPLE_PRINTF_TY]], ptr [[BUF]], i32 0, i32 0
18 // CHECK: store i32 1, ptr [[PTR0]], align 4
19 // CHECK: [[PTR1:%[0-9]+]] = getelementptr inbounds nuw [[SIMPLE_PRINTF_TY]], ptr [[BUF]], i32 0, i32 1
20 // CHECK: store i64 2, ptr [[PTR1]], align 8
21 // CHECK: [[PTR2:%[0-9]+]] = getelementptr inbounds nuw [[SIMPLE_PRINTF_TY]], ptr [[BUF]], i32 0, i32 2
22 // CHECK: store double 3.0{{[^,]*}}, ptr [[PTR2]], align 8
23 // CHECK: [[RET:%[0-9]+]] = call i32 @vprintf(ptr [[FMT]], ptr [[BUF]])
24 // CHECK: ret i32 [[RET]]
25 return printf(fmt, 1, 2ll, 3.0);
28 __device__ void CheckNoArgs() {
29 // CHECK: call i32 @vprintf({{.*}}, ptr null){{$}}
30 printf("hello, world!");
33 // Check that printf's alloca happens in the entry block, not inside the if
35 __device__ bool foo();
36 __device__ void CheckAllocaIsInEntryBlock() {
37 // CHECK: alloca %printf_args
38 // CHECK: call {{.*}} @_Z3foov()