[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
This commit is contained in:
parent
07de5d18c9
commit
959de15055
@ -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>(
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user