From ce2a3d9042c95630f12b790bf201c4daf8941afb Mon Sep 17 00:00:00 2001 From: Kelvin Li Date: Tue, 6 Aug 2024 18:23:05 -0400 Subject: [flang] Match the type of the element size in the box in getValueFromBox (#100512) Currently, `%17 = fir.box_elesize %16 : (!fir.class>>) -> i32` is translated to ``` %4 = getelementptr { ptr, i64, i32, i8, i8, i8, i8, ptr, [1 x i64] }, ptr %1, i32 0, i32 1 %5 = load i32, ptr %4, align 4 ``` The type of the element size is `i64`. The load essentially truncates the value and yields incorrect result in the big endian environment. The problem occurs in the `storage_size` intrinsic on a polymorphic variable. --- flang/lib/Optimizer/CodeGen/FIROpPatterns.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'flang/lib/Optimizer/CodeGen/FIROpPatterns.cpp') diff --git a/flang/lib/Optimizer/CodeGen/FIROpPatterns.cpp b/flang/lib/Optimizer/CodeGen/FIROpPatterns.cpp index b9a28b89d9a5..5db9d8ac528e 100644 --- a/flang/lib/Optimizer/CodeGen/FIROpPatterns.cpp +++ b/flang/lib/Optimizer/CodeGen/FIROpPatterns.cpp @@ -102,9 +102,11 @@ mlir::Value ConvertFIRToLLVMPattern::getValueFromBox( auto p = rewriter.create( loc, pty, boxTy.llvm, box, llvm::ArrayRef{0, boxValue}); - auto loadOp = rewriter.create(loc, resultTy, p); + auto fldTy = getBoxEleTy(boxTy.llvm, {boxValue}); + auto loadOp = rewriter.create(loc, fldTy, p); + auto castOp = integerCast(loc, rewriter, resultTy, loadOp); attachTBAATag(loadOp, boxTy.fir, nullptr, p); - return loadOp; + return castOp; } return rewriter.create(loc, box, boxValue); } -- cgit v1.2.3