llvm / Polygeist

C/C++ frontend for MLIR. Also features polyhedral optimizations, parallel optimizations, and more!
https://polygeist.llvm.org
Other
438 stars 100 forks source link

When a class is deleted, the user-defined destructor is not invoked. #415

Open sybs5968 opened 2 weeks ago

sybs5968 commented 2 weeks ago

Hello, I have a problem when I try to use your open source project. Here is the source for testing.

class SimStream {
public:
    int n;
    double a;
    char b;
    SimStream() {
        n = 0;
    }
    SimStream(double _a) {
        a = _a;
    }
    SimStream(int _n , double _a){
        n = _n; a = _a;
    }
    ~SimStream() { printf("---------------------------------------1\n"); };
};

void doSomeThing(SimStream *t) {};

int main() {
    SimStream *s = new SimStream;
    doSomeThing(s);
    delete s;
    return 0;
}

It seems that custom destructor not called. When I delete a class,there are only memref.dealloc %alloc : memref<1x!llvm.struct<(i32, f64, i8)>> and not anything about user-defined destructor function. I don't know what the problem is. If you can answer it, I'd appreciate it.

CXXDeleteExpr 0x559ae6f1da48 'void' Function 0x559ae6edcfa0 'operator delete' 'void (void *) noexcept'
`-ImplicitCastExpr 0x559ae6f1da30 'SimStream *' <LValueToRValue>
  `-DeclRefExpr 0x559ae6f1da10 'SimStream *' lvalue Var 0x559ae6f1d4f8 's' 'SimStream *'
warning not calling destructor on delete
module attributes {dlti.dl_spec = #dlti.dl_spec<#dlti.dl_entry<f80, dense<128> : vector<2xi32>>, #dlti.dl_entry<i1, dense<8> : vector<2xi32>>, #dlti.dl_entry<!llvm.ptr, dense<64> : vector<4xi32>>, #dlti.dl_entry<i16, dense<16> : vector<2xi32>>, #dlti.dl_entry<i8, dense<8> : vector<2xi32>>, #dlti.dl_entry<i32, dense<32> : vector<2xi32>>, #dlti.dl_entry<f16, dense<16> : vector<2xi32>>, #dlti.dl_entry<f64, dense<64> : vector<2xi32>>, #dlti.dl_entry<!llvm.ptr<270>, dense<32> : vector<4xi32>>, #dlti.dl_entry<f128, dense<128> : vector<2xi32>>, #dlti.dl_entry<!llvm.ptr<271>, dense<32> : vector<4xi32>>, #dlti.dl_entry<!llvm.ptr<272>, dense<64> : vector<4xi32>>, #dlti.dl_entry<i64, dense<64> : vector<2xi32>>, #dlti.dl_entry<"dlti.stack_alignment", 128 : i32>, #dlti.dl_entry<"dlti.endianness", "little">>, llvm.data_layout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128", llvm.target_triple = "x86_64-unknown-linux-gnu", "polygeist.target-cpu" = "x86-64", "polygeist.target-features" = "+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87", "polygeist.tune-cpu" = "generic"} {
  func.func @_Z11doSomeThingP9SimStream(%arg0: memref<?x!llvm.struct<(i32, f64, i8)>>) attributes {llvm.linkage = #llvm.linkage<external>} {
    return
  }
  func.func @main() -> i32 attributes {llvm.linkage = #llvm.linkage<external>} {
    %c0_i32 = arith.constant 0 : i32
    %alloc = memref.alloc() : memref<1x!llvm.struct<(i32, f64, i8)>>
    %cast = memref.cast %alloc : memref<1x!llvm.struct<(i32, f64, i8)>> to memref<?x!llvm.struct<(i32, f64, i8)>>
    call @_ZN9SimStreamC1Ev(%cast) : (memref<?x!llvm.struct<(i32, f64, i8)>>) -> ()
    memref.dealloc %alloc : memref<1x!llvm.struct<(i32, f64, i8)>>
    return %c0_i32 : i32
  }
  func.func @_ZN9SimStreamC1Ev(%arg0: memref<?x!llvm.struct<(i32, f64, i8)>>) attributes {llvm.linkage = #llvm.linkage<linkonce_odr>} {
    %c0_i32 = arith.constant 0 : i32
    %0 = "polygeist.memref2pointer"(%arg0) : (memref<?x!llvm.struct<(i32, f64, i8)>>) -> !llvm.ptr
    llvm.store %c0_i32, %0 : i32, !llvm.ptr
    return
  }
}
ivanradanov commented 2 weeks ago

We currently have not support destructors in Polygeist

sybs5968 commented 2 weeks ago

ok,thank you very much.

sybs5968 commented 2 weeks ago

And Where can I see which cases are supported by the current project?