summaryrefslogtreecommitdiff
path: root/flang/lib/Lower/ConvertConstant.cpp
diff options
context:
space:
mode:
authorMichael Kruse <llvm-project@meinersbur.de>2025-01-03 10:22:51 +0100
committerMichael Kruse <llvm-project@meinersbur.de>2025-01-03 10:22:51 +0100
commit38500d63e14ce340236840f60d356cdefb56a52c (patch)
tree17edbec446ce9b50d2f215a483b83afb293a635d /flang/lib/Lower/ConvertConstant.cpp
parent1a3d5daaef7a6a63448a497da3eff7fc9e23df26 (diff)
parent27f30029741ecf023baece7b3dde1ff9011ffefc (diff)
Merge branch 'main' into users/meinersbur/flang_runtime_split-headersusers/meinersbur/flang_runtime_split-headers
Diffstat (limited to 'flang/lib/Lower/ConvertConstant.cpp')
-rw-r--r--flang/lib/Lower/ConvertConstant.cpp16
1 files changed, 11 insertions, 5 deletions
diff --git a/flang/lib/Lower/ConvertConstant.cpp b/flang/lib/Lower/ConvertConstant.cpp
index 556b330b967c..e56fde247828 100644
--- a/flang/lib/Lower/ConvertConstant.cpp
+++ b/flang/lib/Lower/ConvertConstant.cpp
@@ -226,12 +226,18 @@ template <Fortran::common::TypeCategory TC, int KIND>
static mlir::Value genScalarLit(
fir::FirOpBuilder &builder, mlir::Location loc,
const Fortran::evaluate::Scalar<Fortran::evaluate::Type<TC, KIND>> &value) {
- if constexpr (TC == Fortran::common::TypeCategory::Integer) {
- mlir::Type ty = Fortran::lower::getFIRType(builder.getContext(), TC, KIND,
- std::nullopt);
+ if constexpr (TC == Fortran::common::TypeCategory::Integer ||
+ TC == Fortran::common::TypeCategory::Unsigned) {
+ // MLIR requires constants to be signless
+ mlir::Type ty = Fortran::lower::getFIRType(
+ builder.getContext(), Fortran::common::TypeCategory::Integer, KIND,
+ std::nullopt);
if (KIND == 16) {
- auto bigInt =
- llvm::APInt(ty.getIntOrFloatBitWidth(), value.SignedDecimal(), 10);
+ auto bigInt = llvm::APInt(ty.getIntOrFloatBitWidth(),
+ TC == Fortran::common::TypeCategory::Unsigned
+ ? value.UnsignedDecimal()
+ : value.SignedDecimal(),
+ 10);
return builder.create<mlir::arith::ConstantOp>(
loc, ty, mlir::IntegerAttr::get(ty, bigInt));
}