[flang-commits] [flang] 1fd7232 - [flang] Runtime assigned format errors
V Donaldson via flang-commits
flang-commits at lists.llvm.org
Wed Aug 16 10:14:43 PDT 2023
Author: V Donaldson
Date: 2023-08-16T10:14:34-07:00
New Revision: 1fd72321a48d76ae884adb132a109817eee981a0
URL: https://github.com/llvm/llvm-project/commit/1fd72321a48d76ae884adb132a109817eee981a0
DIFF: https://github.com/llvm/llvm-project/commit/1fd72321a48d76ae884adb132a109817eee981a0.diff
LOG: [flang] Runtime assigned format errors
Generate a runtime error message for a reference to an invalid
assigned format such as:
if (.true.) print n
end
Added:
Modified:
flang/lib/Lower/IO.cpp
flang/test/Lower/format-statement.f90
Removed:
################################################################################
diff --git a/flang/lib/Lower/IO.cpp b/flang/lib/Lower/IO.cpp
index 505744adaa63f4..a35b7a991b8578 100644
--- a/flang/lib/Lower/IO.cpp
+++ b/flang/lib/Lower/IO.cpp
@@ -28,6 +28,7 @@
#include "flang/Optimizer/Builder/Complex.h"
#include "flang/Optimizer/Builder/FIRBuilder.h"
#include "flang/Optimizer/Builder/Runtime/RTBuilder.h"
+#include "flang/Optimizer/Builder/Runtime/Stop.h"
#include "flang/Optimizer/Builder/Todo.h"
#include "flang/Optimizer/Dialect/FIRDialect.h"
#include "flang/Optimizer/Dialect/Support/FIRContext.h"
@@ -1639,12 +1640,6 @@ lowerReferenceAsStringSelect(Fortran::lower::AbstractConverter &converter,
const Fortran::lower::SomeExpr &expr,
mlir::Type strTy, mlir::Type lenTy,
Fortran::lower::StatementContext &stmtCtx) {
- // Possible optimization TODO: Instead of inlining a selectOp every time there
- // is a variable reference to a format statement, a function with the selectOp
- // could be generated to reduce code size. It is not clear if such an
- // optimization would be deployed very often or improve the object code
- // beyond, say, what GVN/GCM might produce.
-
// Create the requisite blocks to inline a selectOp.
fir::FirOpBuilder &builder = converter.getFirOpBuilder();
mlir::Block *startBlock = builder.getBlock();
@@ -1657,9 +1652,7 @@ lowerReferenceAsStringSelect(Fortran::lower::AbstractConverter &converter,
auto symbol = GetLastSymbol(&expr);
Fortran::lower::pft::LabelSet labels;
- [[maybe_unused]] auto foundLabelSet =
- converter.lookupLabelSet(*symbol, labels);
- assert(foundLabelSet && "Label not found in map");
+ converter.lookupLabelSet(*symbol, labels);
for (auto label : labels) {
indexList.push_back(label);
@@ -1698,11 +1691,11 @@ lowerReferenceAsStringSelect(Fortran::lower::AbstractConverter &converter,
// Create the unit case which should result in an error.
auto *unitBlock = block->splitBlock(builder.getInsertionPoint());
builder.setInsertionPointToEnd(unitBlock);
-
- // Crash the program.
+ fir::runtime::genReportFatalUserError(
+ builder, loc,
+ "Assigned format variable '" + symbol->name().ToString() +
+ "' has not been assigned a valid format label");
builder.create<fir::UnreachableOp>(loc);
-
- // Add unit case to the select statement.
blockList.push_back(unitBlock);
// Lower the selectOp.
diff --git a/flang/test/Lower/format-statement.f90 b/flang/test/Lower/format-statement.f90
index 8f8d86e9dd7592..0828b965009ce1 100644
--- a/flang/test/Lower/format-statement.f90
+++ b/flang/test/Lower/format-statement.f90
@@ -22,12 +22,16 @@ subroutine formatAssign(flag1, flag2, flag3)
! CHECK: fir.store %[[TWO]]
! CHECK: br ^bb[[END_BLOCK]]
! CHECK: ^bb[[END_BLOCK]]
+ ! CHECK: fir.call @{{.*}}ReportFatalUserError
+ ! CHECK: fir.unreachable
! CHECK: fir.call @{{.*}}BeginExternalFormattedOutput
! CHECK: fir.call @{{.*}}OutputAscii
! CHECK: fir.call @{{.*}}OutputReal32
! CHECK: fir.call @{{.*}}EndIoStatement
pi = 3.141592653589
write(*, label) " PI=", pi
+ ! CHECK: fir.call @{{.*}}ReportFatalUserError
+ ! CHECK: fir.unreachable
! CHECK: fir.call @{{.*}}BeginExternalFormattedOutput
! CHECK: fir.call @{{.*}}OutputAscii
! CHECK: fir.call @{{.*}}OutputReal32
@@ -39,6 +43,8 @@ subroutine formatAssign(flag1, flag2, flag3)
assign 200 to label
end if
if (flag3) then
+ ! CHECK: fir.call @{{.*}}ReportFatalUserError
+ ! CHECK: fir.unreachable
! CHECK: fir.call @{{.*}}BeginExternalFormattedOutput
! CHECK: fir.call @{{.*}}OutputAscii
! CHECK: fir.call @{{.*}}OutputReal32
More information about the flang-commits
mailing list