1 // RUN: %clang_cc1 -std=c++14 -triple amdgcn-amd-amdhsa \
2 // RUN: -fcuda-is-device -emit-llvm -o - -x hip %s | FileCheck %s
3 // RUN: %clang_cc1 -std=c++14 -triple amdgcn-amd-amdhsa \
4 // RUN: -fcuda-is-device -emit-llvm -o - -x hip %s | FileCheck -check-prefix=NEG %s
6 #include "Inputs/cuda.h"
12 // Check the situation of B<T> has empty ctor but B<int> has non-empty ctor.
13 // Make sure const B<int> variables are not promoted to constant variables.
26 static const B<int> y;
32 const B<int> B<int>::y;
39 // Check template variable with empty default ctor but non-empty initializer
40 // ctor is not promoted.
42 const B<T> b = B<T>(-1);
44 constexpr int constexpr_var = 1;
45 constexpr A constexpr_struct{2};
46 constexpr A constexpr_array[4] = {0, 0, 0, 3};
47 constexpr char constexpr_str[] = "abcd";
48 const int const_var = 4;
49 const A const_struct{5};
50 const A const_array[] = {0, 0, 0, 6};
51 const char const_str[] = "xyz";
53 // Check const variables used by host only are not emitted.
54 const int var_host_only = 7;
56 // CHECK-DAG: @_ZL13constexpr_str.const = private unnamed_addr addrspace(4) constant [5 x i8] c"abcd\00"
57 // CHECK-DAG: @_ZL13constexpr_var = internal addrspace(4) constant i32 1
58 // CHECK-DAG: @_ZL16constexpr_struct = internal addrspace(4) constant %struct.A { i32 2 }
59 // CHECK-DAG: @_ZL15constexpr_array = internal addrspace(4) constant [4 x %struct.A] [%struct.A zeroinitializer, %struct.A zeroinitializer, %struct.A zeroinitializer, %struct.A { i32 3 }]
60 // CHECK-DAG: @_ZL9const_var = internal addrspace(4) constant i32 4
61 // CHECK-DAG: @_ZL12const_struct = internal addrspace(4) constant %struct.A { i32 5 }
62 // CHECK-DAG: @_ZL11const_array = internal addrspace(4) constant [4 x %struct.A] [%struct.A zeroinitializer, %struct.A zeroinitializer, %struct.A zeroinitializer, %struct.A { i32 6 }]
63 // CHECK-DAG: @_ZL9const_str = internal addrspace(4) constant [4 x i8] c"xyz\00"
65 // NEG-NOT: @_ZN1BIiE1yE
67 // NEG-NOT: @_ZL13var_host_only
68 // NEG-NOT: {{^}}@{{.*}} = external
70 // CHECK-LABEL: define{{.*}}@_Z7dev_funPiPPKi
74 // CHECK: load i8, ptr getelementptr {{.*}} @_ZL13constexpr_str.const
78 // CHECK: load i8, ptr getelementptr {{.*}} @_ZL9const_str
79 // CHECK: store ptr {{.*}}@_ZL13constexpr_var
80 // CHECK: store ptr {{.*}} @_ZL16constexpr_struct
81 // CHECK: store ptr getelementptr {{.*}} @_ZL15constexpr_array
82 // CHECK: store ptr {{.*}}@_ZL9const_var
83 // CHECK: store ptr {{.*}} @_ZL12const_struct
84 // CHECK: store ptr getelementptr {{.*}} @_ZL11const_array
85 __device__ void dev_fun(int *out, const int **out2) {
87 *out = constexpr_struct.x;
88 *out = constexpr_array[3].x;
89 *out = constexpr_str[3];
91 *out = const_struct.x;
92 *out = const_array[3].x;
94 *out2 = &constexpr_var;
95 *out2 = &constexpr_struct.x;
96 *out2 = &constexpr_array[3].x;
98 *out2 = &const_struct.x;
99 *out2 = &const_array[3].x;
105 (void) var_host_only;