[flang-commits] [flang] [flang] Add support for the IARGC and GETARG legacy intrinsics (PR #196425)

via flang-commits flang-commits at lists.llvm.org
Sun May 10 15:44:55 PDT 2026


================
@@ -4368,6 +4373,35 @@ void IntrinsicLibrary::genGetCommandArgument(
   }
 }
 
+// GETARG
+void IntrinsicLibrary::genGetarg(llvm::ArrayRef<fir::ExtendedValue> args) {
+  assert(args.size() == 2);
+
+  mlir::Value pos = fir::getBase(args[0]);
+  mlir::Value value = fir::getBase(args[1]);
+
+  if (!pos)
+    fir::emitFatalError(loc, "expected POS parameter");
+
+  auto posTy = mlir::dyn_cast<mlir::IntegerType>(pos.getType());
+  auto defaultTy =
+      mlir::cast<mlir::IntegerType>(builder.getDefaultIntegerType());
+
+  assert(posTy && "POS must be an integer");
+
+  if (posTy.getWidth() > defaultTy.getWidth())
+    fir::emitFatalError(
+        loc,
+        "POS must be an INTEGER type not wider than the default INTEGER kind");
----------------
Tuhil926 wrote:

I actually could not find a way to do this particular check with `TypePattern` and `KindCode`. I see `KindCode::greaterOrEqualToKind`, but there's nothing for 'less than or equal to', and even if there was, I'm not sure if I can give it a `kindValue` parameter equal to the default integer width. I've removed this check now and made the `POS` parameter be `DefaultInt`, the same as `GET_COMMAND_ARGUMENT`. I assume this will be fine, as they both use `fir::runtime::genGetCommandArgument` for lowering.

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


More information about the flang-commits mailing list