[all-commits] [llvm/llvm-project] 53f51d: [ADT] Allow K to be incomplete during DenseMap<K*, ...

Reid Kleckner via All-commits all-commits at lists.llvm.org
Fri Feb 28 14:24:10 PST 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: 53f51da09e4530a193b7c17aece6daace6f6b8f5
      https://github.com/llvm/llvm-project/commit/53f51da09e4530a193b7c17aece6daace6f6b8f5
  Author: Reid Kleckner <rnk at google.com>
  Date:   2020-02-28 (Fri, 28 Feb 2020)

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

  Log Message:
  -----------
  [ADT] Allow K to be incomplete during DenseMap<K*, V> instantiation

DenseMap requires two sentinel values for keys: empty and tombstone
values. To avoid undefined behavior, LLVM aligns the two sentinel
pointers to alignof(T). This requires T to be complete, which is
needlessly restrictive.

Instead, assume that DenseMap pointer keys have a maximum alignment of
4096, and use the same sentinel values for all pointer keys. The new
sentinels are:
  empty:     static_cast<uintptr_t>(-1) << 12
  tombstone: static_cast<uintptr_t>(-2) << 12

These correspond to the addresses of -4096 and -8192. Hopefully, such a
key is never inserted into a DenseMap.

I encountered this while looking at making clang's SourceManager not
require FileManager.h, but it has several maps keyed on classes defined
in FileManager.h. FileManager depends on various LLVM FS headers, which
cumulatively take ~200ms to parse, and are generally not needed.

Reviewed By: hans

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




More information about the All-commits mailing list