[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / OpenMP / bug54082.c
blob337c120983e0a3603622b526f3584d201217f66c
1 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --function-signature --include-generated-funcs --prefix-filecheck-ir-name _
2 // RUN: %clang_cc1 -fopenmp -O1 -x c -triple x86_64-apple-darwin10 -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK
4 typedef enum omp_allocator_handle_t {
5 omp_null_allocator = 0,
6 omp_default_mem_alloc = 1,
7 omp_large_cap_mem_alloc = 2,
8 omp_const_mem_alloc = 3,
9 omp_high_bw_mem_alloc = 4,
10 omp_low_lat_mem_alloc = 5,
11 omp_cgroup_mem_alloc = 6,
12 omp_pteam_mem_alloc = 7,
13 omp_thread_mem_alloc = 8,
14 KMP_ALLOCATOR_MAX_HANDLE = __UINTPTR_MAX__
15 } omp_allocator_handle_t;
17 typedef enum omp_memspace_handle_t {
18 omp_default_mem_space = 0,
19 omp_large_cap_mem_space = 1,
20 omp_const_mem_space = 2,
21 omp_high_bw_mem_space = 3,
22 omp_low_lat_mem_space = 4,
23 llvm_omp_target_host_mem_space = 100,
24 llvm_omp_target_shared_mem_space = 101,
25 llvm_omp_target_device_mem_space = 102,
26 KMP_MEMSPACE_MAX_HANDLE = __UINTPTR_MAX__
27 } omp_memspace_handle_t;
29 typedef enum {
30 omp_atk_sync_hint = 1,
31 omp_atk_alignment = 2,
32 omp_atk_access = 3,
33 omp_atk_pool_size = 4,
34 omp_atk_fallback = 5,
35 omp_atk_fb_data = 6,
36 omp_atk_pinned = 7,
37 omp_atk_partition = 8
38 } omp_alloctrait_key_t;
40 typedef __UINTPTR_TYPE__ omp_uintptr_t;
41 typedef __SIZE_TYPE__ size_t;
43 typedef struct {
44 omp_alloctrait_key_t key;
45 omp_uintptr_t value;
46 } omp_alloctrait_t;
48 extern omp_allocator_handle_t
49 omp_init_allocator(omp_memspace_handle_t memspace, int ntraits,
50 const omp_alloctrait_t traits[]);
52 #define N 1024
54 void foo() {
55 int *x;
57 omp_memspace_handle_t x_memspace = omp_default_mem_space;
58 omp_alloctrait_t x_traits[1] = {omp_atk_alignment, 64};
59 omp_allocator_handle_t x_alloc = omp_init_allocator(x_memspace, 1, x_traits);
61 #pragma omp parallel for allocate(x_alloc : x) private(x)
62 for (int i = 0; i < N; i++) {
63 (void)x;
66 // CHECK-LABEL: define {{[^@]+}}@foo
67 // CHECK-SAME: () local_unnamed_addr #[[ATTR0:[0-9]+]] {
68 // CHECK-NEXT: entry:
69 // CHECK-NEXT: [[X_TRAITS:%.*]] = alloca [1 x %struct.omp_alloctrait_t], align 16
70 // CHECK-NEXT: [[X_ALLOC:%.*]] = alloca i64, align 8
71 // CHECK-NEXT: call void @llvm.lifetime.start.p0(i64 16, ptr nonnull [[X_TRAITS]]) #[[ATTR5:[0-9]+]]
72 // CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(16) [[X_TRAITS]], ptr noundef nonnull align 16 dereferenceable(16) @__const.foo.x_traits, i64 16, i1 false)
73 // CHECK-NEXT: call void @llvm.lifetime.start.p0(i64 8, ptr nonnull [[X_ALLOC]]) #[[ATTR5]]
74 // CHECK-NEXT: [[CALL:%.*]] = call i64 @omp_init_allocator(i64 noundef 0, i32 noundef 1, ptr noundef nonnull [[X_TRAITS]]) #[[ATTR5]]
75 // CHECK-NEXT: store i64 [[CALL]], ptr [[X_ALLOC]], align 8, !tbaa [[TBAA3:![0-9]+]]
76 // CHECK-NEXT: call void (ptr, i32, ptr, ...) @__kmpc_fork_call(ptr nonnull @[[GLOB2:[0-9]+]], i32 1, ptr nonnull @foo.omp_outlined, ptr nonnull [[X_ALLOC]])
77 // CHECK-NEXT: call void @llvm.lifetime.end.p0(i64 8, ptr nonnull [[X_ALLOC]]) #[[ATTR5]]
78 // CHECK-NEXT: call void @llvm.lifetime.end.p0(i64 16, ptr nonnull [[X_TRAITS]]) #[[ATTR5]]
79 // CHECK-NEXT: ret void
82 // CHECK-LABEL: define {{[^@]+}}@foo.omp_outlined
83 // CHECK-SAME: (ptr noalias nocapture noundef readonly [[DOTGLOBAL_TID_:%.*]], ptr noalias nocapture readnone [[DOTBOUND_TID_:%.*]], ptr nocapture noundef nonnull readonly align 8 dereferenceable(8) [[X_ALLOC:%.*]]) #[[ATTR4:[0-9]+]] {
84 // CHECK-NEXT: entry:
85 // CHECK-NEXT: [[DOTOMP_LB:%.*]] = alloca i32, align 4
86 // CHECK-NEXT: [[DOTOMP_UB:%.*]] = alloca i32, align 4
87 // CHECK-NEXT: [[DOTOMP_STRIDE:%.*]] = alloca i32, align 4
88 // CHECK-NEXT: [[DOTOMP_IS_LAST:%.*]] = alloca i32, align 4
89 // CHECK-NEXT: call void @llvm.lifetime.start.p0(i64 4, ptr nonnull [[DOTOMP_LB]]) #[[ATTR5]]
90 // CHECK-NEXT: store i32 0, ptr [[DOTOMP_LB]], align 4, !tbaa [[TBAA6:![0-9]+]]
91 // CHECK-NEXT: call void @llvm.lifetime.start.p0(i64 4, ptr nonnull [[DOTOMP_UB]]) #[[ATTR5]]
92 // CHECK-NEXT: store i32 1023, ptr [[DOTOMP_UB]], align 4, !tbaa [[TBAA6]]
93 // CHECK-NEXT: call void @llvm.lifetime.start.p0(i64 4, ptr nonnull [[DOTOMP_STRIDE]]) #[[ATTR5]]
94 // CHECK-NEXT: store i32 1, ptr [[DOTOMP_STRIDE]], align 4, !tbaa [[TBAA6]]
95 // CHECK-NEXT: call void @llvm.lifetime.start.p0(i64 4, ptr nonnull [[DOTOMP_IS_LAST]]) #[[ATTR5]]
96 // CHECK-NEXT: store i32 0, ptr [[DOTOMP_IS_LAST]], align 4, !tbaa [[TBAA6]]
97 // CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr [[DOTGLOBAL_TID_]], align 4, !tbaa [[TBAA6]]
98 // CHECK-NEXT: [[TMP1:%.*]] = load i64, ptr [[X_ALLOC]], align 8, !tbaa [[TBAA3]]
99 // CHECK-NEXT: [[CONV:%.*]] = inttoptr i64 [[TMP1]] to ptr
100 // CHECK-NEXT: [[DOTX__VOID_ADDR:%.*]] = tail call ptr @__kmpc_alloc(i32 [[TMP0]], i64 8, ptr [[CONV]])
101 // CHECK-NEXT: call void @__kmpc_for_static_init_4(ptr nonnull @[[GLOB1:[0-9]+]], i32 [[TMP0]], i32 34, ptr nonnull [[DOTOMP_IS_LAST]], ptr nonnull [[DOTOMP_LB]], ptr nonnull [[DOTOMP_UB]], ptr nonnull [[DOTOMP_STRIDE]], i32 1, i32 1)
102 // CHECK-NEXT: [[TMP2:%.*]] = load i32, ptr [[DOTOMP_UB]], align 4
103 // CHECK-NEXT: [[COND:%.*]] = call i32 @llvm.smin.i32(i32 [[TMP2]], i32 1023)
104 // CHECK-NEXT: store i32 [[COND]], ptr [[DOTOMP_UB]], align 4, !tbaa [[TBAA6]]
105 // CHECK-NEXT: call void @__kmpc_for_static_fini(ptr nonnull @[[GLOB1]], i32 [[TMP0]])
106 // CHECK-NEXT: [[TMP3:%.*]] = load i64, ptr [[X_ALLOC]], align 8, !tbaa [[TBAA3]]
107 // CHECK-NEXT: [[CONV5:%.*]] = inttoptr i64 [[TMP3]] to ptr
108 // CHECK-NEXT: call void @__kmpc_free(i32 [[TMP0]], ptr [[DOTX__VOID_ADDR]], ptr [[CONV5]])
109 // CHECK-NEXT: call void @llvm.lifetime.end.p0(i64 4, ptr nonnull [[DOTOMP_IS_LAST]]) #[[ATTR5]]
110 // CHECK-NEXT: call void @llvm.lifetime.end.p0(i64 4, ptr nonnull [[DOTOMP_STRIDE]]) #[[ATTR5]]
111 // CHECK-NEXT: call void @llvm.lifetime.end.p0(i64 4, ptr nonnull [[DOTOMP_UB]]) #[[ATTR5]]
112 // CHECK-NEXT: call void @llvm.lifetime.end.p0(i64 4, ptr nonnull [[DOTOMP_LB]]) #[[ATTR5]]
113 // CHECK-NEXT: ret void