Skip to content

Commit c1ab6df

Browse files
committed
fix out of bound error in getcwd's lowering
1 parent 3d2899b commit c1ab6df

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

flang/lib/Optimizer/Builder/IntrinsicCall.cpp

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3477,27 +3477,26 @@ IntrinsicLibrary::genGetCwd(std::optional<mlir::Type> resultType,
34773477
(args.size() >= 1 && !resultType.has_value()));
34783478

34793479
auto cwd = fir::getBase(args[0]);
3480-
const fir::ExtendedValue &status = args[1];
3481-
34823480
auto statusValue = fir::runtime::genGetCwd(builder, loc, cwd);
34833481

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.
34963482
if (resultType.has_value()) {
3483+
// Function form, return status.
34973484
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+
}
34983498
}
34993499

3500-
// Subroutine form, return none.
35013500
return {};
35023501
}
35033502

0 commit comments

Comments
 (0)