[PATCH] D118787: [flang] Lower integer constant code for STOP stmt

Valentin Clement via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 3 02:31:24 PST 2022


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGca53e049e013: [flang] Lower integer constant code for STOP stmt (authored by clementval).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D118787/new/

https://reviews.llvm.org/D118787

Files:
  flang/lib/Lower/Runtime.cpp
  flang/test/Lower/stop-statement.f90


Index: flang/test/Lower/stop-statement.f90
===================================================================
--- flang/test/Lower/stop-statement.f90
+++ flang/test/Lower/stop-statement.f90
@@ -19,3 +19,12 @@
  ! CHECK: fir.call @_Fortran{{.*}}StopStatement(%[[c0]], %[[true]], %[[false]])
  ! CHECK-NEXT: fir.unreachable
 end subroutine
+
+! CHECK-LABEL stop_code
+subroutine stop_code()
+  stop 42
+ ! CHECK-DAG: %[[c42:.*]] = arith.constant 42 : i32
+ ! CHECK-DAG: %[[false:.*]] = arith.constant false
+ ! CHECK: fir.call @_Fortran{{.*}}StopStatement(%[[c42]], %[[false]], %[[false]])
+ ! CHECK-NEXT: fir.unreachable
+end subroutine
Index: flang/lib/Lower/Runtime.cpp
===================================================================
--- flang/lib/Lower/Runtime.cpp
+++ flang/lib/Lower/Runtime.cpp
@@ -42,8 +42,27 @@
   mlir::FuncOp callee;
   mlir::FunctionType calleeType;
   // First operand is stop code (zero if absent)
-  if (std::get<std::optional<Fortran::parser::StopCode>>(stmt.t)) {
-    TODO(loc, "STOP first operand not lowered yet");
+  if (const auto &code =
+          std::get<std::optional<Fortran::parser::StopCode>>(stmt.t)) {
+    auto expr = converter.genExprValue(*Fortran::semantics::GetExpr(*code));
+    LLVM_DEBUG(llvm::dbgs() << "stop expression: "; expr.dump();
+               llvm::dbgs() << '\n');
+    expr.match(
+        [&](const fir::CharBoxValue &x) {
+          TODO(loc, "STOP CharBoxValue first operand not lowered yet");
+        },
+        [&](fir::UnboxedValue x) {
+          callee = fir::runtime::getRuntimeFunc<mkRTKey(StopStatement)>(
+              loc, builder);
+          calleeType = callee.getType();
+          mlir::Value cast =
+              builder.createConvert(loc, calleeType.getInput(0), x);
+          operands.push_back(cast);
+        },
+        [&](auto) {
+          mlir::emitError(loc, "unhandled expression in STOP");
+          std::exit(1);
+        });
   } else {
     callee = fir::runtime::getRuntimeFunc<mkRTKey(StopStatement)>(loc, builder);
     calleeType = callee.getType();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D118787.405554.patch
Type: text/x-patch
Size: 2066 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220203/c88e7df1/attachment-0001.bin>


More information about the llvm-commits mailing list