llvm / clangir

A new (MLIR based) high-level IR for clang.
https://clangir.org
Other
327 stars 86 forks source link

[CIR] Generate `cir.dyn_cast` for dynamic casts to void ptr #557

Closed Lancern closed 3 months ago

Lancern commented 3 months ago

This patch update the CIRGen of dynamic_cast expressions and make it start to generate cir.dyn_cast operations for dynamic_cast expressions that cast to a void pointer. This patch also updates the lowering prepare pass so that it lowers such cir.dyn_cast operations to the code emitted before this patch.

This patch adds a new attribute #cir.dyn_cast_to_void that carries ABI- specific information about a dynamic-cast-to-void-pointer operation. For downcasts and sidecasts, the cir.dyn_cast operation continues to hold a #cir.dyn_cast_info attribute. For dynamic-cast-to-void-pointer, the cir.dyn_cast operation holds a #cir.dyn_cast_to_void attribute instead.

Lancern commented 3 months ago

Rebased onto the latest main.

Lancern commented 3 months ago

Rebased onto the latest main.

BTW, I found a bug in the previous related patch. The cir.dyn_cast operation is lowered to a cir.ternary that guards against the source pointer being null. I got the true branch and the false branch wrong. Fixed it inline together with the latest rebase and improvements.