brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.2 KiB · e68b38f Raw
82 lines · cpp
1// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -mconstructor-aliases -fclangir -emit-cir %s -o %t.cir2// RUN: FileCheck --check-prefix=CIR --input-file=%t.cir %s3// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -mconstructor-aliases -fclangir -emit-llvm %s -o %t-cir.ll4// RUN: FileCheck --input-file=%t-cir.ll %s -check-prefix=LLVM5// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -mconstructor-aliases -emit-llvm %s -o %t.ll6// RUN: FileCheck --input-file=%t.ll %s -check-prefix=OGCG7 8struct A {9  A();10  virtual void f(char);11};12 13// This should initialize the vtable pointer.14A::A() {}15 16// CIR: !rec_A = !cir.record<struct "A" {!cir.vptr}>17// CIR: !rec_anon_struct = !cir.record<struct  {!cir.array<!cir.ptr<!u8i> x 3>}>18 19// CIR: cir.global "private" external @_ZTV1A : !rec_anon_struct20 21// LLVM: @_ZTV1A = external global { [3 x ptr] }22 23// OGCG: @_ZTV1A = external unnamed_addr constant { [3 x ptr] }24 25// CIR: cir.func{{.*}} @_ZN1AC2Ev(%arg0: !cir.ptr<!rec_A> {{.*}})26// CIR:    %[[THIS_ADDR:.*]] = cir.alloca !cir.ptr<!rec_A>, !cir.ptr<!cir.ptr<!rec_A>>, ["this", init]27// CIR:    cir.store %arg0, %[[THIS_ADDR]] : !cir.ptr<!rec_A>, !cir.ptr<!cir.ptr<!rec_A>>28// CIR:    %[[THIS:.*]] = cir.load %[[THIS_ADDR]] : !cir.ptr<!cir.ptr<!rec_A>>, !cir.ptr<!rec_A>29// CIR:    %[[VPTR:.*]] = cir.vtable.address_point(@_ZTV1A, address_point = <index = 0, offset = 2>) : !cir.vptr30// CIR:    %[[THIS_VPTR_PTR:.*]] = cir.vtable.get_vptr %[[THIS]] : !cir.ptr<!rec_A> -> !cir.ptr<!cir.vptr>31// CIR:    cir.store{{.*}} align(8) %[[VPTR]], %[[THIS_VPTR_PTR]] : !cir.vptr, !cir.ptr<!cir.vptr>32// CIR:    cir.return33 34// LLVM: define{{.*}} void @_ZN1AC2Ev(ptr %[[ARG0:.*]])35// LLVM:   %[[THIS_ADDR:.*]] = alloca ptr36// LLVM:   store ptr %[[ARG0]], ptr %[[THIS_ADDR]]37// LLVM:   %[[THIS:.*]] = load ptr, ptr %[[THIS_ADDR]]38// LLVM:   store ptr getelementptr inbounds nuw (i8, ptr @_ZTV1A, i64 16), ptr %[[THIS]]39 40// OGCG: define{{.*}} void @_ZN1AC2Ev(ptr {{.*}} %[[ARG0:.*]])41// OGCG:   %[[THIS_ADDR:.*]] = alloca ptr42// OGCG:   store ptr %[[ARG0]], ptr %[[THIS_ADDR]]43// OGCG:   %[[THIS:.*]] = load ptr, ptr %[[THIS_ADDR]]44// OGCG:   store ptr getelementptr inbounds inrange(-16, 8) ({ [3 x ptr] }, ptr @_ZTV1A, i32 0, i32 0, i32 2), ptr %[[THIS]]45 46// NOTE: The GEP in OGCG looks very different from the one generated with CIR,47//       but it is equivalent. The OGCG GEP indexes by base pointer, then48//       structure, then array, whereas the CIR GEP indexes by byte offset.49 50void f1(A *a) {51  a->f('c');52}53 54// CIR: cir.func{{.*}} @_Z2f1P1A(%arg0: !cir.ptr<!rec_A> {{.*}})55// CIR:   %[[A_ADDR:.*]] = cir.alloca !cir.ptr<!rec_A>56// CIR:   cir.store %arg0, %[[A_ADDR]]57// CIR:   %[[A:.*]] = cir.load{{.*}} %[[A_ADDR]]58// CIR:   %[[C_LITERAL:.*]] = cir.const #cir.int<99> : !s8i59// CIR:   %[[VPTR_ADDR:.*]] = cir.vtable.get_vptr %[[A]] : !cir.ptr<!rec_A> -> !cir.ptr<!cir.vptr>60// CIR:   %[[VPTR:.*]] = cir.load{{.*}} %[[VPTR_ADDR]] : !cir.ptr<!cir.vptr>, !cir.vptr61// CIR:   %[[FN_PTR_PTR:.*]] = cir.vtable.get_virtual_fn_addr %[[VPTR]][0] : !cir.vptr -> !cir.ptr<!cir.ptr<!cir.func<(!cir.ptr<!rec_A>, !s8i)>>>62// CIR:   %[[FN_PTR:.*]] = cir.load{{.*}} %[[FN_PTR_PTR:.*]] : !cir.ptr<!cir.ptr<!cir.func<(!cir.ptr<!rec_A>, !s8i)>>>, !cir.ptr<!cir.func<(!cir.ptr<!rec_A>, !s8i)>>63// CIR:   cir.call %[[FN_PTR]](%[[A]], %[[C_LITERAL]]) : (!cir.ptr<!cir.func<(!cir.ptr<!rec_A>, !s8i)>>, !cir.ptr<!rec_A>, !s8i) -> ()64 65// LLVM: define{{.*}} void @_Z2f1P1A(ptr %[[ARG0:.*]])66// LLVM:   %[[A_ADDR:.*]] = alloca ptr67// LLVM:   store ptr %[[ARG0]], ptr %[[A_ADDR]]68// LLVM:   %[[A:.*]] = load ptr, ptr %[[A_ADDR]]69// LLVM:   %[[VPTR:.*]] = load ptr, ptr %[[A]]70// LLVM:   %[[FN_PTR_PTR:.*]] = getelementptr inbounds ptr, ptr %[[VPTR]], i32 071// LLVM:   %[[FN_PTR:.*]] = load ptr, ptr %[[FN_PTR_PTR]]72// LLVM:   call void %[[FN_PTR]](ptr %[[A]], i8 99)73 74// OGCG: define{{.*}} void @_Z2f1P1A(ptr {{.*}} %[[ARG0:.*]])75// OGCG:   %[[A_ADDR:.*]] = alloca ptr76// OGCG:   store ptr %[[ARG0]], ptr %[[A_ADDR]]77// OGCG:   %[[A:.*]] = load ptr, ptr %[[A_ADDR]]78// OGCG:   %[[VPTR:.*]] = load ptr, ptr %[[A]]79// OGCG:   %[[FN_PTR_PTR:.*]] = getelementptr inbounds ptr, ptr %[[VPTR]], i64 080// OGCG:   %[[FN_PTR:.*]] = load ptr, ptr %[[FN_PTR_PTR]]81// OGCG:   call void %[[FN_PTR]](ptr {{.*}} %[[A]], i8 {{.*}} 99)82