[clang][modules] Don't prevent translation of FW_Private includes when explicitly...
[llvm-project.git] / clang / test / CodeGenHIP / printf.cpp
blob8c8b801dbbf56021a5d446666108b747d4fa62c4
1 // REQUIRES: amdgpu-registered-target
2 // RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -x hip -emit-llvm -fcuda-is-device \
3 // RUN: -o - %s | FileCheck --enable-var-scope %s
5 #define __device__ __attribute__((device))
7 extern "C" __device__ int printf(const char *format, ...);
9 __device__ int foo1() {
10 const char *s = "hello world";
11 return printf("%.*f %*.*s %p\n", 8, 3.14159, 8, 4, s, s);
14 // CHECK-LABEL: @_Z4foo1v()
15 // CHECK: [[BEGIN:%.*]] = call i64 @__ockl_printf_begin(i64 0)
16 // CHECK: [[STRLEN1:%.*]] = phi i64 [ %{{[^,]*}}, %{{[^ ]*}} ], [ 0, %{{[^ ]*}} ]
17 // CHECK: [[APPEND1:%.*]] = call i64 @__ockl_printf_append_string_n(i64 [[BEGIN]], {{.*}}, i64 [[STRLEN1]], i32 0)
18 // CHECK: [[APPEND2:%.*]] = call i64 @__ockl_printf_append_args(i64 [[APPEND1]], i32 1, i64 8, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i32 0)
19 // CHECK: [[APPEND3:%.*]] = call i64 @__ockl_printf_append_args(i64 [[APPEND2]], i32 1, i64 4614256650576692846, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i32 0)
20 // CHECK: [[APPEND4:%.*]] = call i64 @__ockl_printf_append_args(i64 [[APPEND3]], i32 1, i64 8, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i32 0)
21 // CHECK: [[APPEND5:%.*]] = call i64 @__ockl_printf_append_args(i64 [[APPEND4]], i32 1, i64 4, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i32 0)
22 // CHECK: [[STRLEN2:%.*]] = phi i64 [ %{{[^,]*}}, %{{[^ ]*}} ], [ 0, %{{[^ ]*}} ]
23 // CHECK: [[APPEND6:%.*]] = call i64 @__ockl_printf_append_string_n(i64 [[APPEND5]], {{.*}}, i64 [[STRLEN2]], i32 0)
24 // CHECK: [[PTR2INT:%.*]] = ptrtoint ptr %{{.*}} to i64
25 // CHECK: [[APPEND7:%.*]] = call i64 @__ockl_printf_append_args(i64 [[APPEND6]], i32 1, i64 [[PTR2INT]], i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i32 1)
26 // CHECK: [[RETURN:%.*]] = trunc i64 [[APPEND7]] to i32
27 // CHECK: ret i32 [[RETURN]]
29 __device__ char *dstr;
31 __device__ int foo2() {
32 return printf("%s %p\n", dstr, dstr);
35 // CHECK-LABEL: @_Z4foo2v()
36 // CHECK: [[BEGIN:%.*]] = call i64 @__ockl_printf_begin(i64 0)
37 // CHECK: [[STRLEN1:%.*]] = phi i64 [ %{{[^,]*}}, %{{[^ ]*}} ], [ 0, %{{[^ ]*}} ]
38 // CHECK: [[APPEND1:%.*]] = call i64 @__ockl_printf_append_string_n(i64 [[BEGIN]], {{.*}}, i64 [[STRLEN1]], i32 0)
39 // CHECK: [[STRLEN2:%.*]] = phi i64 [ %{{[^,]*}}, %{{[^ ]*}} ], [ 0, %{{[^ ]*}} ]
40 // CHECK: [[APPEND2:%.*]] = call i64 @__ockl_printf_append_string_n(i64 [[APPEND1]], {{.*}}, i64 [[STRLEN2]], i32 0)
41 // CHECK: [[PTR2INT:%.*]] = ptrtoint ptr %{{.*}} to i64
42 // CHECK: [[APPEND3:%.*]] = call i64 @__ockl_printf_append_args(i64 [[APPEND2]], i32 1, i64 [[PTR2INT]], i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i32 1)
43 // CHECK: [[RETURN:%.*]] = trunc i64 [[APPEND3]] to i32
44 // CHECK: ret i32 [[RETURN]]