[flang-commits] [PATCH] D132178: [flang][runtime] Catch input error case of missing integer value
Peter Klausler via Phabricator via flang-commits
flang-commits at lists.llvm.org
Thu Aug 18 15:51:38 PDT 2022
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG514b759a969b: [flang][runtime] Catch input error case of missing integer value (authored by klausler).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D132178/new/
https://reviews.llvm.org/D132178
Files:
flang/runtime/edit-input.cpp
flang/runtime/namelist.cpp
flang/runtime/namelist.h
Index: flang/runtime/namelist.h
===================================================================
--- flang/runtime/namelist.h
+++ flang/runtime/namelist.h
@@ -35,10 +35,11 @@
const Item *item; // in original declaration order
};
-// Look ahead on input for an identifier followed by a '=', '(', or '%'
+// Look ahead on input for a '/' or an identifier followed by a '=', '(', or '%'
// character; for use in disambiguating a name-like value (e.g. F or T) from a
-// NAMELIST group item name. Always false when not reading a NAMELIST.
-bool IsNamelistName(IoStatementState &);
+// NAMELIST group item name and for coping with short arrays. Always false
+// when not reading a NAMELIST.
+bool IsNamelistNameOrSlash(IoStatementState &);
} // namespace Fortran::runtime::io
#endif // FORTRAN_RUNTIME_NAMELIST_H_
Index: flang/runtime/namelist.cpp
===================================================================
--- flang/runtime/namelist.cpp
+++ flang/runtime/namelist.cpp
@@ -493,7 +493,7 @@
return true;
}
-bool IsNamelistName(IoStatementState &io) {
+bool IsNamelistNameOrSlash(IoStatementState &io) {
if (auto *listInput{
io.get_if<ListDirectedStatementState<Direction::Input>>()}) {
if (listInput->inNamelistArray()) {
@@ -508,6 +508,8 @@
ch = io.GetNextNonBlank(byteCount);
// TODO: how to deal with NaN(...) ambiguity?
return ch && (*ch == '=' || *ch == '(' || *ch == '%');
+ } else {
+ return *ch == '/';
}
}
}
Index: flang/runtime/edit-input.cpp
===================================================================
--- flang/runtime/edit-input.cpp
+++ flang/runtime/edit-input.cpp
@@ -118,7 +118,7 @@
RUNTIME_CHECK(io.GetIoErrorHandler(), kind >= 1 && !(kind & (kind - 1)));
switch (edit.descriptor) {
case DataEdit::ListDirected:
- if (IsNamelistName(io)) {
+ if (IsNamelistNameOrSlash(io)) {
return false;
}
break;
@@ -172,6 +172,11 @@
value += digit;
any = true;
}
+ if (!any && !remaining) {
+ io.GetIoErrorHandler().SignalError(
+ "Integer value absent from NAMELIST or list-directed input");
+ return false;
+ }
auto maxForKind{common::UnsignedInt128{1} << ((8 * kind) - 1)};
overflow |= value >= maxForKind && (value > maxForKind || !negate);
if (overflow) {
@@ -527,7 +532,7 @@
bool EditRealInput(IoStatementState &io, const DataEdit &edit, void *n) {
switch (edit.descriptor) {
case DataEdit::ListDirected:
- if (IsNamelistName(io)) {
+ if (IsNamelistNameOrSlash(io)) {
return false;
}
return EditCommonRealInput<KIND>(io, edit, n);
@@ -561,7 +566,7 @@
bool EditLogicalInput(IoStatementState &io, const DataEdit &edit, bool &x) {
switch (edit.descriptor) {
case DataEdit::ListDirected:
- if (IsNamelistName(io)) {
+ if (IsNamelistNameOrSlash(io)) {
return false;
}
break;
@@ -650,7 +655,7 @@
io.HandleRelativePosition(byteCount);
return EditDelimitedCharacterInput(io, x, length, *ch);
}
- if (IsNamelistName(io) || io.GetConnectionState().IsAtEOF()) {
+ if (IsNamelistNameOrSlash(io) || io.GetConnectionState().IsAtEOF()) {
return false;
}
// Undelimited list-directed character input: stop at a value separator
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D132178.453821.patch
Type: text/x-patch
Size: 3296 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20220818/f1fa59ca/attachment-0001.bin>
More information about the flang-commits
mailing list