From: peter klausler Date: Wed, 8 Jul 2020 20:09:53 +0000 (-0700) Subject: [flang] Fix negative unit number hashing X-Git-Tag: llvmorg-12-init~628 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=cffc6036173d540e0d0215ce177a667c838336c5;p=platform%2Fupstream%2Fllvm.git [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 --- diff --git a/flang/runtime/unit-map.h b/flang/runtime/unit-map.h index 286cb06..9efb269 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 namespace Fortran::runtime::io { @@ -59,7 +60,7 @@ private: }; 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};