diff --git a/flang/lib/Optimizer/CodeGen/CodeGen.cpp b/flang/lib/Optimizer/CodeGen/CodeGen.cpp --- a/flang/lib/Optimizer/CodeGen/CodeGen.cpp +++ b/flang/lib/Optimizer/CodeGen/CodeGen.cpp @@ -1114,6 +1114,12 @@ llvmStructTy.cast().getBody()[1]; mlir::Value lenAfterCast = integerCast(loc, rewriter, lenTy, charBufferLen); + mlir::Type addrTy = + llvmStructTy.cast().getBody()[0]; + if (addrTy != charBuffer.getType()) + charBuffer = + rewriter.create(loc, addrTy, charBuffer); + auto insertBufferOp = rewriter.create( loc, llvmStruct, charBuffer, 0); rewriter.replaceOpWithNewOp( diff --git a/flang/test/Fir/boxchar.fir b/flang/test/Fir/boxchar.fir --- a/flang/test/Fir/boxchar.fir +++ b/flang/test/Fir/boxchar.fir @@ -16,6 +16,16 @@ return } +// CHECK-LABEL: define void @get_name_2 +func.func @get_name_2() { + %1 = fir.address_of (@name) : !fir.ref> + %2 = arith.constant 9 : i64 + %4 = fir.emboxchar %1, %2 : (!fir.ref>, 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