[flang-commits] [flang] 959de15 - [flang] fir.emboxchar codegen with static length fir.char types
Jean Perier via flang-commits
flang-commits at lists.llvm.org
Wed Dec 7 02:59:41 PST 2022
Author: Jean Perier
Date: 2022-12-07T11:59:10+01:00
New Revision: 959de15055c45e33160308bc6b4846d93d08aaa2
URL: https://github.com/llvm/llvm-project/commit/959de15055c45e33160308bc6b4846d93d08aaa2
DIFF: https://github.com/llvm/llvm-project/commit/959de15055c45e33160308bc6b4846d93d08aaa2.diff
LOG: [flang] fir.emboxchar codegen with static length fir.char types
The verifier of fir.emboxchar accepts `fir.char<kind, constant>` types,
but its codegen failed because of a missing cast. It is convenient and
safe to not require making the cast in FIR, so add it in codegen.
Differential Revision: https://reviews.llvm.org/D139514
Added:
Modified:
flang/lib/Optimizer/CodeGen/CodeGen.cpp
flang/test/Fir/boxchar.fir
Removed:
################################################################################
diff --git a/flang/lib/Optimizer/CodeGen/CodeGen.cpp b/flang/lib/Optimizer/CodeGen/CodeGen.cpp
index 3918e72d2a4c7..29f693d7d3a81 100644
--- a/flang/lib/Optimizer/CodeGen/CodeGen.cpp
+++ b/flang/lib/Optimizer/CodeGen/CodeGen.cpp
@@ -1114,6 +1114,12 @@ struct EmboxCharOpConversion : public FIROpConversion<fir::EmboxCharOp> {
llvmStructTy.cast<mlir::LLVM::LLVMStructType>().getBody()[1];
mlir::Value lenAfterCast = integerCast(loc, rewriter, lenTy, charBufferLen);
+ mlir::Type addrTy =
+ llvmStructTy.cast<mlir::LLVM::LLVMStructType>().getBody()[0];
+ if (addrTy != charBuffer.getType())
+ charBuffer =
+ rewriter.create<mlir::LLVM::BitcastOp>(loc, addrTy, charBuffer);
+
auto insertBufferOp = rewriter.create<mlir::LLVM::InsertValueOp>(
loc, llvmStruct, charBuffer, 0);
rewriter.replaceOpWithNewOp<mlir::LLVM::InsertValueOp>(
diff --git a/flang/test/Fir/boxchar.fir b/flang/test/Fir/boxchar.fir
index 4c5fdec2184ed..e2c76c0c22c6e 100644
--- a/flang/test/Fir/boxchar.fir
+++ b/flang/test/Fir/boxchar.fir
@@ -16,6 +16,16 @@ func.func @get_name() {
return
}
+// CHECK-LABEL: define void @get_name_2
+func.func @get_name_2() {
+ %1 = fir.address_of (@name) : !fir.ref<!fir.char<1,9>>
+ %2 = arith.constant 9 : i64
+ %4 = fir.emboxchar %1, %2 : (!fir.ref<!fir.char<1,9>>, i64) -> !fir.boxchar<1>
+ // CHECK: call void @callee(ptr @name, i64 9)
+ fir.call @callee(%4) : (!fir.boxchar<1>) -> ()
+ return
+}
+
fir.global @name constant : !fir.char<1,9> {
%str = fir.string_lit "Your name"(9) : !fir.char<1,9>
//constant 1
More information about the flang-commits
mailing list