[flang-commits] [flang] cc30674 - [flang] Handle logical constant value for quiet in STOP stmt

Valentin Clement via flang-commits flang-commits at lists.llvm.org
Fri Feb 4 01:12:35 PST 2022


Author: Valentin Clement
Date: 2022-02-04T10:12:25+01:00
New Revision: cc306740ccfcb0b64f789c2062c4de8954026ad4

URL: https://github.com/llvm/llvm-project/commit/cc306740ccfcb0b64f789c2062c4de8954026ad4
DIFF: https://github.com/llvm/llvm-project/commit/cc306740ccfcb0b64f789c2062c4de8954026ad4.diff

LOG: [flang] Handle logical constant value for quiet in STOP stmt

This patch handles the quiet argument in the STOP statement. It adds
ability to lower LOGICAL constant.

This patch is part of the upstreaming effort from fir-dev branch.

Reviewed By: kiranchandramohan, PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D118897

Co-authored-by: Jean Perier <jperier at nvidia.com>

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/flang/lib/Lower/ConvertExpr.cpp b/flang/lib/Lower/ConvertExpr.cpp
index 72c8313f61a2d..e77ef422d4340 100644
--- a/flang/lib/Lower/ConvertExpr.cpp
+++ b/flang/lib/Lower/ConvertExpr.cpp
@@ -59,6 +59,11 @@ class ScalarExprLowering {
     return builder.createIntegerConstant(getLoc(), type, value);
   }
 
+  /// Generate a logical/boolean constant of `value`
+  mlir::Value genBoolConstant(bool value) {
+    return builder.createBool(getLoc(), value);
+  }
+
   ExtValue genval(Fortran::semantics::SymbolRef sym) {
     TODO(getLoc(), "genval SymbolRef");
   }
@@ -231,7 +236,7 @@ class ScalarExprLowering {
     if constexpr (TC == Fortran::common::TypeCategory::Integer) {
       return genIntegerConstant<KIND>(builder.getContext(), value.ToInt64());
     } else if constexpr (TC == Fortran::common::TypeCategory::Logical) {
-      TODO(getLoc(), "genval bool constant");
+      return genBoolConstant(value.IsTrue());
     } else if constexpr (TC == Fortran::common::TypeCategory::Real) {
       TODO(getLoc(), "genval real constant");
     } else if constexpr (TC == Fortran::common::TypeCategory::Complex) {

diff  --git a/flang/lib/Lower/Runtime.cpp b/flang/lib/Lower/Runtime.cpp
index 3ec2fed82eb5d..e5270bf1b393a 100644
--- a/flang/lib/Lower/Runtime.cpp
+++ b/flang/lib/Lower/Runtime.cpp
@@ -77,8 +77,13 @@ void Fortran::lower::genStopStatement(
       loc, calleeType.getInput(operands.size()), isError));
 
   // Third operand indicates QUIET (default to false).
-  if (std::get<std::optional<Fortran::parser::ScalarLogicalExpr>>(stmt.t)) {
-    TODO(loc, "STOP third operand not lowered yet");
+  if (const auto &quiet =
+          std::get<std::optional<Fortran::parser::ScalarLogicalExpr>>(stmt.t)) {
+    const SomeExpr *expr = Fortran::semantics::GetExpr(*quiet);
+    assert(expr && "failed getting typed expression");
+    mlir::Value q = fir::getBase(converter.genExprValue(*expr));
+    operands.push_back(
+        builder.createConvert(loc, calleeType.getInput(operands.size()), q));
   } else {
     operands.push_back(builder.createIntegerConstant(
         loc, calleeType.getInput(operands.size()), 0));

diff  --git a/flang/test/Lower/stop-statement.f90 b/flang/test/Lower/stop-statement.f90
index 062d8353e56df..e077b130aa8cf 100644
--- a/flang/test/Lower/stop-statement.f90
+++ b/flang/test/Lower/stop-statement.f90
@@ -28,3 +28,13 @@ subroutine stop_code()
  ! CHECK: fir.call @_Fortran{{.*}}StopStatement(%[[c42]], %[[false]], %[[false]])
  ! CHECK-NEXT: fir.unreachable
 end subroutine
+
+! CHECK-LABEL stop_quiet_constant
+subroutine stop_quiet_constant()
+  stop, quiet = .true.
+ ! CHECK-DAG: %[[true:.*]] = arith.constant true
+ ! CHECK-DAG: %[[false:.*]] = arith.constant false
+ ! CHECK-DAG: %[[c0:.*]] = arith.constant 0 : i32
+ ! CHECK: fir.call @_Fortran{{.*}}StopStatement(%[[c0]], %[[false]], %[[true]])
+ ! CHECK-NEXT: fir.unreachable
+end subroutine


        


More information about the flang-commits mailing list