[all-commits] [llvm/llvm-project] 7a6435: [DenseMap] Do not align pointer sentinel values (N...

Nikita Popov via All-commits all-commits at lists.llvm.org
Mon Jul 7 03:48:03 PDT 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 7a6435bec59010e4bb2e1e52a9ba840ed152b4ce
      https://github.com/llvm/llvm-project/commit/7a6435bec59010e4bb2e1e52a9ba840ed152b4ce
  Author: Nikita Popov <npopov at redhat.com>
  Date:   2025-07-07 (Mon, 07 Jul 2025)

  Changed paths:
    M clang/lib/AST/APValue.cpp
    M llvm/include/llvm/ADT/DenseMapInfo.h
    M llvm/include/llvm/ADT/PointerUnion.h
    M mlir/include/mlir/Support/TypeID.h
    M mlir/lib/Bindings/Python/NanobindUtils.h

  Log Message:
  -----------
  [DenseMap] Do not align pointer sentinel values (NFC) (#146595)

DenseMapInfo for pointers currently uses empty/tombstone values that are
aligned (by assuming a very conservative alignment). However, this means
that we have to work with larger immediates.

This patch proposes to use the values -1 and -2 instead, without caring
about pointer alignment. (Non-roundtrip) integer to pointer casts are
implementation-defined in C++, but the general implementer consensus
(including Clang) is that raw pointers do not carry alignment
requirements, only memory accesses do.

We already have lots of places that rely on this using variations on
`reinterpret_cast<T*>(-1)`, so it seems odd to insist on properly
aligned pointers in this one place.

It is necessary to adjust a few other places after this change, which
currently assume that `DenseMapInfo<void *>` returns a highly-aligned
pointer.

This is a small improvement for both compile-time and clang binary size.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list