[flang-commits] [flang] 8927530 - [flang] Add lowering for basic empty SUBROUTINE
Valentin Clement via flang-commits
flang-commits at lists.llvm.org
Tue Feb 1 06:28:28 PST 2022
Author: Valentin Clement
Date: 2022-02-01T15:28:18+01:00
New Revision: 89275300d861aef73225428c95fdb069de36186d
URL: https://github.com/llvm/llvm-project/commit/89275300d861aef73225428c95fdb069de36186d
DIFF: https://github.com/llvm/llvm-project/commit/89275300d861aef73225428c95fdb069de36186d.diff
LOG: [flang] Add lowering for basic empty SUBROUTINE
This patch adds the ability to lower an empty subroutine.
Reviewed By: kiranchandramohan
Differential Revision: https://reviews.llvm.org/D118695
Added:
flang/test/Lower/basic-subroutine.f90
Modified:
flang/lib/Lower/Bridge.cpp
Removed:
################################################################################
diff --git a/flang/lib/Lower/Bridge.cpp b/flang/lib/Lower/Bridge.cpp
index 3645152444e06..fdd422586690e 100644
--- a/flang/lib/Lower/Bridge.cpp
+++ b/flang/lib/Lower/Bridge.cpp
@@ -175,6 +175,8 @@ class FirConverter : public Fortran::lower::AbstractConverter {
setCurrentPosition(Fortran::lower::pft::stmtSourceLoc(funit.endStmt));
if (funit.isMainProgram())
genExitRoutine();
+ else
+ genFIRProcedureExit(funit, funit.getSubprogramSymbol());
funit.finalBlock = nullptr;
LLVM_DEBUG(llvm::dbgs() << "*** Lowering result:\n\n"
<< *builder->getFunction() << '\n');
@@ -240,6 +242,15 @@ class FirConverter : public Fortran::lower::AbstractConverter {
}
void genFIR(const Fortran::parser::EndProgramStmt &) { genExitRoutine(); }
+ void genFIRProcedureExit(Fortran::lower::pft::FunctionLikeUnit &funit,
+ const Fortran::semantics::Symbol &symbol) {
+ if (Fortran::semantics::IsFunction(symbol)) {
+ TODO(toLocation(), "Function lowering");
+ } else {
+ genExitRoutine();
+ }
+ }
+
void genFIR(const Fortran::parser::CallStmt &stmt) {
TODO(toLocation(), "CallStmt lowering");
}
@@ -606,9 +617,8 @@ class FirConverter : public Fortran::lower::AbstractConverter {
TODO(toLocation(), "EndSelectStmt lowering");
}
- void genFIR(const Fortran::parser::EndSubroutineStmt &) {
- TODO(toLocation(), "EndSubroutineStmt lowering");
- }
+ // Nop statements - No code, or code is generated at the construct level.
+ void genFIR(const Fortran::parser::EndSubroutineStmt &) {} // nop
void genFIR(const Fortran::parser::EntryStmt &) {
TODO(toLocation(), "EntryStmt lowering");
diff --git a/flang/test/Lower/basic-subroutine.f90 b/flang/test/Lower/basic-subroutine.f90
new file mode 100644
index 0000000000000..aaa37d7123250
--- /dev/null
+++ b/flang/test/Lower/basic-subroutine.f90
@@ -0,0 +1,13 @@
+! RUN: bbc %s --pft-test | FileCheck %s
+! RUN: bbc %s -o "-" -emit-fir | FileCheck %s --check-prefix=FIR
+
+subroutine sub1()
+end subroutine
+
+! CHECK: 1 Subroutine sub1: subroutine sub1()
+! CHECK: 1 EndSubroutineStmt: end subroutine
+! CHECK: End Subroutine sub1
+
+! FIR-LABEL: func @_QPsub1() {
+! FIR: return
+! FIR: }
More information about the flang-commits
mailing list