Skip to content

Commit d8548e1

Browse files
committed
conv:irstollvm: Implement null to pointer cast conversion.
1 parent 16b3c16 commit d8548e1

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

lib/vast/Conversion/Common/IRsToLLVM.cpp

+10-2
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,13 @@ namespace vast::conv::irstollvm
595595
return mlir::success();
596596
};
597597

598+
auto null_to_ptr = [&] {
599+
// TODO: deal with nullptr_t conversion
600+
auto null = pattern.null_ptr(rewriter, op.getLoc(), dst_type);
601+
rewriter.replaceOp(op, { null });
602+
return mlir::success();
603+
};
604+
598605
auto int_to_ptr = [&] {
599606
rewriter.template replaceOpWithNewOp< LLVM::IntToPtrOp >(op, dst_type, src);
600607
return mlir::success();
@@ -677,7 +684,7 @@ namespace vast::conv::irstollvm
677684
if (src_bw > dst_bw) {
678685
rewriter.template replaceOpWithNewOp< LLVM::FPTruncOp >(op , dst_type, src);
679686
} else {
680-
rewriter.template replaceOpWithNewOp<mlir::LLVM::FPExtOp>(op, dst_type, src);
687+
rewriter.template replaceOpWithNewOp< LLVM::FPExtOp >(op, dst_type, src);
681688
}
682689
return mlir::success();
683690
};
@@ -702,7 +709,8 @@ namespace vast::conv::irstollvm
702709
case hl::CastKind::ArrayToPointerDecay:
703710
return arr_to_ptr_decay();
704711
// case hl::CastKind::FunctionToPointerDecay:
705-
// case hl::CastKind::NullToPointer:
712+
case hl::CastKind::NullToPointer:
713+
return null_to_ptr();
706714
// case hl::CastKind::NullToMemberPointer:
707715
// case hl::CastKind::BaseToDerivedMemberPointer:
708716
// case hl::CastKind::DerivedToBaseMemberPointer:

0 commit comments

Comments
 (0)