Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 1 addition & 13 deletions flang/lib/Optimizer/CodeGen/CodeGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3373,19 +3373,7 @@ struct AbsentOpConversion : public fir::FIROpConversion<fir::AbsentOp> {
matchAndRewrite(fir::AbsentOp absent, OpAdaptor,
mlir::ConversionPatternRewriter &rewriter) const override {
mlir::Type ty = convertType(absent.getType());
mlir::Location loc = absent.getLoc();

if (mlir::isa<fir::BoxCharType>(absent.getType())) {
auto structTy = mlir::cast<mlir::LLVM::LLVMStructType>(ty);
assert(!structTy.isOpaque() && !structTy.getBody().empty());
auto undefStruct = rewriter.create<mlir::LLVM::UndefOp>(loc, ty);
auto nullField =
rewriter.create<mlir::LLVM::ZeroOp>(loc, structTy.getBody()[0]);
rewriter.replaceOpWithNewOp<mlir::LLVM::InsertValueOp>(
absent, undefStruct, nullField, 0);
} else {
rewriter.replaceOpWithNewOp<mlir::LLVM::ZeroOp>(absent, ty);
}
rewriter.replaceOpWithNewOp<mlir::LLVM::ZeroOp>(absent, ty);
return mlir::success();
}
};
Expand Down
2 changes: 1 addition & 1 deletion flang/test/Fir/optional.fir
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func.func @foo3(%arg0: !fir.boxchar<1>) -> i1 {
// CHECK-LABEL: @bar3
func.func @bar3() -> i1 {
%0 = fir.absent !fir.boxchar<1>
// CHECK: call i1 @foo3(ptr null, i64 undef)
// CHECK: call i1 @foo3(ptr null, i64 0)
%1 = fir.call @foo3(%0) : (!fir.boxchar<1>) -> i1
return %1 : i1
}
Expand Down
Loading