[flang-commits] [flang] e553008 - [Flang] Fix type error when calling EXIT intrinsic (#178688)
via flang-commits
flang-commits at lists.llvm.org
Sat Jan 31 00:54:46 PST 2026
Author: Michael Klemm
Date: 2026-01-31T09:54:41+01:00
New Revision: e553008914af024809dc94ef01b47bbc01354b8b
URL: https://github.com/llvm/llvm-project/commit/e553008914af024809dc94ef01b47bbc01354b8b
DIFF: https://github.com/llvm/llvm-project/commit/e553008914af024809dc94ef01b47bbc01354b8b.diff
LOG: [Flang] Fix type error when calling EXIT intrinsic (#178688)
`EXIT` expects a `KIND=8` integer. If such an integer was passed when
`-fdefault-integer-8` was present, the `assert` removed in this PR would
trigger. Since Flang was already silently downcasting `KIND=8` to
`KIND=4`, this PR removes the `assert` and adds a new test to validate
the correct behavior when large integers are the default
Added:
Modified:
flang/lib/Evaluate/intrinsics.cpp
flang/lib/Optimizer/Builder/IntrinsicCall.cpp
flang/test/Lower/Intrinsics/exit.f90
Removed:
################################################################################
diff --git a/flang/lib/Evaluate/intrinsics.cpp b/flang/lib/Evaluate/intrinsics.cpp
index 72ac9e2f68758..ac662ff70358b 100644
--- a/flang/lib/Evaluate/intrinsics.cpp
+++ b/flang/lib/Evaluate/intrinsics.cpp
@@ -1604,7 +1604,7 @@ static const IntrinsicInterface intrinsicSubroutine[]{
{"cmdmsg", DefaultChar, Rank::scalar, Optionality::optional,
common::Intent::InOut}},
{}, Rank::elemental, IntrinsicClass::impureSubroutine},
- {"exit", {{"status", DefaultInt, Rank::scalar, Optionality::optional}}, {},
+ {"exit", {{"status", AnyInt, Rank::scalar, Optionality::optional}}, {},
Rank::elemental, IntrinsicClass::impureSubroutine},
{"free", {{"ptr", Addressable}}, {}},
{"flush",
diff --git a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
index 73db17f7bf837..2541e41bb405a 100644
--- a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
+++ b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
@@ -3853,9 +3853,6 @@ void IntrinsicLibrary::genExit(llvm::ArrayRef<fir::ExtendedValue> args) {
EXIT_SUCCESS)
: fir::getBase(args[0]);
- assert(status.getType() == builder.getDefaultIntegerType() &&
- "STATUS parameter must be an INTEGER of default kind");
-
fir::runtime::genExit(builder, loc, status);
}
diff --git a/flang/test/Lower/Intrinsics/exit.f90 b/flang/test/Lower/Intrinsics/exit.f90
index 49b41346cac0d..b28673db0d31c 100644
--- a/flang/test/Lower/Intrinsics/exit.f90
+++ b/flang/test/Lower/Intrinsics/exit.f90
@@ -21,3 +21,11 @@ subroutine exit_test2(status)
! CHECK-32: fir.call @_FortranAExit(%[[status]]) {{.*}}: (i32) -> ()
! CHECK-64: fir.call @_FortranAExit(%[[statusConv]]) {{.*}}: (i32) -> ()
end subroutine exit_test2
+
+subroutine exit_test3(status)
+ integer(kind=4) :: status
+ ! CHECK: %[[status:.*]] = fir.load %[[statusArg]] : !fir.ref<i32>
+ ! CHECK-32: fir.call @_FortranAExit(%[[status]]) {{.*}}: (i32) -> ()
+ ! CHECK-64: fir.call @_FortranAExit(%[[status]]) {{.*}}: (i32) -> ()
+ call exit(status)
+end subroutine exit_test3
More information about the flang-commits
mailing list