[all-commits] [llvm/llvm-project] 2c84b9: Fix assertion in SmallDenseMap constructor with re...

David Blaikie via All-commits all-commits at lists.llvm.org
Mon Jul 25 10:09:59 PDT 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 2c84b92346bc45a88f92d781e30daa8490049c4d
      https://github.com/llvm/llvm-project/commit/2c84b92346bc45a88f92d781e30daa8490049c4d
  Author: Vladislav Dzhidzhoev <vdzhidzhoev at accesssoftek.com>
  Date:   2022-07-25 (Mon, 25 Jul 2022)

  Changed paths:
    M llvm/include/llvm/ADT/DenseMap.h
    M llvm/unittests/ADT/DenseMapTest.cpp

  Log Message:
  -----------
  Fix assertion in SmallDenseMap constructor with reserve from non-power-of-2 buckets count

`SmallDenseMap` constructor with reserve gets an arbitrary `NumInitBuckets` value and passes it below to `init` method.

If `NumInitBuckets` is greater then `InlineBuckets`, then `SmallDenseMap` initializes to large representation passing `NumInitBuckets` below to `DenseMap` initialization. `DenseMap::initEmpty` method asserts that initial buckets count must be a power of 2.

Proposed solution is to update `NumInitBuckets` value in `SmallDenseMap` constructor till the next power of 2. It should satisfy both `DenseMap` preconditions and required minimum buckets count for reservation.

Reviewed By: atrick

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




More information about the All-commits mailing list