Files
TheRock/compiler/amd-llvm/clang/test/CIR/CodeGen/launder.cpp
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

120 lines
6.5 KiB
C++

// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir
// RUN: FileCheck --input-file=%t.cir %s -check-prefix=CIR
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o %t.ll
// RUN: FileCheck --input-file=%t.ll %s -check-prefix=LLVM
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm %s -o %t.ll
// RUN: FileCheck --input-file=%t.ll %s -check-prefix=OGCG
// __builtin_launder doesn't actually DO anything unless fstrict-vtable-pointers
// is enabled, so test here to make sure we get that switch correctly done.
// RUN: %clang_cc1 -fstrict-vtable-pointers -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir
// RUN: FileCheck --input-file=%t.cir %s -check-prefix=CIR-STRICT
// RUN: %clang_cc1 -fstrict-vtable-pointers -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o %t.ll
// RUN: FileCheck --input-file=%t.ll %s -check-prefix=LLVM-STRICT
// RUN: %clang_cc1 -fstrict-vtable-pointers -triple x86_64-unknown-linux-gnu -emit-llvm %s -o %t.ll
// RUN: FileCheck --input-file=%t.ll %s -check-prefix=OGCG-STRICT
struct Base {};
struct Derived : virtual Base {};
struct VirtMem {
Derived d;
};
auto use_derived(Derived *d) {
return __builtin_launder(d);
}
// CIR-LABEL: cir.func{{.*}}@_Z11use_derivedP7Derived
// CIR: %[[ARG_ALLOCA:.*]] = cir.alloca !cir.ptr<!rec_Derived>, !cir.ptr<!cir.ptr<!rec_Derived>>, ["d", init]
// CIR: %[[RET_ALLOCA:.*]] = cir.alloca !cir.ptr<!rec_Derived>, !cir.ptr<!cir.ptr<!rec_Derived>>, ["__retval"]
// CIR: %[[ARG_LOAD:.*]] = cir.load align(8) %[[ARG_ALLOCA]] : !cir.ptr<!cir.ptr<!rec_Derived>>, !cir.ptr<!rec_Derived>
// CIR: cir.store %[[ARG_LOAD]], %[[RET_ALLOCA]] : !cir.ptr<!rec_Derived>, !cir.ptr<!cir.ptr<!rec_Derived>>
// CIR: %[[RET:.*]] = cir.load %[[RET_ALLOCA]] : !cir.ptr<!cir.ptr<!rec_Derived>>, !cir.ptr<!rec_Derived>
// CIR: cir.return %[[RET]] : !cir.ptr<!rec_Derived>
//
// LLVM-LABEL: define {{.*}}@_Z11use_derivedP7Derived
// LLVM: %[[ARG_ALLOCA:.*]] = alloca ptr
// LLVM: %[[RET_ALLOCA:.*]] = alloca ptr
// LLVM: %[[ARG_LOAD:.*]] = load ptr, ptr %[[ARG_ALLOCA]]
// LLVM: store ptr %[[ARG_LOAD]], ptr %[[RET_ALLOCA]]
// LLVM: %[[RET:.*]] = load ptr, ptr %[[RET_ALLOCA]]
// LLVM: ret ptr %[[RET]]
//
// OGCG-LABEL: define {{.*}}@_Z11use_derivedP7Derived
// OGCG: %[[ARG_ALLOCA:.*]] = alloca ptr
// OGCG: %[[ARG_LOAD:.*]] = load ptr, ptr %[[ARG_ALLOCA]]
// OGCG: ret ptr %[[ARG_LOAD]]
//
// CIR-STRICT-LABEL: cir.func{{.*}}@_Z11use_derivedP7Derived
// CIR-STRICT: %[[ARG_ALLOCA:.*]] = cir.alloca !cir.ptr<!rec_Derived>, !cir.ptr<!cir.ptr<!rec_Derived>>, ["d", init]
// CIR-STRICT: %[[RET_ALLOCA:.*]] = cir.alloca !cir.ptr<!rec_Derived>, !cir.ptr<!cir.ptr<!rec_Derived>>, ["__retval"]
// CIR-STRICT: %[[LOAD_ARG:.*]] = cir.load align(8) %[[ARG_ALLOCA]] : !cir.ptr<!cir.ptr<!rec_Derived>>, !cir.ptr<!rec_Derived>
// CIR-STRICT: %[[LAUNDER:.*]] = cir.launder %[[LOAD_ARG]] : !cir.ptr<!rec_Derived>
// CIR-STRICT: cir.store %[[LAUNDER]], %[[RET_ALLOCA]] : !cir.ptr<!rec_Derived>, !cir.ptr<!cir.ptr<!rec_Derived>>
// CIR-STRICT: %[[RET:.*]] = cir.load %[[RET_ALLOCA]] : !cir.ptr<!cir.ptr<!rec_Derived>>, !cir.ptr<!rec_Derived>
// CIR-STRICT: cir.return %[[RET]] : !cir.ptr<!rec_Derived>
//
// LLVM-STRICT-LABEL: define {{.*}}@_Z11use_derivedP7Derived
// LLVM-STRICT: %[[ARG_ALLOCA:.*]] = alloca ptr
// LLVM-STRICT: %[[RET_ALLOCA:.*]] = alloca ptr
// LLVM-STRICT: %[[ARG_LOAD:.*]] = load ptr, ptr %[[ARG_ALLOCA]]
// LLVM-STRICT: %[[LAUNDER:.*]] = call ptr @llvm.launder.invariant.group.p0(ptr %[[ARG_LOAD]])
// LLVM-STRICT: store ptr %[[LAUNDER]], ptr %[[RET_ALLOCA]]
// LLVM-STRICT: %[[RET:.*]] = load ptr, ptr %[[RET_ALLOCA]]
// LLVM-STRICT: ret ptr %[[RET]]
//
//
// OGCG-STRICT-LABEL: define {{.*}}@_Z11use_derivedP7Derived
// OGCG-STRICT: %[[ARG_ALLOCA:.*]] = alloca ptr
// OGCG-STRICT: %[[ARG_LOAD:.*]] = load ptr, ptr %[[ARG_ALLOCA]]
// OGCG-STRICT: %[[LAUNDER:.*]] = call ptr @llvm.launder.invariant.group.p0(ptr %[[ARG_LOAD]])
// OGCG-STRICT: ret ptr %[[LAUNDER]]
auto use_vm(VirtMem *vm) {
return __builtin_launder(vm);
}
// CIR-LABEL: cir.func {{.*}}@_Z6use_vmP7VirtMem
// CIR: %[[ARG_ALLOCA:.*]] = cir.alloca !cir.ptr<!rec_VirtMem>, !cir.ptr<!cir.ptr<!rec_VirtMem>>, ["vm", init]
// CIR: %[[RET_ALLOCA:.*]] = cir.alloca !cir.ptr<!rec_VirtMem>, !cir.ptr<!cir.ptr<!rec_VirtMem>>, ["__retval"]
// CIR: cir.store %[[ARG_LOAD]], %[[RET_ALLOCA]] : !cir.ptr<!rec_VirtMem>, !cir.ptr<!cir.ptr<!rec_VirtMem>>
// CIR: %[[RET:.*]] = cir.load %[[RET_ALLOCA]] : !cir.ptr<!cir.ptr<!rec_VirtMem>>, !cir.ptr<!rec_VirtMem>
// CIR: cir.return %[[RET]] : !cir.ptr<!rec_VirtMem>
//
// LLVM-LABEL: define {{.*}}@_Z6use_vmP7VirtMem
// LLVM: %[[ARG_ALLOCA:.*]] = alloca ptr
// LLVM: %[[RET_ALLOCA:.*]] = alloca ptr
// LLVM: %[[ARG_LOAD:.*]] = load ptr, ptr %[[ARG_ALLOCA]]
// LLVM: store ptr %[[ARG_LOAD]], ptr %[[RET_ALLOCA]]
// LLVM: %[[RET:.*]] = load ptr, ptr %[[RET_ALLOCA]]
// LLVM: ret ptr %[[RET]]
//
// OGCG-LABEL: define {{.*}}@_Z6use_vmP7VirtMem
// OGCG: %[[ARG_ALLOCA:.*]] = alloca ptr
// OGCG: %[[ARG_LOAD:.*]] = load ptr, ptr %[[ARG_ALLOCA]]
// OGCG: ret ptr %[[ARG_LOAD]]
//
// CIR-STRICT-LABEL: cir.func {{.*}}@_Z6use_vmP7VirtMem
// CIR-STRICT: %[[ARG_ALLOCA:.*]] = cir.alloca !cir.ptr<!rec_VirtMem>, !cir.ptr<!cir.ptr<!rec_VirtMem>>, ["vm", init]
// CIR-STRICT: %[[RET_ALLOCA:.*]] = cir.alloca !cir.ptr<!rec_VirtMem>, !cir.ptr<!cir.ptr<!rec_VirtMem>>, ["__retval"]
// CIR-STRICT: %[[LOAD_ARG:.*]] = cir.load align(8) %[[ARG_ALLOCA]] : !cir.ptr<!cir.ptr<!rec_VirtMem>>, !cir.ptr<!rec_VirtMem>
// CIR-STRICT: %[[LAUNDER:.*]] = cir.launder %[[LOAD_ARG]] : !cir.ptr<!rec_VirtMem>
// CIR-STRICT: cir.store %[[LAUNDER]], %[[RET_ALLOCA]] : !cir.ptr<!rec_VirtMem>, !cir.ptr<!cir.ptr<!rec_VirtMem>>
// CIR-STRICT: %[[RET:.*]] = cir.load %[[RET_ALLOCA]] : !cir.ptr<!cir.ptr<!rec_VirtMem>>, !cir.ptr<!rec_VirtMem>
// CIR-STRICT: cir.return %[[RET]] : !cir.ptr<!rec_VirtMem>
//
// LLVM-STRICT-LABEL: define {{.*}}@_Z6use_vmP7VirtMem
// LLVM-STRICT: %[[ARG_ALLOCA:.*]] = alloca ptr
// LLVM-STRICT: %[[RET_ALLOCA:.*]] = alloca ptr
// LLVM-STRICT: %[[ARG_LOAD:.*]] = load ptr, ptr %[[ARG_ALLOCA]]
// LLVM-STRICT: %[[LAUNDER:.*]] = call ptr @llvm.launder.invariant.group.p0(ptr %[[ARG_LOAD]])
// LLVM-STRICT: store ptr %[[LAUNDER]], ptr %[[RET_ALLOCA]]
// LLVM-STRICT: %[[RET:.*]] = load ptr, ptr %[[RET_ALLOCA]]
// LLVM-STRICT: ret ptr %[[RET]]
//
// OGCG-STRICT-LABEL: define {{.*}}@_Z6use_vmP7VirtMem
// OGCG-STRICT: %[[ARG_ALLOCA:.*]] = alloca ptr
// OGCG-STRICT: %[[LAUNDER:.*]] = call ptr @llvm.launder.invariant.group.p0(ptr %[[ARG_LOAD]])
// OGCG-STRICT: ret ptr %[[LAUNDER]]