Skip to content

Commit e8e5d07

Browse files
committed
Revert "[flang] Avoid undefined behaviour when parsing format expressions (#147539)"
This reverts commit d0caf0d. MathExtras.h is not found in some builds.
1 parent 44d3769 commit e8e5d07

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

flang/include/flang/Common/format.h

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
#include "Fortran-consts.h"
1313
#include "enum-set.h"
14-
#include "llvm/Support/MathExtras.h"
1514
#include <cstring>
1615

1716
// Define a FormatValidator class template to validate a format expression
@@ -215,18 +214,16 @@ template <typename CHAR> void FormatValidator<CHAR>::NextToken() {
215214
case '7':
216215
case '8':
217216
case '9': {
217+
int64_t lastValue;
218218
const CHAR *lastCursor;
219219
integerValue_ = 0;
220220
bool overflow{false};
221221
do {
222+
lastValue = integerValue_;
222223
lastCursor = cursor_;
223-
if (LLVM_LIKELY(!overflow)) {
224-
overflow = llvm::MulOverflow(
225-
static_cast<int64_t>(10), integerValue_, integerValue_);
226-
}
227-
if (LLVM_LIKELY(!overflow)) {
228-
overflow = llvm::AddOverflow(
229-
integerValue_, static_cast<int64_t>(c - '0'), integerValue_);
224+
integerValue_ = 10 * integerValue_ + c - '0';
225+
if (lastValue > integerValue_) {
226+
overflow = true;
230227
}
231228
c = NextChar();
232229
} while (c >= '0' && c <= '9');

0 commit comments

Comments
 (0)