[flang-commits] [flang] [Flang] Fix type error when calling EXIT intrinsic (PR #178688)

Michael Klemm via flang-commits flang-commits at lists.llvm.org
Thu Jan 29 08:00:39 PST 2026


https://github.com/mjklemm created https://github.com/llvm/llvm-project/pull/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

>From 268912aa6cfcce8d9cee6e74146e4d88802d5c18 Mon Sep 17 00:00:00 2001
From: Michael Klemm <michael.klemm at amd.com>
Date: Thu, 22 Jan 2026 16:47:35 +0100
Subject: [PATCH] [Flang] Fix type error when calling EXIT instrinsic

`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
---
 flang/lib/Evaluate/intrinsics.cpp             | 2 +-
 flang/lib/Optimizer/Builder/IntrinsicCall.cpp | 3 ---
 flang/test/Lower/Intrinsics/exit.f90          | 8 ++++++++
 3 files changed, 9 insertions(+), 4 deletions(-)

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 4ba906dce4a13..31bd70c8b762d 100644
--- a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
+++ b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
@@ -3852,9 +3852,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