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 
     12 // CHECK:       define {{.*}}void [[FOO:@.+]]()
     13 
     14 void foo() {}
     15 
     16 // CHECK-LABEL: @main
     17 // TERM_DEBUG-LABEL: @main
     18 int main() {
     19   // CHECK:       [[A_ADDR:%.+]] = alloca i8
     20   char a;
     21 
     22 // CHECK:       [[GTID:%.+]] = call {{.*}}i32 @__kmpc_global_thread_num([[IDENT_T_TY]]* [[DEFAULT_LOC:@.+]])
     23 // CHECK:       [[RES:%.+]] = call {{.*}}i32 @__kmpc_master([[IDENT_T_TY]]* [[DEFAULT_LOC]], i32 [[GTID]])
     24 // CHECK-NEXT:  [[IS_MASTER:%.+]] = icmp ne i32 [[RES]], 0
     25 // CHECK-NEXT:  br i1 [[IS_MASTER]], label {{%?}}[[THEN:.+]], label {{%?}}[[EXIT:.+]]
     26 // CHECK:       [[THEN]]
     27 // CHECK-NEXT:  store i8 2, i8* [[A_ADDR]]
     28 // CHECK-NEXT:  call {{.*}}void @__kmpc_end_master([[IDENT_T_TY]]* [[DEFAULT_LOC]], i32 [[GTID]])
     29 // CHECK-NEXT:  br label {{%?}}[[EXIT]]
     30 // CHECK:       [[EXIT]]
     31 #pragma omp master
     32   a = 2;
     33 // CHECK:       [[RES:%.+]] = call {{.*}}i32 @__kmpc_master([[IDENT_T_TY]]* [[DEFAULT_LOC]], i32 [[GTID]])
     34 // CHECK-NEXT:  [[IS_MASTER:%.+]] = icmp ne i32 [[RES]], 0
     35 // CHECK-NEXT:  br i1 [[IS_MASTER]], label {{%?}}[[THEN:.+]], label {{%?}}[[EXIT:.+]]
     36 // CHECK:       [[THEN]]
     37 // CHECK-NEXT:  invoke {{.*}}void [[FOO]]()
     38 // CHECK:       call {{.*}}void @__kmpc_end_master([[IDENT_T_TY]]* [[DEFAULT_LOC]], i32 [[GTID]])
     39 // CHECK-NEXT:  br label {{%?}}[[EXIT]]
     40 // CHECK:       [[EXIT]]
     41 #pragma omp master
     42   foo();
     43 // CHECK-NOT:   call i32 @__kmpc_master
     44 // CHECK-NOT:   call void @__kmpc_end_master
     45   return a;
     46 }
     47 
     48 // CHECK-LABEL:      parallel_master
     49 // TERM_DEBUG-LABEL: parallel_master
     50 void parallel_master() {
     51 #pragma omp parallel
     52 #pragma omp master
     53   // TERM_DEBUG-NOT: __kmpc_global_thread_num
     54   // TERM_DEBUG:     call i32 @__kmpc_master({{.+}}), !dbg [[DBG_LOC_START:![0-9]+]]
     55   // TERM_DEBUG:     invoke void {{.*}}foo{{.*}}()
     56   // TERM_DEBUG:     unwind label %[[TERM_LPAD:.+]],
     57   // TERM_DEBUG-NOT: __kmpc_global_thread_num
     58   // TERM_DEBUG:     call void @__kmpc_end_master({{.+}}), !dbg [[DBG_LOC_END:![0-9]+]]
     59   // TERM_DEBUG:     [[TERM_LPAD]]
     60   // TERM_DEBUG:     call void @__clang_call_terminate
     61   // TERM_DEBUG:     unreachable
     62   foo();
     63 }
     64 // TERM_DEBUG-DAG: [[DBG_LOC_START]] = !DILocation(line: [[@LINE-12]],
     65 // TERM_DEBUG-DAG: [[DBG_LOC_END]] = !DILocation(line: [[@LINE-3]],
     66 
     67 #endif
     68