[flang-commits] [flang] cffc603 - [flang] Fix negative unit number hashing

peter klausler via flang-commits flang-commits at lists.llvm.org
Wed Jul 8 17:59:45 PDT 2020


Author: peter klausler
Date: 2020-07-08T17:59:00-07:00
New Revision: cffc6036173d540e0d0215ce177a667c838336c5

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

LOG: [flang] Fix negative unit number hashing

Ensure that external unit number hashing produces a valid
index for a negative unit number, viz. a NEWUNIT=.

Reviewed By: sscalpone

Differential Revision: https://reviews.llvm.org/D83428

Added: 
    

Modified: 
    flang/runtime/unit-map.h

Removed: 
    


################################################################################
diff  --git a/flang/runtime/unit-map.h b/flang/runtime/unit-map.h
index 286cb066fcd4..9efb2698d223 100644
--- a/flang/runtime/unit-map.h
+++ b/flang/runtime/unit-map.h
@@ -15,6 +15,7 @@
 #include "lock.h"
 #include "memory.h"
 #include "unit.h"
+#include <cstdlib>
 
 namespace Fortran::runtime::io {
 
@@ -59,7 +60,7 @@ class UnitMap {
   };
 
   static constexpr int buckets_{1031}; // must be prime
-  int Hash(int n) { return n % buckets_; }
+  int Hash(int n) { return std::abs(n) % buckets_; }
 
   ExternalFileUnit *Find(int n) {
     Chain *previous{nullptr};


        


More information about the flang-commits mailing list