[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / CodeGen / dynamic-alloca-with-address-space.c
blob0ef9039e68968efc124b4a2b3de06f68be45e46f
1 // RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -emit-llvm %s -o - \
2 // RUN: | FileCheck %s --check-prefix=CHECK
3 // RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -DOCL12 -x cl -std=cl1.2 \
4 // RUN: -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK-CL12
5 // RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -x cl -std=cl2.0 \
6 // RUN: -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK-CL20
8 #if defined(OCL12)
9 #define CAST (char *)(unsigned long)
10 #else
11 #define CAST (char *)
12 #endif
14 void allocas(unsigned long n) {
15 char *a = CAST __builtin_alloca(n);
16 char *uninitialized_a = CAST __builtin_alloca_uninitialized(n);
17 char *aligned_a = CAST __builtin_alloca_with_align(n, 8);
18 char *aligned_uninitialized_a = CAST __builtin_alloca_with_align_uninitialized(n, 8);
21 // CHECK: @allocas(
22 // CHECK: store i64 %n, ptr %n.addr.ascast, align 8
23 // CHECK: %0 = load i64, ptr %n.addr.ascast, align 8
24 // CHECK: %1 = alloca i8, i64 %0, align 8, addrspace(5)
25 // CHECK: %2 = addrspacecast ptr addrspace(5) %1 to ptr
26 // CHECK: store ptr %2, ptr %a.ascast, align 8
27 // CHECK: %3 = load i64, ptr %n.addr.ascast, align 8
28 // CHECK: %4 = alloca i8, i64 %3, align 8, addrspace(5)
29 // CHECK: %5 = addrspacecast ptr addrspace(5) %4 to ptr
30 // CHECK: store ptr %5, ptr %uninitialized_a.ascast, align 8
31 // CHECK: %6 = load i64, ptr %n.addr.ascast, align 8
32 // CHECK: %7 = alloca i8, i64 %6, align 1, addrspace(5)
33 // CHECK: %8 = addrspacecast ptr addrspace(5) %7 to ptr
34 // CHECK: store ptr %8, ptr %aligned_a.ascast, align 8
35 // CHECK: %9 = load i64, ptr %n.addr.ascast, align 8
36 // CHECK: %10 = alloca i8, i64 %9, align 1, addrspace(5)
37 // CHECK: %11 = addrspacecast ptr addrspace(5) %10 to ptr
38 // CHECK: store ptr %11, ptr %aligned_uninitialized_a.ascast, align 8
39 // CHECK: ret void
40 // CHECK-CL12-NOT: addrspacecast
41 // CHECK-CL20-NOT: addrspacecast