[flang-commits] [flang] [flang] add fir.box_offset operation (PR #73641)
Pete Steinfeld via flang-commits
flang-commits at lists.llvm.org
Wed Nov 29 05:59:23 PST 2023
================
@@ -3656,6 +3656,27 @@ struct NegcOpConversion : public FIROpConversion<fir::NegcOp> {
}
};
+struct BoxOffsetOpConversion : public FIROpConversion<fir::BoxOffsetOp> {
+ using FIROpConversion::FIROpConversion;
+
+ mlir::LogicalResult
+ matchAndRewrite(fir::BoxOffsetOp boxOffset, OpAdaptor adaptor,
+ mlir::ConversionPatternRewriter &rewriter) const override {
+
+ mlir::Type pty = ::getLlvmPtrType(boxOffset.getContext());
+ mlir::Type boxType = fir::unwrapRefType(boxOffset.getBoxRef().getType());
+ mlir::Type llvmBoxTy =
+ lowerTy().convertBoxTypeAsStruct(mlir::cast<fir::BaseBoxType>(boxType));
+ unsigned fieldId = boxOffset.getField() == fir::BoxFieldAttr::derived_type
+ ? getTypeDescFieldId(boxType)
+ : kAddrPosInBox;
+ rewriter.replaceOpWithNewOp<mlir::LLVM::GEPOp>(
+ boxOffset, pty, llvmBoxTy, adaptor.getBoxRef(),
+ llvm::ArrayRef<mlir::LLVM::GEPArg>{0, fieldId});
----------------
psteinfeld wrote:
I get a warning on this line about a narrowing conversion, and, since I build with warnings treated as errors, this breaks my build. I build with GCC 9.3.0.
Here's the relevant text of the error message:
```
/local/home/psteinfeld/up/standalone/llvm-project/flang/lib/Optimizer/CodeGen/CodeGen.cpp: In member function ‘virtual mlir::LogicalResult {anonymous}::BoxOffsetOpConversion::matchAndRewrite(fir::BoxOffsetOp, mlir::ConvertOpToLLVMPattern<fir::BoxOffsetOp>::OpAdaptor, mlir::ConversionPatternRewriter&) const’:
/local/home/psteinfeld/up/standalone/llvm-project/flang/lib/Optimizer/CodeGen/CodeGen.cpp:3675:54: error: narrowing conversion of ‘fieldId’ from ‘unsigned int’ to ‘int32_t’ {aka ‘int’} inside { } [-Werror=narrowing]
llvm::ArrayRef<mlir::LLVM::GEPArg>{0, fieldId});
^
At global scope:
cc1plus: error: unrecognized command line option ‘-Wno-ctad-maybe-unsupported’ [-Werror]
cc1plus: error: unrecognized command line option ‘-Wno-deprecated-copy’ [-Werror]
cc1plus: all warnings being treated as errors
```
https://github.com/llvm/llvm-project/pull/73641
More information about the flang-commits
mailing list