1 // RUN: %clang_cc1 -verify -fopenmp -fopenmp-targets=powerpc64le-ibm-linux-gnu -x c++ -triple powerpc64le-unknown-unknown -emit-llvm %s -o - | FileCheck %s
2 // RUN: %clang_cc1 -fopenmp -fopenmp-targets=powerpc64le-ibm-linux-gnu -x c++ -std=c++11 -triple powerpc64le-unknown-unknown -emit-pch -o %t %s
3 // RUN: %clang_cc1 -fopenmp -fopenmp-targets=powerpc64le-ibm-linux-gnu -x c++ -triple powerpc64le-unknown-unknown -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s
4 // expected-no-diagnostics
5 #ifndef HEADER
6 #define HEADER
7 
8 // CHECK: [[SIZE_ENTER:@.+]] = private unnamed_addr global [2 x i64] [i64 0, i64 24]
9 // 0 = OMP_MAP_NONE
10 // 281474976710656 = 0x1000000000000 = OMP_MAP_MEMBER_OF of 1-st element
11 // CHECK: [[MAP_ENTER:@.+]] = private unnamed_addr constant [2 x i64] [i64 0, i64 281474976710656]
12 // CHECK: [[SIZE_EXIT:@.+]] = private unnamed_addr global [2 x i64] [i64 0, i64 24]
13 // 281474976710664 = 0x1000000000008 = OMP_MAP_MEMBER_OF of 1-st element | OMP_MAP_DELETE
14 // CHECK: [[MAP_EXIT:@.+]] = private unnamed_addr constant [2 x i64] [i64 0, i64 281474976710664]
15 template <typename T>
16 struct S {
17   constexpr static int size = 6;
18   T data[size];
19 };
20 
21 template <typename T>
22 struct maptest {
23   S<T> s;
24   maptest() {
25     // CHECK: [[BPTRS:%.+]] = alloca [2 x i8*],
26     // CHECK: [[PTRS:%.+]] = alloca [2 x i8*],
27     // CHECK: getelementptr inbounds
28     // CHECK: [[S_ADDR:%.+]] = getelementptr inbounds %struct.maptest, %struct.maptest* [[THIS:%.+]], i32 0, i32 0
29     // CHECK: [[S_DATA_ADDR:%.+]] = getelementptr inbounds %struct.S, %struct.S* [[S_ADDR]], i32 0, i32 0
30     // CHECK: [[S_DATA_0_ADDR:%.+]] = getelementptr inbounds [6 x float], [6 x float]* [[S_DATA_ADDR]], i64 0, i64 0
31 
32     // SZ = &this->s.data[6]-&this->s.data[0]
33     // CHECK: [[S_ADDR:%.+]] = getelementptr inbounds %struct.maptest, %struct.maptest* [[THIS]], i32 0, i32 0
34     // CHECK: [[S_DATA_ADDR:%.+]] = getelementptr inbounds %struct.S, %struct.S* [[S_ADDR]], i32 0, i32 0
35     // CHECK: [[S_DATA_5_ADDR:%.+]] = getelementptr inbounds [6 x float], [6 x float]* [[S_DATA_ADDR]], i64 0, i64 5
36     // CHECK: [[S_DATA_6_ADDR:%.+]] = getelementptr float, float* [[S_DATA_5_ADDR]], i32 1
37     // CHECK: [[BEG:%.+]] = bitcast float* [[S_DATA_0_ADDR]] to i8*
38     // CHECK: [[END:%.+]] = bitcast float* [[S_DATA_6_ADDR]] to i8*
39     // CHECK: [[END_BC:%.+]] = ptrtoint i8* [[END]] to i64
40     // CHECK: [[BEG_BC:%.+]] = ptrtoint i8* [[BEG]] to i64
41     // CHECK: [[DIFF:%.+]] = sub i64 [[END_BC]], [[BEG_BC]]
42     // CHECK: [[SZ:%.+]] = sdiv exact i64 [[DIFF]], ptrtoint (i8* getelementptr (i8, i8* null, i32 1) to i64)
43 
44     // Fill mapping arrays
45     // CHECK: [[BPTR0:%.+]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[BPTRS]], i32 0, i32 0
46     // CHECK: [[BPTR0_THIS:%.+]] = bitcast i8** [[BPTR0]] to %struct.maptest**
47     // CHECK: store %struct.maptest* [[THIS]], %struct.maptest** [[BPTR0_THIS]],
48     // CHECK: [[PTR0:%.+]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[PTRS]], i32 0, i32 0
49     // CHECK: [[PTR0_DATA:%.+]] = bitcast i8** [[PTR0]] to float**
50     // CHECK: store float* [[S_DATA_0_ADDR]], float** [[PTR0_DATA]],
51     // CHECK: store i64 [[SZ]], i64* getelementptr inbounds ([2 x i64], [2 x i64]* [[SIZE_ENTER]], i32 0, i32 0),
52     // CHECK: [[BPTR1:%.+]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[BPTRS]], i32 0, i32 1
53     // CHECK: [[BPTR1_THIS:%.+]] = bitcast i8** [[BPTR1]] to %struct.maptest**
54     // CHECK: store %struct.maptest* [[THIS]], %struct.maptest** [[BPTR1_THIS]],
55     // CHECK: [[PTR1:%.+]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[PTRS]], i32 0, i32 1
56     // CHECK: [[PTR1_DATA:%.+]] = bitcast i8** [[PTR1]] to float**
57     // CHECK: store float* [[S_DATA_0_ADDR]], float** [[PTR1_DATA]],
58     // CHECK: [[BPTR:%.+]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[BPTRS]], i32 0, i32 0
59     // CHECK: [[PTR:%.+]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[PTRS]], i32 0, i32 0
60     // CHECK: call void @__tgt_target_data_begin_mapper(%struct.ident_t* @{{.+}}, i64 -1, i32 2, i8** [[BPTR]], i8** [[PTR]], i64* getelementptr inbounds ([2 x i64], [2 x i64]* [[SIZE_ENTER]], i32 0, i32 0), i64* getelementptr inbounds ([2 x i64], [2 x i64]* [[MAP_ENTER]], i32 0, i32 0), i8** null, i8** null)
61 #pragma omp target enter data map(alloc : s.data[:6])
62   }
63 
64   ~maptest() {
65     // CHECK: [[BPTRS:%.+]] = alloca [2 x i8*],
66     // CHECK: [[PTRS:%.+]] = alloca [2 x i8*],
67     // CHECK: [[S_ADDR:%.+]] = getelementptr inbounds %struct.maptest, %struct.maptest* [[THIS:%.+]], i32 0, i32 0
68     // CHECK: [[S_DATA_ADDR:%.+]] = getelementptr inbounds %struct.S, %struct.S* [[S_ADDR]], i32 0, i32 0
69     // CHECK: [[S_DATA_0_ADDR:%.+]] = getelementptr inbounds [6 x float], [6 x float]* [[S_DATA_ADDR]], i64 0, i64 0
70 
71     // SZ = &this->s.data[6]-&this->s.data[0]
72     // CHECK: [[S_ADDR:%.+]] = getelementptr inbounds %struct.maptest, %struct.maptest* [[THIS]], i32 0, i32 0
73     // CHECK: [[S_DATA_ADDR:%.+]] = getelementptr inbounds %struct.S, %struct.S* [[S_ADDR]], i32 0, i32 0
74     // CHECK: [[S_DATA_5_ADDR:%.+]] = getelementptr inbounds [6 x float], [6 x float]* [[S_DATA_ADDR]], i64 0, i64 5
75     // CHECK: [[S_DATA_6_ADDR:%.+]] = getelementptr float, float* [[S_DATA_5_ADDR]], i32 1
76     // CHECK: [[BEG:%.+]] = bitcast float* [[S_DATA_0_ADDR]] to i8*
77     // CHECK: [[END:%.+]] = bitcast float* [[S_DATA_6_ADDR]] to i8*
78     // CHECK: [[END_BC:%.+]] = ptrtoint i8* [[END]] to i64
79     // CHECK: [[BEG_BC:%.+]] = ptrtoint i8* [[BEG]] to i64
80     // CHECK: [[DIFF:%.+]] = sub i64 [[END_BC]], [[BEG_BC]]
81     // CHECK: [[SZ:%.+]] = sdiv exact i64 [[DIFF]], ptrtoint (i8* getelementptr (i8, i8* null, i32 1) to i64)
82 
83     // Fill mapping arrays
84     // CHECK: [[BPTR0:%.+]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[BPTRS]], i32 0, i32 0
85     // CHECK: [[BPTR0_THIS:%.+]] = bitcast i8** [[BPTR0]] to %struct.maptest**
86     // CHECK: store %struct.maptest* [[THIS]], %struct.maptest** [[BPTR0_THIS]],
87     // CHECK: [[PTR0:%.+]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[PTRS]], i32 0, i32 0
88     // CHECK: [[PTR0_DATA:%.+]] = bitcast i8** [[PTR0]] to float**
89     // CHECK: store float* [[S_DATA_0_ADDR]], float** [[PTR0_DATA]],
90     // CHECK: store i64 [[SZ]], i64* getelementptr inbounds ([2 x i64], [2 x i64]* [[SIZE_EXIT]], i32 0, i32 0),
91     // CHECK: [[BPTR1:%.+]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[BPTRS]], i32 0, i32 1
92     // CHECK: [[BPTR1_THIS:%.+]] = bitcast i8** [[BPTR1]] to %struct.maptest**
93     // CHECK: store %struct.maptest* [[THIS]], %struct.maptest** [[BPTR1_THIS]],
94     // CHECK: [[PTR1:%.+]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[PTRS]], i32 0, i32 1
95     // CHECK: [[PTR1_DATA:%.+]] = bitcast i8** [[PTR1]] to float**
96     // CHECK: store float* [[S_DATA_0_ADDR]], float** [[PTR1_DATA]],
97     // CHECK: [[BPTR:%.+]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[BPTRS]], i32 0, i32 0
98     // CHECK: [[PTR:%.+]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[PTRS]], i32 0, i32 0
99     // CHECK: call void @__tgt_target_data_end_mapper(%struct.ident_t* @{{.+}}, i64 -1, i32 2, i8** [[BPTR]], i8** [[PTR]], i64* getelementptr inbounds ([2 x i64], [2 x i64]* [[SIZE_EXIT]], i32 0, i32 0), i64* getelementptr inbounds ([2 x i64], [2 x i64]* [[MAP_EXIT]], i32 0, i32 0), i8** null, i8** null)
100 #pragma omp target exit data map(delete : s.data[:6])
101   }
102 };
103 
104 maptest<float> a;
105 
106 #endif
107