[all-commits] [llvm/llvm-project] 30084d: [libc++] Fix type confusion in hash_{, multi}map

Peter Collingbourne via All-commits all-commits at lists.llvm.org
Tue Mar 24 15:45:16 PDT 2026


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 30084d74765c70e9cab4f11e9f2c29f141df299e
      https://github.com/llvm/llvm-project/commit/30084d74765c70e9cab4f11e9f2c29f141df299e
  Author: Peter Collingbourne <pcc at google.com>
  Date:   2026-03-24 (Tue, 24 Mar 2026)

  Changed paths:
    M libcxx/include/ext/hash_map
    A libcxx/test/extensions/gnu/hash_map/non_standard_layout.pass.cpp
    A libcxx/test/extensions/gnu/hash_multimap/non_standard_layout.pass.cpp

  Log Message:
  -----------
  [libc++] Fix type confusion in hash_{,multi}map

The type `__gnu_cxx::hash_{,multi}map` creates objects of type
`std::pair<Key, Value>` and returns pointers to them of type
`std::pair<const Key, Value>`. If either `Key` or `Value` are
non-standard-layout, this is UB, and is furthermore considered by
pointer field protection to be a type confusion, which leads to a
program crash. Fix it by using the correct type for the pair's storage
and using const_cast to form a pointer to the key in the one place where
that is needed.

Reviewers: ldionne

Reviewed By: ldionne

Pull Request: https://github.com/llvm/llvm-project/pull/183223



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