@@ -3477,27 +3477,26 @@ IntrinsicLibrary::genGetCwd(std::optional<mlir::Type> resultType,
3477
3477
(args.size () >= 1 && !resultType.has_value ()));
3478
3478
3479
3479
auto cwd = fir::getBase (args[0 ]);
3480
- const fir::ExtendedValue &status = args[1 ];
3481
-
3482
3480
auto statusValue = fir::runtime::genGetCwd (builder, loc, cwd);
3483
3481
3484
- // Handle optional status argument.
3485
- if (!isStaticallyAbsent (status)) {
3486
- mlir::Value statusAddr = fir::getBase (status);
3487
- mlir::Value statusIsPresentAtRuntime =
3488
- builder.genIsNotNullAddr (loc, statusAddr);
3489
- builder.genIfThen (loc, statusIsPresentAtRuntime)
3490
- .genThen (
3491
- [&]() { builder.createStoreWithConvert (loc, statusValue, statusAddr); })
3492
- .end ();
3493
- }
3494
-
3495
- // Function form, return status.
3496
3482
if (resultType.has_value ()) {
3483
+ // Function form, return status.
3497
3484
return statusValue;
3485
+ } else {
3486
+ // Subroutine form, store status and return none.
3487
+ const fir::ExtendedValue &status = args[1 ];
3488
+ if (!isStaticallyAbsent (status)) {
3489
+ mlir::Value statusAddr = fir::getBase (status);
3490
+ mlir::Value statusIsPresentAtRuntime =
3491
+ builder.genIsNotNullAddr (loc, statusAddr);
3492
+ builder.genIfThen (loc, statusIsPresentAtRuntime)
3493
+ .genThen ([&]() {
3494
+ builder.createStoreWithConvert (loc, statusValue, statusAddr);
3495
+ })
3496
+ .end ();
3497
+ }
3498
3498
}
3499
3499
3500
- // Subroutine form, return none.
3501
3500
return {};
3502
3501
}
3503
3502
0 commit comments