Skip to content

Commit fd0417a

Browse files
clementvalschweitzpgijeanPerier
committed
[flang] Add type conversion for !fir.box<none>
`none` is used in `fir.box` type to specify a polymorphic type. This patch add the conversion from `!fir.box<none>` to LLVM. This patch is part of the upstreaming effort from fir-dev branch. Reviewed By: awarzynski Differential Revision: https://reviews.llvm.org/D119325 Co-authored-by: Eric Schweitz <eschweitz@nvidia.com> Co-authored-by: Jean Perier <jperier@nvidia.com>
1 parent 2509873 commit fd0417a

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

flang/lib/Optimizer/CodeGen/TypeConverter.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@ class LLVMTypeConverter : public mlir::LLVMTypeConverter {
124124
return mlir::LLVM::LLVMStructType::getLiteral(&getContext(), members,
125125
/*isPacked=*/false);
126126
});
127+
addConversion([&](mlir::NoneType none) {
128+
return mlir::LLVM::LLVMStructType::getLiteral(
129+
none.getContext(), llvm::None, /*isPacked=*/false);
130+
});
127131
}
128132

129133
// i32 is used here because LLVM wants i32 constants when indexing into struct

flang/test/Fir/types-to-llvm.fir

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,3 +418,11 @@ func private @foo0(%arg0: tuple<i64, !fir.box<i32>>)
418418
func private @foo1(%arg0: !fir.type<derived8{a:i64,b:!fir.box<i32>}>)
419419
// CHECK-LABEL: foo1
420420
// CHECK-SAME: !llvm.struct<"derived8", (i64, struct<(ptr<i32>, i{{.*}})>)>
421+
422+
// -----
423+
424+
// Test fir.box<none> translation.
425+
// `none` is used for polymorphic type.
426+
func private @foo0(%arg0: !fir.box<none>)
427+
// CHECK-LABEL: foo0
428+
// CHECK-SAME: !llvm.ptr<struct<(ptr<struct<()>>, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}})>>)

0 commit comments

Comments
 (0)