|
| 1 | +// RUN: %clang_cc1 -triple aarch64-none-linux-android24 -emit-cir %s -o %t.cir |
| 2 | +// RUN: FileCheck --check-prefix=CIR --input-file=%t.cir %s |
| 3 | +// RUN: %clang_cc1 -triple aarch64-none-linux-android24 -fclangir \ |
| 4 | +// RUN: -emit-llvm -fno-clangir-call-conv-lowering -o - %s \ |
| 5 | +// RUN: | opt -S -passes=instcombine,mem2reg,simplifycfg -o %t.ll |
| 6 | +// RUN: FileCheck --check-prefix=LLVM --input-file=%t.ll %s |
| 7 | + |
| 8 | +// This test file is a collection of test cases for all target-independent |
| 9 | +// builtins that are related to memory operations. |
| 10 | + |
| 11 | +int s; |
| 12 | + |
| 13 | +int *test_addressof() { |
| 14 | + return __builtin_addressof(s); |
| 15 | + |
| 16 | + // CIR-LABEL: test_addressof |
| 17 | + // CIR: [[ADDR:%.*]] = cir.get_global @s : !cir.ptr<!s32i> |
| 18 | + // CIR: cir.store [[ADDR]], [[SAVE:%.*]] : !cir.ptr<!s32i>, !cir.ptr<!cir.ptr<!s32i>> |
| 19 | + // CIR: [[RES:%.*]] = cir.load [[SAVE]] : !cir.ptr<!cir.ptr<!s32i>>, !cir.ptr<!s32i> |
| 20 | + // CIR: cir.return [[RES]] : !cir.ptr<!s32i> |
| 21 | + |
| 22 | + // LLVM-LABEL: test_addressof |
| 23 | + // LLVM: store ptr @s, ptr [[ADDR:%.*]], align 8 |
| 24 | + // LLVM: [[RES:%.*]] = load ptr, ptr [[ADDR]], align 8 |
| 25 | + // LLVM: ret ptr [[RES]] |
| 26 | +} |
| 27 | + |
| 28 | +namespace std { template<typename T> T *addressof(T &); } |
| 29 | +int *test_std_addressof() { |
| 30 | + return std::addressof(s); |
| 31 | + |
| 32 | + // CIR-LABEL: test_std_addressof |
| 33 | + // CIR: [[ADDR:%.*]] = cir.get_global @s : !cir.ptr<!s32i> |
| 34 | + // CIR: cir.store [[ADDR]], [[SAVE:%.*]] : !cir.ptr<!s32i>, !cir.ptr<!cir.ptr<!s32i>> |
| 35 | + // CIR: [[RES:%.*]] = cir.load [[SAVE]] : !cir.ptr<!cir.ptr<!s32i>>, !cir.ptr<!s32i> |
| 36 | + // CIR: cir.return [[RES]] : !cir.ptr<!s32i> |
| 37 | + |
| 38 | + // LLVM-LABEL: test_std_addressof |
| 39 | + // LLVM: store ptr @s, ptr [[ADDR:%.*]], align 8 |
| 40 | + // LLVM: [[RES:%.*]] = load ptr, ptr [[ADDR]], align 8 |
| 41 | + // LLVM: ret ptr [[RES]] |
| 42 | +} |
| 43 | + |
| 44 | +namespace std { template<typename T> T *__addressof(T &); } |
| 45 | +int *test_std_addressof2() { |
| 46 | + return std::__addressof(s); |
| 47 | + |
| 48 | + // CIR-LABEL: test_std_addressof2 |
| 49 | + // CIR: [[ADDR:%.*]] = cir.get_global @s : !cir.ptr<!s32i> |
| 50 | + // CIR: cir.store [[ADDR]], [[SAVE:%.*]] : !cir.ptr<!s32i>, !cir.ptr<!cir.ptr<!s32i>> |
| 51 | + // CIR: [[RES:%.*]] = cir.load [[SAVE]] : !cir.ptr<!cir.ptr<!s32i>>, !cir.ptr<!s32i> |
| 52 | + // CIR: cir.return [[RES]] : !cir.ptr<!s32i> |
| 53 | + |
| 54 | + /// LLVM-LABEL: test_std_addressof2 |
| 55 | + // LLVM: store ptr @s, ptr [[ADDR:%.*]], align 8 |
| 56 | + // LLVM: [[RES:%.*]] = load ptr, ptr [[ADDR]], align 8 |
| 57 | + // LLVM: ret ptr [[RES]] |
| 58 | +} |
0 commit comments