[flang-commits] [flang] e8e5d07 - Revert "[flang] Avoid undefined behaviour when parsing format expressions (#147539)"

David Spickett via flang-commits flang-commits at lists.llvm.org
Wed Jul 9 07:50:56 PDT 2025


Author: David Spickett
Date: 2025-07-09T14:49:58Z
New Revision: e8e5d07767c444913f837dd35846a92fcf520eab

URL: https://github.com/llvm/llvm-project/commit/e8e5d07767c444913f837dd35846a92fcf520eab
DIFF: https://github.com/llvm/llvm-project/commit/e8e5d07767c444913f837dd35846a92fcf520eab.diff

LOG: Revert "[flang] Avoid undefined behaviour when parsing format expressions (#147539)"

This reverts commit d0caf0d4857c2b00ba988f86703663685ec8697f.

MathExtras.h is not found in some builds.

Added: 
    

Modified: 
    flang/include/flang/Common/format.h

Removed: 
    


################################################################################
diff  --git a/flang/include/flang/Common/format.h b/flang/include/flang/Common/format.h
index 11aa6f2c07797..1650f56140b4d 100644
--- a/flang/include/flang/Common/format.h
+++ b/flang/include/flang/Common/format.h
@@ -11,7 +11,6 @@
 
 #include "Fortran-consts.h"
 #include "enum-set.h"
-#include "llvm/Support/MathExtras.h"
 #include <cstring>
 
 // Define a FormatValidator class template to validate a format expression
@@ -215,18 +214,16 @@ template <typename CHAR> void FormatValidator<CHAR>::NextToken() {
   case '7':
   case '8':
   case '9': {
+    int64_t lastValue;
     const CHAR *lastCursor;
     integerValue_ = 0;
     bool overflow{false};
     do {
+      lastValue = integerValue_;
       lastCursor = cursor_;
-      if (LLVM_LIKELY(!overflow)) {
-        overflow = llvm::MulOverflow(
-            static_cast<int64_t>(10), integerValue_, integerValue_);
-      }
-      if (LLVM_LIKELY(!overflow)) {
-        overflow = llvm::AddOverflow(
-            integerValue_, static_cast<int64_t>(c - '0'), integerValue_);
+      integerValue_ = 10 * integerValue_ + c - '0';
+      if (lastValue > integerValue_) {
+        overflow = true;
       }
       c = NextChar();
     } while (c >= '0' && c <= '9');


        


More information about the flang-commits mailing list