Skip to content

Commit

Permalink
[CIR][Lowering] Handle unsupported types for CIR-MLIR type conversion
Browse files Browse the repository at this point in the history
* Pointers to CIR types that do not have converters (e.g. cir.struct)
cause crashes due to passing null types to construct mlir::MemRefType.

* This commit adds checks for pointers and alloca lowering to fail
gracefully if the underlying type can not be converted.
  • Loading branch information
mrsoliman committed Feb 18, 2024
1 parent c2049ba commit 744d5fb
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions clang/lib/CIR/Lowering/ThroughMLIR/LowerCIRToMLIR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ class CIRAllocaOpLowering
auto type = adaptor.getAllocaType();
auto mlirType = getTypeConverter()->convertType(type);

// FIXME: Some types can not be converted yet (e.g. struct)
if (!mlirType)
return mlir::LogicalResult::failure();

auto memreftype = mlir::MemRefType::get({}, mlirType);
rewriter.replaceOpWithNewOp<mlir::memref::AllocaOp>(op, memreftype,
op.getAlignmentAttr());
Expand Down Expand Up @@ -615,6 +619,9 @@ static mlir::TypeConverter prepareTypeConverter() {
mlir::TypeConverter converter;
converter.addConversion([&](mlir::cir::PointerType type) -> mlir::Type {
auto ty = converter.convertType(type.getPointee());
// FIXME: The pointee type might not be converted (e.g. struct)
if (!ty)
return nullptr;
return mlir::MemRefType::get({}, ty);
});
converter.addConversion(
Expand Down

0 comments on commit 744d5fb

Please sign in to comment.