|
| 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 | + |
| 6 | +using pi1_t = int __attribute__((address_space(1))) *; |
| 7 | +using pi2_t = int __attribute__((address_space(2))) *; |
| 8 | + |
| 9 | +using ri1_t = int __attribute__((address_space(1))) &; |
| 10 | +using ri2_t = int __attribute__((address_space(2))) &; |
| 11 | + |
| 12 | +// CIR: cir.func @{{.*test_ptr.*}} |
| 13 | +// LLVM: define void @{{.*test_ptr.*}} |
| 14 | +void test_ptr() { |
| 15 | + pi1_t ptr1; |
| 16 | + pi2_t ptr2 = (pi2_t)ptr1; |
| 17 | + // CIR: %[[#PTR1:]] = cir.load %{{[0-9]+}} : !cir.ptr<!cir.ptr<!s32i, addrspace(1)>>, !cir.ptr<!s32i, addrspace(1)> |
| 18 | + // CIR-NEXT: %[[#CAST:]] = cir.cast(address_space, %[[#PTR1]] : !cir.ptr<!s32i, addrspace(1)>), !cir.ptr<!s32i, addrspace(2)> |
| 19 | + // CIR-NEXT: cir.store %[[#CAST]], %{{[0-9]+}} : !cir.ptr<!s32i, addrspace(2)>, !cir.ptr<!cir.ptr<!s32i, addrspace(2)>> |
| 20 | + |
| 21 | + // LLVM: %[[#PTR1:]] = load ptr addrspace(1), ptr %{{[0-9]+}}, align 8 |
| 22 | + // LLVM-NEXT: %[[#CAST:]] = addrspacecast ptr addrspace(1) %[[#PTR1]] to ptr addrspace(2) |
| 23 | + // LLVM-NEXT: store ptr addrspace(2) %[[#CAST]], ptr %{{[0-9]+}}, align 8 |
| 24 | +} |
| 25 | + |
| 26 | +// CIR: cir.func @{{.*test_ref.*}} |
| 27 | +// LLVM: define void @{{.*test_ref.*}} |
| 28 | +void test_ref() { |
| 29 | + pi1_t ptr; |
| 30 | + ri1_t ref1 = *ptr; |
| 31 | + ri2_t ref2 = (ri2_t)ref1; |
| 32 | + // CIR: %[[#DEREF:]] = cir.load deref %{{[0-9]+}} : !cir.ptr<!cir.ptr<!s32i, addrspace(1)>>, !cir.ptr<!s32i, addrspace(1)> |
| 33 | + // CIR-NEXT: cir.store %[[#DEREF]], %[[#ALLOCAREF1:]] : !cir.ptr<!s32i, addrspace(1)>, !cir.ptr<!cir.ptr<!s32i, addrspace(1)>> |
| 34 | + // CIR-NEXT: %[[#REF1:]] = cir.load %[[#ALLOCAREF1]] : !cir.ptr<!cir.ptr<!s32i, addrspace(1)>>, !cir.ptr<!s32i, addrspace(1)> |
| 35 | + // CIR-NEXT: %[[#CAST:]] = cir.cast(address_space, %[[#REF1]] : !cir.ptr<!s32i, addrspace(1)>), !cir.ptr<!s32i, addrspace(2)> |
| 36 | + // CIR-NEXT: cir.store %[[#CAST]], %{{[0-9]+}} : !cir.ptr<!s32i, addrspace(2)>, !cir.ptr<!cir.ptr<!s32i, addrspace(2)>> |
| 37 | + |
| 38 | + // LLVM: %[[#DEREF:]] = load ptr addrspace(1), ptr %{{[0-9]+}}, align 8 |
| 39 | + // LLVM-NEXT: store ptr addrspace(1) %[[#DEREF]], ptr %[[#ALLOCAREF1:]], align 8 |
| 40 | + // LLVM-NEXT: %[[#REF1:]] = load ptr addrspace(1), ptr %[[#ALLOCAREF1]], align 8 |
| 41 | + // LLVM-NEXT: %[[#CAST:]] = addrspacecast ptr addrspace(1) %[[#REF1]] to ptr addrspace(2) |
| 42 | + // LLVM-NEXT: store ptr addrspace(2) %[[#CAST]], ptr %{{[0-9]+}}, align 8 |
| 43 | +} |
| 44 | + |
| 45 | +// CIR: cir.func @{{.*test_nullptr.*}} |
| 46 | +// LLVM: define void @{{.*test_nullptr.*}} |
| 47 | +void test_nullptr() { |
| 48 | + constexpr pi1_t null1 = nullptr; |
| 49 | + pi2_t ptr = (pi2_t)null1; |
| 50 | + // CIR: %[[#NULL1:]] = cir.const #cir.ptr<null> : !cir.ptr<!s32i, addrspace(1)> |
| 51 | + // CIR-NEXT: cir.store %[[#NULL1]], %{{[0-9]+}} : !cir.ptr<!s32i, addrspace(1)>, !cir.ptr<!cir.ptr<!s32i, addrspace(1)>> |
| 52 | + // CIR-NEXT: %[[#NULL2:]] = cir.const #cir.ptr<null> : !cir.ptr<!s32i, addrspace(2)> |
| 53 | + // CIR-NEXT: cir.store %[[#NULL2]], %{{[0-9]+}} : !cir.ptr<!s32i, addrspace(2)>, !cir.ptr<!cir.ptr<!s32i, addrspace(2)>> |
| 54 | + |
| 55 | + // LLVM: store ptr addrspace(1) null, ptr %{{[0-9]+}}, align 8 |
| 56 | + // LLVM-NEXT: store ptr addrspace(2) null, ptr %{{[0-9]+}}, align 8 |
| 57 | +} |
0 commit comments