Home | History | Annotate | Download | only in OpenMP
      1 // RUN: %clang_cc1 -verify -fopenmp -x c++ -emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck %s
      2 // RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s
      3 // RUN: %clang_cc1 -fopenmp -x c++ -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s
      4 // 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
      5 // expected-no-diagnostics
      6 // REQUIRES: x86-registered-target
      7 #ifndef HEADER
      8 #define HEADER
      9 
     10 // CHECK:       [[IDENT_T_TY:%.+]] = type { i32, i32, i32, i32, i8* }
     11 // CHECK:       [[UNNAMED_LOCK:@.+]] = common global [8 x i32] zeroinitializer
     12 // CHECK:       [[THE_NAME_LOCK:@.+]] = common global [8 x i32] zeroinitializer
     13 // CHECK:       [[THE_NAME_LOCK1:@.+]] = common global [8 x i32] zeroinitializer
     14 
     15 // CHECK:       define {{.*}}void [[FOO:@.+]]()
     16 
     17 void foo() {}
     18 
     19 // CHECK-LABEL: @main
     20 // TERM_DEBUG-LABEL: @main
     21 int main() {
     22 // CHECK:       [[A_ADDR:%.+]] = alloca i8
     23   char a;
     24 
     25 // CHECK:       [[GTID:%.+]] = call {{.*}}i32 @__kmpc_global_thread_num([[IDENT_T_TY]]* [[DEFAULT_LOC:@.+]])
     26 // CHECK:       call {{.*}}void @__kmpc_critical([[IDENT_T_TY]]* [[DEFAULT_LOC]], i32 [[GTID]], [8 x i32]* [[UNNAMED_LOCK]])
     27 // CHECK-NEXT:  store i8 2, i8* [[A_ADDR]]
     28 // CHECK-NEXT:  call {{.*}}void @__kmpc_end_critical([[IDENT_T_TY]]* [[DEFAULT_LOC]], i32 [[GTID]], [8 x i32]* [[UNNAMED_LOCK]])
     29 #pragma omp critical
     30   a = 2;
     31 // CHECK:       call {{.*}}void @__kmpc_critical([[IDENT_T_TY]]* [[DEFAULT_LOC]], i32 [[GTID]], [8 x i32]* [[THE_NAME_LOCK]])
     32 // CHECK-NEXT:  invoke {{.*}}void [[FOO]]()
     33 // CHECK:       call {{.*}}void @__kmpc_end_critical([[IDENT_T_TY]]* [[DEFAULT_LOC]], i32 [[GTID]], [8 x i32]* [[THE_NAME_LOCK]])
     34 #pragma omp critical(the_name)
     35   foo();
     36 // CHECK:       call {{.*}}void @__kmpc_critical_with_hint([[IDENT_T_TY]]* [[DEFAULT_LOC]], i32 [[GTID]], [8 x i32]* [[THE_NAME_LOCK1]], i{{64|32}} 23)
     37 // CHECK-NEXT:  invoke {{.*}}void [[FOO]]()
     38 // CHECK:       call {{.*}}void @__kmpc_end_critical([[IDENT_T_TY]]* [[DEFAULT_LOC]], i32 [[GTID]], [8 x i32]* [[THE_NAME_LOCK1]])
     39 #pragma omp critical(the_name1) hint(23)
     40   foo();
     41 // CHECK:       call {{.*}}void @__kmpc_critical([[IDENT_T_TY]]* [[DEFAULT_LOC]], i32 [[GTID]], [8 x i32]* [[THE_NAME_LOCK]])
     42 // CHECK-NOT:   call {{.*}}void @__kmpc_end_critical(
     43   if (a)
     44 #pragma omp critical(the_name)
     45     while (1)
     46       ;
     47 // CHECK:  call {{.*}}void [[FOO]]()
     48   foo();
     49 // CHECK-NOT:   call void @__kmpc_critical
     50 // CHECK-NOT:   call void @__kmpc_end_critical
     51   return a;
     52 }
     53 
     54 struct S {
     55   int a;
     56 };
     57 // CHECK-LABEL: critical_ref
     58 void critical_ref(S &s) {
     59   // CHECK: [[S_ADDR:%.+]] = alloca %struct.S*,
     60   // CHECK: [[S_REF:%.+]] = load %struct.S*, %struct.S** [[S_ADDR]],
     61   // CHECK: [[S_A_REF:%.+]] = getelementptr inbounds %struct.S, %struct.S* [[S_REF]], i32 0, i32 0
     62   ++s.a;
     63   // CHECK: call void @__kmpc_critical(
     64 #pragma omp critical
     65   // CHECK: [[S_REF:%.+]] = load %struct.S*, %struct.S** [[S_ADDR]],
     66   // CHECK: [[S_A_REF:%.+]] = getelementptr inbounds %struct.S, %struct.S* [[S_REF]], i32 0, i32 0
     67   ++s.a;
     68   // CHECK: call void @__kmpc_end_critical(
     69 }
     70 
     71 // CHECK-LABEL:      parallel_critical
     72 // TERM_DEBUG-LABEL: parallel_critical
     73 void parallel_critical() {
     74 #pragma omp parallel
     75 #pragma omp critical
     76   // TERM_DEBUG-NOT: __kmpc_global_thread_num
     77   // TERM_DEBUG:     call void @__kmpc_critical({{.+}}), !dbg [[DBG_LOC_START:![0-9]+]]
     78   // TERM_DEBUG:     invoke void {{.*}}foo{{.*}}()
     79   // TERM_DEBUG:     unwind label %[[TERM_LPAD:.+]],
     80   // TERM_DEBUG-NOT: __kmpc_global_thread_num
     81   // TERM_DEBUG:     call void @__kmpc_end_critical({{.+}}), !dbg [[DBG_LOC_END:![0-9]+]]
     82   // TERM_DEBUG:     [[TERM_LPAD]]
     83   // TERM_DEBUG:     call void @__clang_call_terminate
     84   // TERM_DEBUG:     unreachable
     85   foo();
     86 }
     87 // TERM_DEBUG-DAG: [[DBG_LOC_START]] = !DILocation(line: [[@LINE-12]],
     88 // TERM_DEBUG-DAG: [[DBG_LOC_END]] = !DILocation(line: [[@LINE-3]],
     89 #endif
     90