[clang] [flang] [flang] Add UNSIGNED (PR #113504)

Peter Klausler via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 24 12:25:16 PDT 2024


================
@@ -968,21 +968,41 @@ struct BinaryOp {};
                                            fir::FirOpBuilder &builder,         \
                                            const Op &, hlfir::Entity lhs,      \
                                            hlfir::Entity rhs) {                \
-      return hlfir::EntityWithAttributes{                                      \
-          builder.create<GenBinFirOp>(loc, lhs, rhs)};                         \
+      if constexpr (Fortran::common::TypeCategory::GenBinTyCat ==              \
+                        Fortran::common::TypeCategory::Unsigned &&             \
+                    !std::is_same_v<GenBinFirOp, mlir::arith::DivUIOp>) {      \
+        int bits =                                                             \
+            Fortran::evaluate::Type<Fortran::common::TypeCategory::Integer,    \
+                                    KIND>::Scalar::bits;                       \
+        auto signlessType = mlir::IntegerType::get(                            \
+            builder.getContext(), bits,                                        \
+            mlir::IntegerType::SignednessSemantics::Signless);                 \
+        auto lhsSL = builder.createConvert(loc, signlessType, lhs);            \
----------------
klausler wrote:

The conversion of the operands is required in order to avoid errors from the MLIR validator.

The conversion of the result ensures that it is characterized properly as unsigned for any later use as an argument to a runtime intrinsic function or an output data transfer statement.

https://github.com/llvm/llvm-project/pull/113504


More information about the cfe-commits mailing list