[flang-commits] [flang] ee7b6fd - [flang] Set proper source location for the main function.
Slava Zakharin via flang-commits
flang-commits at lists.llvm.org
Tue Mar 21 12:32:58 PDT 2023
Author: Slava Zakharin
Date: 2023-03-21T12:32:42-07:00
New Revision: ee7b6fd4c1c11641f9b1b54441ed038fd761de13
URL: https://github.com/llvm/llvm-project/commit/ee7b6fd4c1c11641f9b1b54441ed038fd761de13
DIFF: https://github.com/llvm/llvm-project/commit/ee7b6fd4c1c11641f9b1b54441ed038fd761de13.diff
LOG: [flang] Set proper source location for the main function.
Take the source position for the anonymous program from its scope.
If the first evaluation is a construct or directive, then it has
null source position.
Author: vdonaldson
Differential Revision: https://reviews.llvm.org/D146445
Added:
flang/test/Lower/main_location.f90
Modified:
flang/lib/Lower/PFTBuilder.cpp
Removed:
################################################################################
diff --git a/flang/lib/Lower/PFTBuilder.cpp b/flang/lib/Lower/PFTBuilder.cpp
index 6261a9093cbc..2c63852ce95e 100644
--- a/flang/lib/Lower/PFTBuilder.cpp
+++ b/flang/lib/Lower/PFTBuilder.cpp
@@ -1671,9 +1671,7 @@ parser::CharBlock
Fortran::lower::pft::FunctionLikeUnit::getStartingSourceLoc() const {
if (beginStmt)
return stmtSourceLoc(*beginStmt);
- if (!evaluationList.empty())
- return evaluationList.front().position;
- return stmtSourceLoc(endStmt);
+ return scope->sourceRange();
}
//===----------------------------------------------------------------------===//
diff --git a/flang/test/Lower/main_location.f90 b/flang/test/Lower/main_location.f90
new file mode 100644
index 000000000000..db63339288f0
--- /dev/null
+++ b/flang/test/Lower/main_location.f90
@@ -0,0 +1,26 @@
+! RUN: split-file %s %t
+! RUN: bbc %t/test1.f90 -o - --emit-fir --mlir-print-debuginfo | FileCheck %s --check-prefix=TEST1
+! RUN: bbc %t/test2.f90 -o - --emit-fir --mlir-print-debuginfo | FileCheck %s --check-prefix=TEST2
+
+! Check that the missing optional program-stmt (R1401)
+! does not result in unknown source location of the corresponding
+! function.
+
+!--- test1.f90
+if (.false.) then
+endif
+end
+
+! TEST1: func.func @_QQmain() {
+! TEST1-NEXT: return loc("{{.*}}test1.f90":3:1)
+! TEST1-NEXT: } loc("{{.*}}test1.f90":1:1)
+
+!--- test2.f90
+!!! keep me here
+if (.true.) then
+endif
+end program
+
+! TEST2: func.func @_QQmain() {
+! TEST2-NEXT: return loc("{{.*}}test2.f90":4:1)
+! TEST2-NEXT: } loc("{{.*}}test2.f90":2:1)
More information about the flang-commits
mailing list