Skip to content

Commit ec231f6

Browse files
committed
Part 1: use the correct floating point op for unsupported floating point kinds.
1 parent 9930973 commit ec231f6

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

flang/lib/Lower/ConvertExpr.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "flang/Lower/IntrinsicCall.h"
2323
#include "flang/Lower/Runtime.h"
2424
#include "flang/Lower/Todo.h"
25+
#include "flang/Optimizer/Dialect/FIRAttr.h"
2526
#include "flang/Optimizer/Dialect/FIRDialect.h"
2627
#include "flang/Semantics/expression.h"
2728
#include "flang/Semantics/symbol.h"
@@ -152,16 +153,21 @@ class ExprLowering {
152153
mlir::Value genBoolConstant(mlir::MLIRContext *context, bool value) {
153154
auto i1Type = builder.getI1Type();
154155
auto attr = builder.getIntegerAttr(i1Type, value ? 1 : 0);
155-
return builder.create<mlir::ConstantOp>(getLoc(), i1Type, attr).getResult();
156+
return builder.create<mlir::ConstantOp>(getLoc(), i1Type, attr);
156157
}
157158

159+
/// Generate a real constant with of `value`.
158160
template <int KIND>
159161
mlir::Value genRealConstant(mlir::MLIRContext *context,
160162
const llvm::APFloat &value) {
161163
auto fltTy = Fortran::lower::convertReal(context, KIND);
162-
auto attr = builder.getFloatAttr(fltTy, value);
163-
auto res = builder.create<mlir::ConstantOp>(getLoc(), fltTy, attr);
164-
return res.getResult();
164+
if (fltTy.isa<mlir::FloatType>()) {
165+
auto attr = builder.getFloatAttr(fltTy, value);
166+
return builder.create<mlir::ConstantOp>(getLoc(), fltTy, attr);
167+
}
168+
// MLIR standard dialect doesn't support floating point larger than double.
169+
auto attr = fir::RealAttr::get(context, {KIND, value});
170+
return builder.create<fir::ConstfOp>(getLoc(), fltTy, attr);
165171
}
166172

167173
mlir::Type getSomeKindInteger() { return builder.getIndexType(); }

0 commit comments

Comments
 (0)