1 // RUN: %clang_cc1 -verify -fopenmp -x c++ -triple %itanium_abi_triple -emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck %s
2 // RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple %itanium_abi_triple -fexceptions -fcxx-exceptions -emit-pch -o %t %s
3 // RUN: %clang_cc1 -fopenmp -x c++ -triple %itanium_abi_triple -fexceptions -fcxx-exceptions -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 typedef __INTPTR_TYPE__ intptr_t;
9 
10 // CHECK-DAG: [[IDENT_T_TY:%.+]] = type { i32, i32, i32, i32, i8* }
11 // CHECK-DAG: [[S_TY:%.+]] = type { [[INTPTR_T_TY:i[0-9]+]], [[INTPTR_T_TY]], [[INTPTR_T_TY]] }
12 // CHECK-DAG: [[STR:@.+]] = private unnamed_addr constant [23 x i8] c";unknown;unknown;0;0;;\00"
13 // CHECK-DAG: [[DEF_LOC_2:@.+]] = private unnamed_addr constant [[IDENT_T_TY]] { i32 0, i32 2, i32 0, i32 0, i8* getelementptr inbounds ([23 x i8], [23 x i8]* [[STR]], i32 0, i32 0) }
14 
15 void foo();
16 
17 struct S {
18   intptr_t a, b, c;
SS19   S(intptr_t a) : a(a) {}
operator charS20   operator char() { return a; }
~SS21   ~S() {}
22 };
23 
24 template <typename T, int C>
tmain()25 int tmain() {
26 #pragma omp parallel num_threads(C)
27   foo();
28 #pragma omp parallel num_threads(T(23))
29   foo();
30   return 0;
31 }
32 
main()33 int main() {
34   S s(0);
35   char a = s;
36 #pragma omp parallel num_threads(2)
37   foo();
38 #pragma omp parallel num_threads(a)
39   foo();
40   return a + tmain<char, 5>() + tmain<S, 1>();
41 }
42 
43 // CHECK-LABEL: define {{.*}}i{{[0-9]+}} @main()
44 // CHECK-DAG:   [[S_ADDR:%.+]] = alloca [[S_TY]]
45 // CHECK-DAG:   [[A_ADDR:%.+]] = alloca i8
46 // CHECK-DAG:   [[GTID:%.+]] = call {{.*}}i32 @__kmpc_global_thread_num([[IDENT_T_TY]]* [[DEF_LOC_2]])
47 // CHECK-DAG:   call {{.*}} [[S_TY_CONSTR:@.+]]([[S_TY]]* [[S_ADDR]], [[INTPTR_T_TY]] [[INTPTR_T_TY_ATTR:(signext )?]]0)
48 // CHECK:       [[S_CHAR_OP:%.+]] = invoke{{.*}} i8 [[S_TY_CHAR_OP:@.+]]([[S_TY]]* [[S_ADDR]])
49 // CHECK:       store i8 [[S_CHAR_OP]], i8* [[A_ADDR]]
50 // CHECK:       call {{.*}}void @__kmpc_push_num_threads([[IDENT_T_TY]]* [[DEF_LOC_2]], i32 [[GTID]], i32 2)
51 // CHECK:       call {{.*}}void {{.*}} @__kmpc_fork_call(
52 // CHECK:       [[A_VAL:%.+]] = load i8, i8* [[A_ADDR]]
53 // CHECK:       [[RES:%.+]] = sext i8 [[A_VAL]] to i32
54 // CHECK:       call {{.*}}void @__kmpc_push_num_threads([[IDENT_T_TY]]* [[DEF_LOC_2]], i32 [[GTID]], i32 [[RES]])
55 // CHECK:       call {{.*}}void {{.*}} @__kmpc_fork_call(
56 // CHECK:       invoke{{.*}} [[INT_TY:i[0-9]+]] [[TMAIN_CHAR_5:@.+]]()
57 // CHECK:       invoke{{.*}} [[INT_TY]] [[TMAIN_S_1:@.+]]()
58 // CHECK:       call {{.*}} [[S_TY_DESTR:@.+]]([[S_TY]]* [[S_ADDR]])
59 // CHECK:       ret [[INT_TY]]
60 // CHECK:       }
61 
62 // CHECK:       define{{.*}} [[INT_TY]] [[TMAIN_CHAR_5]]()
63 // CHECK:       [[GTID:%.+]] = call {{.*}}i32 @__kmpc_global_thread_num([[IDENT_T_TY]]* [[DEF_LOC_2]])
64 // CHECK:       call {{.*}}void @__kmpc_push_num_threads([[IDENT_T_TY]]* [[DEF_LOC_2]], i32 [[GTID]], i32 5)
65 // CHECK:       call {{.*}}void {{.*}} @__kmpc_fork_call(
66 // CHECK:       call {{.*}}void @__kmpc_push_num_threads([[IDENT_T_TY]]* [[DEF_LOC_2]], i32 [[GTID]], i32 23)
67 // CHECK:       call {{.*}}void {{.*}} @__kmpc_fork_call(
68 // CHECK:       ret [[INT_TY]] 0
69 // CHECK-NEXT:  }
70 
71 // CHECK:       define{{.*}} [[INT_TY]] [[TMAIN_S_1]]()
72 // CHECK:       [[GTID:%.+]] = call {{.*}}i32 @__kmpc_global_thread_num([[IDENT_T_TY]]* [[DEF_LOC_2]])
73 // CHECK:       call {{.*}}void @__kmpc_push_num_threads([[IDENT_T_TY]]* [[DEF_LOC_2]], i32 [[GTID]], i32 1)
74 // CHECK:       call {{.*}}void {{.*}} @__kmpc_fork_call(
75 // CHECK:       call {{.*}} [[S_TY_CONSTR]]([[S_TY]]* [[S_TEMP:%.+]], [[INTPTR_T_TY]] [[INTPTR_T_TY_ATTR]]23)
76 // CHECK:       [[S_CHAR_OP:%.+]] = invoke{{.*}} i8 [[S_TY_CHAR_OP]]([[S_TY]]* [[S_TEMP]])
77 // CHECK:       [[RES:%.+]] = sext {{.*}}i8 [[S_CHAR_OP]] to i32
78 // CHECK:       call {{.*}}void @__kmpc_push_num_threads([[IDENT_T_TY]]* [[DEF_LOC_2]], i32 [[GTID]], i32 [[RES]])
79 // CHECK:       call {{.*}} [[S_TY_DESTR]]([[S_TY]]* [[S_TEMP]])
80 // CHECK:       call {{.*}}void {{.*}} @__kmpc_fork_call(
81 // CHECK:       ret [[INT_TY]] 0
82 // CHECK:       }
83 
84 #endif
85