[flang-commits] [flang] c02abb6 - [flang][runtime] Enforce some limits on kP scale factors
Peter Klausler via flang-commits
flang-commits at lists.llvm.org
Fri Apr 22 16:51:42 PDT 2022
Author: Peter Klausler
Date: 2022-04-22T16:51:36-07:00
New Revision: c02abb68cd88a9edbc5d4dd83de6f50766fb9ae8
URL: https://github.com/llvm/llvm-project/commit/c02abb68cd88a9edbc5d4dd83de6f50766fb9ae8
DIFF: https://github.com/llvm/llvm-project/commit/c02abb68cd88a9edbc5d4dd83de6f50766fb9ae8.diff
LOG: [flang][runtime] Enforce some limits on kP scale factors
Ew.d and Dw.d output edit descriptors should respect limitations from
the standard on the value of a kP scale factor with respect to the
digit count (d), at least for values of k other than zero.
Differential Revision: https://reviews.llvm.org/D124300
Added:
Modified:
flang/include/flang/Runtime/iostat.h
flang/runtime/edit-output.cpp
flang/runtime/iostat.cpp
Removed:
################################################################################
diff --git a/flang/include/flang/Runtime/iostat.h b/flang/include/flang/Runtime/iostat.h
index 0303d3de16d09..f09f25a738e2e 100644
--- a/flang/include/flang/Runtime/iostat.h
+++ b/flang/include/flang/Runtime/iostat.h
@@ -69,6 +69,7 @@ enum Iostat {
IostatUTF8Decoding,
IostatUnitOverflow,
IostatBadRealInput,
+ IostatBadScaleFactor,
};
const char *IostatErrorString(int);
diff --git a/flang/runtime/edit-output.cpp b/flang/runtime/edit-output.cpp
index 95292ded777b6..ebdc62b78bb6b 100644
--- a/flang/runtime/edit-output.cpp
+++ b/flang/runtime/edit-output.cpp
@@ -196,9 +196,21 @@ bool RealOutputEditing<binaryPrecision>::EditEorDOutput(const DataEdit &edit) {
int scale{isEN || isES ? 1 : edit.modes.scale}; // 'kP' value
int zeroesAfterPoint{0};
if (scale < 0) {
+ if (scale <= -editDigits) {
+ io_.GetIoErrorHandler().SignalError(IostatBadScaleFactor,
+ "Scale factor (kP) %d cannot be less than -d (%d)", scale,
+ -editDigits);
+ return false;
+ }
zeroesAfterPoint = -scale;
significantDigits = std::max(0, significantDigits - zeroesAfterPoint);
} else if (scale > 0) {
+ if (scale >= editDigits + 2) {
+ io_.GetIoErrorHandler().SignalError(IostatBadScaleFactor,
+ "Scale factor (kP) %d cannot be greater than d+2 (%d)", scale,
+ editDigits + 2);
+ return false;
+ }
++significantDigits;
scale = std::min(scale, significantDigits + 1);
}
diff --git a/flang/runtime/iostat.cpp b/flang/runtime/iostat.cpp
index e31fb83678301..e375b28a4c734 100644
--- a/flang/runtime/iostat.cpp
+++ b/flang/runtime/iostat.cpp
@@ -81,6 +81,8 @@ const char *IostatErrorString(int iostat) {
return "UNIT number is out of range";
case IostatBadRealInput:
return "Bad REAL input value";
+ case IostatBadScaleFactor:
+ return "Bad REAL output scale factor (kP)";
default:
return nullptr;
}
More information about the flang-commits
mailing list