clangir icon indicating copy to clipboard operation
clangir copied to clipboard

LLVM Lowering: support for `cir.delete.array`

Open ghehg opened this issue 11 months ago • 9 comments

The following code fails to compile, which is reduced from libcxx code.

int *newmem();
struct cls {
  ~cls();
};
cls::~cls() { delete[] newmem(); }

error failed to legalize operation 'cir.delete.array' that was explicitly marked illegal

It is because we do not have a lowering prep implementation for cir.delelte.array, once we have it, we should be able to compile this. Not sure for this simple case, array cookie info is needed, but in general, it is needed for ABI lowering cir.delelte.array.

Create this issue so that we can track implementation as it would help ClangIR build libcxx

@ChuanqiXu9, keep you in the loop as you introduced cir.delelte.array in https://github.com/llvm/clangir/pull/1172, I understand that you guys don't need it to be lowered for analysis purpose, but you might be interested if someone in community picks it up.

ghehg avatar Jan 16 '25 14:01 ghehg

@bcardosolopes assign me please

elhewaty avatar Jan 18 '25 16:01 elhewaty

@elhewaty Assigned to you.

Lancern avatar Jan 19 '25 05:01 Lancern

@elhewaty if this is your first contribution I recommend something a bit easier, but happy to review regardless. FWIW, @andykaylor is working on a similar issue https://github.com/llvm/clangir/pull/1286 here.

bcardosolopes avatar Jan 21 '25 22:01 bcardosolopes

@bcardosolopes, please recommend easier ones if possible, and I can delay this for later.

elhewaty avatar Jan 22 '25 10:01 elhewaty

@elhewaty any bug marked with good-first-issue should be good: https://github.com/llvm/clangir/issues?q=is%3Aissue%20is%3Aopen%20label%3A%22good%20first%20issue%22%20

One specific example: https://github.com/llvm/clangir/issues/589

I wouldn't be worried about people claiming the issues, if there hasn't been an update in a while (maybe more than a week?) they might not ever work on it anyways (from my experience so far), just post a comment that you are working on it and I'll assign it to you too.

bcardosolopes avatar Jan 22 '25 22:01 bcardosolopes

I am interested in this one, should I be using /clang/lib/CodeGen/CGExprCXX.cpp as reference here?

moar55 avatar Feb 15 '25 09:02 moar55

failed to legalize operation 'cir.delete.array' that was explicitly marked illegal

What did you invoke to get this error? @ghehg

moar55 avatar Feb 15 '25 09:02 moar55

What did you invoke to get this error?

Trying to lower to LLVM will give you that. If you add an extra RUN line to clang/test/CIR/CodeGen/delete-array.cpp that does -emit-llvm instead of -emit-cir you'll gonna be able to repro

bcardosolopes avatar Feb 20 '25 21:02 bcardosolopes

@bcardosolopes, I made an initial attempt to implement this. Would you please take a look and let me know if I am on the right track.

ahmedshakill avatar Apr 26 '25 12:04 ahmedshakill