brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.3 KiB · 08a6b21 Raw
130 lines · cpp
1// RUN: %clang_cc1 -triple aarch64-none-linux-android21 -std=c++20 -mconstructor-aliases -O0 -fclangir -emit-cir %s -o %t.cir2// RUN: FileCheck --check-prefix=CIR --input-file=%t.cir %s3// RUN: %clang_cc1 -triple aarch64-none-linux-android21 -std=c++20 -mconstructor-aliases -O0 -fclangir -emit-llvm %s -o %t-cir.ll4// RUN: FileCheck --check-prefix=LLVM --input-file=%t-cir.ll %s5// RUN: %clang_cc1 -triple aarch64-none-linux-android21 -std=c++20 -mconstructor-aliases -O0 -emit-llvm %s -o %t.ll6// RUN: FileCheck --check-prefix=OGCG --input-file=%t.ll %s7 8// TODO(cir): Try to emit base destructor as an alias at O1 or higher.9 10// FIXME: LLVM IR dialect does not yet support function ptr globals, which precludes11// a lot of the proper semantics for properly representing alias functions in LLVM12// (see the note on LLVM_O1 below).13 14struct Member {15  ~Member();16};17 18struct A {19  virtual ~A();20};21 22struct B : A {23  Member m;24  virtual ~B();25};26 27B::~B() { }28 29// Aliases are inserted before the function definitions in LLVM IR30// FIXME: These should have unnamed_addr set.31// LLVM: @_ZN1BD1Ev = alias void (ptr), ptr @_ZN1BD2Ev32// LLVM: @_ZN1CD1Ev = alias void (ptr), ptr @_ZN1CD2Ev33 34// OGCG: @_ZN1BD1Ev = unnamed_addr alias void (ptr), ptr @_ZN1BD2Ev35// OGCG: @_ZN1CD1Ev = unnamed_addr alias void (ptr), ptr @_ZN1CD2Ev36 37 38// Base (D2) dtor for B: calls A's base dtor.39 40// CIR: cir.func{{.*}} @_ZN1BD2Ev41// CIR:   cir.call @_ZN6MemberD1Ev42// CIR:   cir.call @_ZN1AD2Ev43 44// LLVM: define{{.*}} void @_ZN1BD2Ev45// LLVM:   call void @_ZN6MemberD1Ev46// LLVM:   call void @_ZN1AD2Ev47 48// OGCG: define{{.*}} @_ZN1BD2Ev49// OGCG:   call void @_ZN6MemberD1Ev50// OGCG:   call void @_ZN1AD2Ev51 52// Complete (D1) dtor for B: just an alias because there are no virtual bases.53 54// CIR: cir.func{{.*}} @_ZN1BD1Ev(!cir.ptr<!rec_B>) alias(@_ZN1BD2Ev)55// This is defined above for LLVM and OGCG.56 57// Deleting (D0) dtor for B: defers to the complete dtor but also calls operator delete.58 59// CIR: cir.func{{.*}} @_ZN1BD0Ev60// CIR:   cir.call @_ZN1BD1Ev(%[[THIS:.*]]) nothrow : (!cir.ptr<!rec_B>) -> ()61// CIR:   %[[THIS_VOID:.*]] = cir.cast bitcast %[[THIS]] : !cir.ptr<!rec_B> -> !cir.ptr<!void>62// CIR:   %[[SIZE:.*]] = cir.const #cir.int<16>63// CIR:   cir.call @_ZdlPvm(%[[THIS_VOID]], %[[SIZE]])64 65// LLVM: define{{.*}} void @_ZN1BD0Ev66// LLVM:   call void @_ZN1BD1Ev(ptr %[[THIS:.*]])67// LLVM:   call void @_ZdlPvm(ptr %[[THIS]], i64 16)68 69// OGCG: define{{.*}} @_ZN1BD0Ev70// OGCG:   call void @_ZN1BD1Ev(ptr{{.*}} %[[THIS:.*]])71// OGCG:   call void @_ZdlPvm(ptr{{.*}} %[[THIS]], i64{{.*}} 16)72 73struct C : B {74  ~C();75};76 77C::~C() { }78 79// Base (D2) dtor for C: calls B's base dtor.80 81// CIR: cir.func{{.*}} @_ZN1CD2Ev82// CIR:   %[[B:.*]] = cir.base_class_addr %[[THIS:.*]] : !cir.ptr<!rec_C> nonnull [0] -> !cir.ptr<!rec_B>83// CIR:   cir.call @_ZN1BD2Ev(%[[B]])84 85// LLVM: define{{.*}} void @_ZN1CD2Ev86// LLVM:   call void @_ZN1BD2Ev87 88// OGCG: define{{.*}} @_ZN1CD2Ev89// OGCG:   call void @_ZN1BD2Ev90 91// Complete (D1) dtor for C: just an alias because there are no virtual bases.92 93// CIR: cir.func{{.*}} @_ZN1CD1Ev(!cir.ptr<!rec_C>) alias(@_ZN1CD2Ev)94// This is defined above for LLVM and OGCG.95 96 97// Deleting (D0) dtor for C: defers to the complete dtor but also calls operator delete.98 99// CIR: cir.func{{.*}} @_ZN1CD0Ev100// CIR:   cir.call @_ZN1CD1Ev(%[[THIS:.*]]) nothrow : (!cir.ptr<!rec_C>) -> ()101// CIR:   %[[THIS_VOID:.*]] = cir.cast bitcast %[[THIS]] : !cir.ptr<!rec_C> -> !cir.ptr<!void>102// CIR:   %[[SIZE:.*]] = cir.const #cir.int<16>103// CIR:   cir.call @_ZdlPvm(%[[THIS_VOID]], %[[SIZE]])104 105// LLVM: define{{.*}} void @_ZN1CD0Ev106// LLVM:   call void @_ZN1CD1Ev(ptr %[[THIS:.*]])107// LLVM:   call void @_ZdlPvm(ptr %[[THIS]], i64 16)108 109// OGCG: define{{.*}} @_ZN1CD0Ev110// OGCG:   call void @_ZN1CD1Ev(ptr{{.*}} %[[THIS:.*]])111// OGCG:   call void @_ZdlPvm(ptr{{.*}} %[[THIS]], i64{{.*}} 16)112 113namespace PR12798 {114  // A qualified call to a base class destructor should not undergo virtual115  // dispatch. Template instantiation used to lose the qualifier.116  struct A { virtual ~A(); };117  template<typename T> void f(T *p) { p->A::~A(); }118 119  // CIR: cir.func{{.*}} @_ZN7PR127981fINS_1AEEEvPT_120  // CIR:   cir.call @_ZN7PR127981AD1Ev121 122  // LLVM: define{{.*}} @_ZN7PR127981fINS_1AEEEvPT_123  // LLVM:   call void @_ZN7PR127981AD1Ev124 125  // OGCG: define{{.*}} @_ZN7PR127981fINS_1AEEEvPT_126  // OGCG:   call void @_ZN7PR127981AD1Ev127 128  template void f(A*);129}130