Files
TheRock/compiler/amd-llvm/clang/test/CIR/CodeGen/class.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

122 lines
4.4 KiB
C++

// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir
// RUN: FileCheck --check-prefix=CIR --input-file=%t.cir %s
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o %t-cir.ll
// RUN: FileCheck --check-prefix=LLVM --input-file=%t-cir.ll %s
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm %s -o %t.ll
// RUN: FileCheck --check-prefix=OGCG --input-file=%t.ll %s
// CIR: !rec_IncompleteC = !cir.struct<class "IncompleteC" incomplete>
// CIR: !rec_Base = !cir.struct<class "Base" {!s32i}>
// CIR: !rec_CompleteC = !cir.struct<class "CompleteC" {!s32i, !s8i}>
// CIR: !rec_Derived = !cir.struct<class "Derived" {!rec_Base, !s32i}>
// Note: LLVM and OGCG do not emit the type for incomplete classes.
// LLVM: %class.CompleteC = type { i32, i8 }
// LLVM: %class.Derived = type { %class.Base, i32 }
// LLVM: %class.Base = type { i32 }
// OGCG: %class.CompleteC = type { i32, i8 }
// OGCG: %class.Derived = type { %class.Base, i32 }
// OGCG: %class.Base = type { i32 }
class IncompleteC;
IncompleteC *p;
// CIR: cir.global external @p = #cir.ptr<null> : !cir.ptr<!rec_IncompleteC>
// LLVM: @p = global ptr null
// OGCG: @p = global ptr null, align 8
class CompleteC {
public:
int a;
char b;
};
CompleteC cc;
// CIR: cir.global external @cc = #cir.zero : !rec_CompleteC
// LLVM: @cc = global %class.CompleteC zeroinitializer
// OGCG: @cc = global %class.CompleteC zeroinitializer
class Base {
public:
int a;
};
class Derived : public Base {
public:
int b;
};
int use(Derived *d) { return d->b; }
// CIR: cir.func{{.*}} @_Z3useP7Derived(%[[ARG0:.*]]: !cir.ptr<!rec_Derived>
// CIR: %[[D_ADDR:.*]] = cir.alloca !cir.ptr<!rec_Derived>, !cir.ptr<!cir.ptr<!rec_Derived>>, ["d", init]
// CIR: cir.store %[[ARG0]], %[[D_ADDR]]
// CIR: %[[D_PTR:.*]] = cir.load align(8) %0
// CIR: %[[D_B_ADDR:.*]] = cir.get_member %[[D_PTR]][1] {name = "b"}
// CIR: %[[D_B:.*]] = cir.load align(4) %[[D_B_ADDR]]
// LLVM: define{{.*}} i32 @_Z3useP7Derived
// LLVM: getelementptr inbounds nuw %class.Derived, ptr %{{.*}}, i32 0, i32 1
// OGCG: define{{.*}} i32 @_Z3useP7Derived
// OGCG: getelementptr inbounds nuw %class.Derived, ptr %{{.*}}, i32 0, i32 1
int use_base() {
Derived d;
return d.a;
}
// CIR: cir.func{{.*}} @_Z8use_basev
// CIR: %[[D_ADDR:.*]] = cir.alloca !rec_Derived, !cir.ptr<!rec_Derived>, ["d"]
// CIR: %[[BASE_ADDR:.*]] cir.base_class_addr %[[D_ADDR]] : !cir.ptr<!rec_Derived> nonnull [0] -> !cir.ptr<!rec_Base>
// CIR: %[[D_A_ADDR:.*]] = cir.get_member %2[0] {name = "a"} : !cir.ptr<!rec_Base> -> !cir.ptr<!s32i>
// CIR: %[[D_A:.*]] = cir.load align(4) %3 : !cir.ptr<!s32i>, !s32i
// LLVM: define{{.*}} i32 @_Z8use_basev
// LLVM: %[[D:.*]] = alloca %class.Derived
// LLVM: %[[D_A_ADDR:.*]] = getelementptr inbounds nuw %class.Base, ptr %[[D]], i32 0, i32 0
// OGCG: define{{.*}} i32 @_Z8use_basev
// OGCG: %[[D:.*]] = alloca %class.Derived
// OGCG: %[[D_A_ADDR:.*]] = getelementptr inbounds nuw %class.Base, ptr %[[D]], i32 0, i32 0
int use_base_via_pointer(Derived *d) {
return d->a;
}
// CIR: cir.func{{.*}} @_Z20use_base_via_pointerP7Derived(%[[ARG0:.*]]: !cir.ptr<!rec_Derived>
// CIR: %[[D_ADDR:.*]] = cir.alloca !cir.ptr<!rec_Derived>, !cir.ptr<!cir.ptr<!rec_Derived>>, ["d", init]
// CIR: cir.store %[[ARG0]], %[[D_ADDR]]
// CIR: %[[D:.*]] = cir.load align(8) %[[D_ADDR]]
// CIR: %[[BASE_ADDR:.*]] = cir.base_class_addr %[[D]] : !cir.ptr<!rec_Derived> nonnull [0] -> !cir.ptr<!rec_Base>
// CIR: %[[D_A_ADDR:.*]] = cir.get_member %[[BASE_ADDR]][0] {name = "a"}
// CIR: %[[D_A:.*]] = cir.load align(4) %[[D_A_ADDR]]
// LLVM: define{{.*}} i32 @_Z20use_base_via_pointerP7Derived
// LLVM: %[[D_A_ADDR:.*]] = getelementptr inbounds nuw %class.Base, ptr %{{.*}}, i32 0, i32 0
// OGCG: define{{.*}} i32 @_Z20use_base_via_pointerP7Derived
// OGCG: %[[D_A_ADDR:.*]] = getelementptr inbounds nuw %class.Base, ptr %{{.*}}, i32 0, i32 0
struct EmptyDerived : Base {};
struct EmptyDerived2 : EmptyDerived {};
void use_empty_derived2() {
EmptyDerived2 d2;
}
// CIR: cir.func{{.*}} @_Z18use_empty_derived2v()
// CIR: %0 = cir.alloca !rec_EmptyDerived2, !cir.ptr<!rec_EmptyDerived2>, ["d2"]
// CIR: cir.return
// LLVM: define{{.*}} void @_Z18use_empty_derived2v
// LLVM: alloca %struct.EmptyDerived2
// LLVM: ret void
// OGCG: define{{.*}} void @_Z18use_empty_derived2v
// OGCG: alloca %struct.EmptyDerived2
// OGCG: ret void