[flang-commits] [clang] [flang] [mlir] [MLIR] Zero-extend unsigned and 1-bit values when translating IntegerAttr (PR #169751)

Andy Kaylor via flang-commits flang-commits at lists.llvm.org
Tue Dec 2 09:14:48 PST 2025


================
@@ -588,10 +588,17 @@ llvm::Constant *mlir::LLVM::detail::getLLVMConstant(
   }
   // For integer types, we allow a mismatch in sizes as the index type in
   // MLIR might have a different size than the index type in the LLVM module.
-  if (auto intAttr = dyn_cast<IntegerAttr>(attr))
-    return llvm::ConstantInt::get(
-        llvmType,
-        intAttr.getValue().sextOrTrunc(llvmType->getIntegerBitWidth()));
+  if (auto intAttr = dyn_cast<IntegerAttr>(attr)) {
+    // If the attribute is an unsigned integer or a 1-bit integer, zero-extend
+    // the value to the bit width of the LLVM type. Otherwise, sign-extend.
+    auto intTy = mlir::dyn_cast<IntegerType>(intAttr.getType());
----------------
andykaylor wrote:

I had this as a `cast` originally, and it does fail sometimes. This can also be `IndexType`, I think.

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


More information about the flang-commits mailing list