1 // RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -fopenmp -fexceptions -fcxx-exceptions -x c++ -emit-llvm %s -o - | FileCheck %s
2 // RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -fopenmp -fexceptions -fcxx-exceptions -debug-info-kind=line-tables-only -x c++ -emit-llvm %s -o - | FileCheck %s --check-prefix=TERM_DEBUG
3 // expected-no-diagnostics
4
5 int a;
6 int b;
7
8 struct St {
9 unsigned long field;
StSt10 St() {}
~StSt11 ~St() {}
getSt12 int &get() { return a; }
13 };
14
15 // CHECK-LABEL: parallel_atomic_ewc
parallel_atomic_ewc()16 void parallel_atomic_ewc() {
17 St s;
18 #pragma omp parallel
19 {
20 // CHECK: invoke void @_ZN2StC1Ev(%struct.St* [[TEMP_ST_ADDR:%.+]])
21 // CHECK: [[SCALAR_ADDR:%.+]] = invoke dereferenceable(4) i32* @_ZN2St3getEv(%struct.St* [[TEMP_ST_ADDR]])
22 // CHECK: [[SCALAR_VAL:%.+]] = load atomic i32, i32* [[SCALAR_ADDR]] monotonic
23 // CHECK: store i32 [[SCALAR_VAL]], i32* @b
24 // CHECK: invoke void @_ZN2StD1Ev(%struct.St* [[TEMP_ST_ADDR]])
25 #pragma omp atomic read
26 b = St().get();
27 // CHECK-DAG: invoke void @_ZN2StC1Ev(%struct.St* [[TEMP_ST_ADDR:%.+]])
28 // CHECK-DAG: [[SCALAR_ADDR:%.+]] = invoke dereferenceable(4) i32* @_ZN2St3getEv(%struct.St* [[TEMP_ST_ADDR]])
29 // CHECK-DAG: [[B_VAL:%.+]] = load i32, i32* @b
30 // CHECK: store atomic i32 [[B_VAL]], i32* [[SCALAR_ADDR]] monotonic
31 // CHECK: invoke void @_ZN2StD1Ev(%struct.St* [[TEMP_ST_ADDR]])
32 #pragma omp atomic write
33 St().get() = b;
34 // CHECK: invoke void @_ZN2StC1Ev(%struct.St* [[TEMP_ST_ADDR:%.+]])
35 // CHECK: [[SCALAR_ADDR:%.+]] = invoke dereferenceable(4) i32* @_ZN2St3getEv(%struct.St* [[TEMP_ST_ADDR]])
36 // CHECK: [[B_VAL:%.+]] = load i32, i32* @b
37 // CHECK: [[OLD_VAL:%.+]] = load atomic i32, i32* [[SCALAR_ADDR]] monotonic,
38 // CHECK: br label %[[OMP_UPDATE:.+]]
39 // CHECK: [[OMP_UPDATE]]
40 // CHECK: [[OLD_PHI_VAL:%.+]] = phi i32 [ [[OLD_VAL]], %{{.+}} ], [ [[NEW_OLD_VAL:%.+]], %[[OMP_UPDATE]] ]
41 // CHECK: [[NEW_VAL:%.+]] = srem i32 [[OLD_PHI_VAL]], [[B_VAL]]
42 // CHECK: store i32 [[NEW_VAL]], i32* [[TEMP:%.+]],
43 // CHECK: [[NEW_VAL:%.+]] = load i32, i32* [[TEMP]],
44 // CHECK: [[RES:%.+]] = cmpxchg i32* [[SCALAR_ADDR]], i32 [[OLD_PHI_VAL]], i32 [[NEW_VAL]] monotonic monotonic
45 // CHECK: [[NEW_OLD_VAL]] = extractvalue { i32, i1 } [[RES]], 0
46 // CHECK: [[COND:%.+]] = extractvalue { i32, i1 } [[RES]], 1
47 // CHECK: br i1 [[COND]], label %[[OMP_DONE:.+]], label %[[OMP_UPDATE]]
48 // CHECK: [[OMP_DONE]]
49 // CHECK: invoke void @_ZN2StD1Ev(%struct.St* [[TEMP_ST_ADDR]])
50 #pragma omp atomic
51 St().get() %= b;
52 #pragma omp atomic
53 s.field++;
54 // CHECK: invoke void @_ZN2StC1Ev(%struct.St* [[TEMP_ST_ADDR:%.+]])
55 // CHECK: [[SCALAR_ADDR:%.+]] = invoke dereferenceable(4) i32* @_ZN2St3getEv(%struct.St* [[TEMP_ST_ADDR]])
56 // CHECK: [[B_VAL:%.+]] = load i32, i32* @b
57 // CHECK: [[OLD_VAL:%.+]] = load atomic i32, i32* [[SCALAR_ADDR]] monotonic,
58 // CHECK: br label %[[OMP_UPDATE:.+]]
59 // CHECK: [[OMP_UPDATE]]
60 // CHECK: [[OLD_PHI_VAL:%.+]] = phi i32 [ [[OLD_VAL]], %{{.+}} ], [ [[NEW_OLD_VAL:%.+]], %[[OMP_UPDATE]] ]
61 // CHECK: [[NEW_CALC_VAL:%.+]] = srem i32 [[OLD_PHI_VAL]], [[B_VAL]]
62 // CHECK: store i32 [[NEW_CALC_VAL]], i32* [[TEMP:%.+]],
63 // CHECK: [[NEW_VAL:%.+]] = load i32, i32* [[TEMP]],
64 // CHECK: [[RES:%.+]] = cmpxchg i32* [[SCALAR_ADDR]], i32 [[OLD_PHI_VAL]], i32 [[NEW_VAL]] monotonic monotonic
65 // CHECK: [[NEW_OLD_VAL]] = extractvalue { i32, i1 } [[RES]], 0
66 // CHECK: [[COND:%.+]] = extractvalue { i32, i1 } [[RES]], 1
67 // CHECK: br i1 [[COND]], label %[[OMP_DONE:.+]], label %[[OMP_UPDATE]]
68 // CHECK: [[OMP_DONE]]
69 // CHECK: store i32 [[NEW_CALC_VAL]], i32* @a,
70 // CHECK: invoke void @_ZN2StD1Ev(%struct.St* [[TEMP_ST_ADDR]])
71 #pragma omp atomic capture
72 a = St().get() %= b;
73 }
74 }
75
foo()76 int &foo() { return a; }
77
78 // TERM_DEBUG-LABEL: parallel_atomic
parallel_atomic()79 void parallel_atomic() {
80 #pragma omp parallel
81 {
82 #pragma omp atomic read
83 // TERM_DEBUG-NOT: __kmpc_global_thread_num
84 // TERM_DEBUG: invoke {{.*}}foo{{.*}}()
85 // TERM_DEBUG: unwind label %[[TERM_LPAD:.+]],
86 // TERM_DEBUG: load atomic i32, i32* @{{.+}} monotonic, {{.*}}!dbg [[READ_LOC:![0-9]+]]
87 foo() = a;
88 #pragma omp atomic write
89 // TERM_DEBUG-NOT: __kmpc_global_thread_num
90 // TERM_DEBUG: invoke {{.*}}foo{{.*}}()
91 // TERM_DEBUG: unwind label %[[TERM_LPAD:.+]],
92 // TERM_DEBUG-NOT: __kmpc_global_thread_num
93 // TERM_DEBUG: store atomic i32 {{%.+}}, i32* @{{.+}} monotonic, {{.*}}!dbg [[WRITE_LOC:![0-9]+]]
94 a = foo();
95 #pragma omp atomic update
96 // TERM_DEBUG-NOT: __kmpc_global_thread_num
97 // TERM_DEBUG: invoke {{.*}}foo{{.*}}()
98 // TERM_DEBUG: unwind label %[[TERM_LPAD:.+]],
99 // TERM_DEBUG-NOT: __kmpc_global_thread_num
100 // TERM_DEBUG: atomicrmw add i32* @{{.+}}, i32 %{{.+}} monotonic, {{.*}}!dbg [[UPDATE_LOC:![0-9]+]]
101 a += foo();
102 #pragma omp atomic capture
103 // TERM_DEBUG-NOT: __kmpc_global_thread_num
104 // TERM_DEBUG: invoke {{.*}}foo{{.*}}()
105 // TERM_DEBUG: unwind label %[[TERM_LPAD:.+]],
106 // TERM_DEBUG-NOT: __kmpc_global_thread_num
107 // TERM_DEBUG: [[OLD_VAL:%.+]] = atomicrmw add i32* @{{.+}}, i32 %{{.+}} monotonic, {{.*}}!dbg [[CAPTURE_LOC:![0-9]+]]
108 // TERM_DEBUG: store i32 [[OLD_VAL]], i32* @b,
109 {b = a; a += foo(); }
110 }
111 // TERM_DEBUG: [[TERM_LPAD]]
112 // TERM_DEBUG: call void @__clang_call_terminate
113 // TERM_DEBUG: unreachable
114 }
115 // TERM_DEBUG-DAG: [[READ_LOC]] = !DILocation(line: [[@LINE-28]],
116 // TERM_DEBUG-DAG: [[WRITE_LOC]] = !DILocation(line: [[@LINE-22]],
117 // TERM_DEBUG-DAG: [[UPDATE_LOC]] = !DILocation(line: [[@LINE-16]],
118 // TERM_DEBUG-DAG: [[CAPTURE_LOC]] = !DILocation(line: [[@LINE-9]],
119