| 1 |
// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir |
| 2 |
// RUN: FileCheck --input-file=%t.cir %s -check-prefix=CIR |
| 3 |
// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o %t.ll |
| 4 |
// RUN: FileCheck --input-file=%t.ll %s -check-prefix=LLVM |
| 5 |
// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-linux-gnu -emit-llvm %s -o %t.ll |
| 6 |
// RUN: FileCheck --input-file=%t.ll %s -check-prefix=OGCG |
| 7 |
|
| 8 |
using pi1_t = int __attribute__((address_space(1))) *; |
| 9 |
using pi2_t = int __attribute__((address_space(2))) *; |
| 10 |
|
| 11 |
using ri1_t = int __attribute__((address_space(1))) &; |
| 12 |
using ri2_t = int __attribute__((address_space(2))) &; |
| 13 |
|
| 14 |
// CIR: cir.func {{.*}} @{{.*test_ptr.*}} |
| 15 |
// LLVM: define dso_local void @{{.*test_ptr.*}} |
| 16 |
// OGCG: define dso_local void @{{.*test_ptr.*}} |
| 17 |
void test_ptr() { |
| 18 |
pi1_t ptr1; |
| 19 |
pi2_t ptr2 = (pi2_t)ptr1; |
| 20 |
// CIR: %[[#PTR1:]] = cir.load{{.*}} %{{[0-9]+}} : !cir.ptr<!cir.ptr<!s32i, target_address_space(1)>>, !cir.ptr<!s32i, target_address_space(1)> |
| 21 |
// CIR-NEXT: %[[#CAST:]] = cir.cast address_space %[[#PTR1]] : !cir.ptr<!s32i, target_address_space(1)> -> !cir.ptr<!s32i, target_address_space(2)> |
| 22 |
// CIR-NEXT: cir.store{{.*}} %[[#CAST]], %{{[0-9]+}} : !cir.ptr<!s32i, target_address_space(2)>, !cir.ptr<!cir.ptr<!s32i, target_address_space(2)>> |
| 23 |
|
| 24 |
// LLVM: %[[#PTR1:]] = load ptr addrspace(1), ptr %{{.*}} |
| 25 |
// LLVM-NEXT: %[[#CAST:]] = addrspacecast ptr addrspace(1) %[[#PTR1]] to ptr addrspace(2) |
| 26 |
// LLVM-NEXT: store ptr addrspace(2) %[[#CAST]], ptr %{{.*}} |
| 27 |
|
| 28 |
// OGCG: %{{.*}} = load ptr addrspace(1), ptr %{{.*}} |
| 29 |
// OGCG-NEXT: %{{.*}} = addrspacecast ptr addrspace(1) %{{.*}} to ptr addrspace(2) |
| 30 |
// OGCG-NEXT: store ptr addrspace(2) %{{.*}}, ptr %{{.*}} |
| 31 |
} |
| 32 |
|
| 33 |
// CIR: cir.func {{.*}} @{{.*test_ref.*}} |
| 34 |
// LLVM: define dso_local void @{{.*test_ref.*}} |
| 35 |
// OGCG: define dso_local void @{{.*test_ref.*}} |
| 36 |
void test_ref() { |
| 37 |
pi1_t ptr; |
| 38 |
ri1_t ref1 = *ptr; |
| 39 |
ri2_t ref2 = (ri2_t)ref1; |
| 40 |
// CIR: %[[#DEREF:]] = cir.load deref{{.*}} %{{[0-9]+}} : !cir.ptr<!cir.ptr<!s32i, target_address_space(1)>>, !cir.ptr<!s32i, target_address_space(1)> |
| 41 |
// CIR-NEXT: cir.store{{.*}} %[[#DEREF]], %{{[0-9]+}} : !cir.ptr<!s32i, target_address_space(1)>, !cir.ptr<!cir.ptr<!s32i, target_address_space(1)>> |
| 42 |
// CIR-NEXT: %[[#REF1:]] = cir.load %{{[0-9]+}} : !cir.ptr<!cir.ptr<!s32i, target_address_space(1)>>, !cir.ptr<!s32i, target_address_space(1)> |
| 43 |
// CIR-NEXT: %[[#CAST:]] = cir.cast address_space %[[#REF1]] : !cir.ptr<!s32i, target_address_space(1)> -> !cir.ptr<!s32i, target_address_space(2)> |
| 44 |
// CIR-NEXT: cir.store{{.*}} %[[#CAST]], %{{[0-9]+}} : !cir.ptr<!s32i, target_address_space(2)>, !cir.ptr<!cir.ptr<!s32i, target_address_space(2)>> |
| 45 |
|
| 46 |
// LLVM: %[[#DEREF:]] = load ptr addrspace(1), ptr %{{.*}} |
| 47 |
// LLVM-NEXT: store ptr addrspace(1) %[[#DEREF]], ptr %{{.*}} |
| 48 |
// LLVM-NEXT: %[[#REF1:]] = load ptr addrspace(1), ptr %{{.*}} |
| 49 |
// LLVM-NEXT: %[[#CAST:]] = addrspacecast ptr addrspace(1) %[[#REF1]] to ptr addrspace(2) |
| 50 |
// LLVM-NEXT: store ptr addrspace(2) %[[#CAST]], ptr %{{.*}} |
| 51 |
|
| 52 |
// OGCG: %{{.*}} = load ptr addrspace(1), ptr %{{.*}} |
| 53 |
// OGCG-NEXT: store ptr addrspace(1) %{{.*}}, ptr %{{.*}} |
| 54 |
// OGCG-NEXT: %{{.*}} = load ptr addrspace(1), ptr %{{.*}} |
| 55 |
// OGCG-NEXT: %{{.*}} = addrspacecast ptr addrspace(1) %{{.*}} to ptr addrspace(2) |
| 56 |
// OGCG-NEXT: store ptr addrspace(2) %{{.*}}, ptr %{{.*}} |
| 57 |
} |
| 58 |
|
| 59 |
// CIR: cir.func {{.*}} @{{.*test_nullptr.*}} |
| 60 |
// LLVM: define dso_local void @{{.*test_nullptr.*}} |
| 61 |
// OGCG: define dso_local void @{{.*test_nullptr.*}} |
| 62 |
void test_nullptr() { |
| 63 |
constexpr pi1_t null1 = nullptr; |
| 64 |
pi2_t ptr = (pi2_t)null1; |
| 65 |
// CIR: %[[#NULL1:]] = cir.const #cir.ptr<null> : !cir.ptr<!s32i, target_address_space(1)> |
| 66 |
// CIR-NEXT: cir.store{{.*}} %[[#NULL1]], %{{[0-9]+}} : !cir.ptr<!s32i, target_address_space(1)>, !cir.ptr<!cir.ptr<!s32i, target_address_space(1)>> |
| 67 |
// CIR-NEXT: %[[#NULL2:]] = cir.const #cir.ptr<null> : !cir.ptr<!s32i, target_address_space(2)> |
| 68 |
// CIR-NEXT: cir.store{{.*}} %[[#NULL2]], %{{[0-9]+}} : !cir.ptr<!s32i, target_address_space(2)>, !cir.ptr<!cir.ptr<!s32i, target_address_space(2)>> |
| 69 |
|
| 70 |
// LLVM: store ptr addrspace(1) null, ptr %{{.*}} |
| 71 |
// LLVM-NEXT: store ptr addrspace(2) null, ptr %{{.*}} |
| 72 |
|
| 73 |
// OGCG: store ptr addrspace(1) null, ptr %{{.*}} |
| 74 |
// OGCG-NEXT: store ptr addrspace(2) null, ptr %{{.*}} |
| 75 |
} |
| 76 |
|
| 77 |
// CIR: cir.func {{.*}} @{{.*test_side_effect.*}} |
| 78 |
// LLVM: define dso_local void @{{.*test_side_effect.*}} |
| 79 |
// OGCG: define dso_local void @{{.*test_side_effect.*}} |
| 80 |
void test_side_effect(pi1_t b) { |
| 81 |
pi2_t p = (pi2_t)(*b++, (int*)0); |
| 82 |
// CIR: %[[#DEREF:]] = cir.load deref{{.*}} %{{[0-9]+}} : !cir.ptr<!cir.ptr<!s32i, target_address_space(1)>>, !cir.ptr<!s32i, target_address_space(1)> |
| 83 |
// CIR: %[[#STRIDE:]] = cir.ptr_stride %[[#DEREF]], %{{[0-9]+}} : (!cir.ptr<!s32i, target_address_space(1)>, !s32i) -> !cir.ptr<!s32i, target_address_space(1)> |
| 84 |
// CIR: %[[#NULL:]] = cir.const #cir.ptr<null> : !cir.ptr<!s32i, target_address_space(2)> |
| 85 |
// CIR-NEXT: cir.store{{.*}} %[[#NULL]], %{{[0-9]+}} : !cir.ptr<!s32i, target_address_space(2)>, !cir.ptr<!cir.ptr<!s32i, target_address_space(2)>> |
| 86 |
|
| 87 |
// LLVM: %{{[0-9]+}} = getelementptr {{.*}}i32, ptr addrspace(1) %{{[0-9]+}}, i{{32|64}} 1 |
| 88 |
// LLVM: store ptr addrspace(2) null, ptr %{{.*}} |
| 89 |
|
| 90 |
// OGCG: %{{.*}} = getelementptr{{.*}} i32, ptr addrspace(1) %{{.*}}, i32 1 |
| 91 |
// OGCG: store ptr addrspace(2) null, ptr %{{.*}} |
| 92 |
} |