[all-commits] [llvm/llvm-project] 0d1ed9: [libc] Tag cpp::byte with gnu::may_alias (#200462)

Mikhail R. Gadelha via All-commits all-commits at lists.llvm.org
Sat May 30 08:40:21 PDT 2026


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 0d1ed9383d1dc5133409e5088e336bc54700fbf7
      https://github.com/llvm/llvm-project/commit/0d1ed9383d1dc5133409e5088e336bc54700fbf7
  Author: Mikhail R. Gadelha <mikhail at igalia.com>
  Date:   2026-05-30 (Sat, 30 May 2026)

  Changed paths:
    M libc/src/__support/CPP/cstddef.h
    M libc/src/stdlib/qsort_data.h

  Log Message:
  -----------
  [libc] Tag cpp::byte with gnu::may_alias (#200462)

Clang's TBAA grants the [basic.lval]/11.3 char-aliasing privilege only
to the named ::std::byte type (Type::isStdByteType() requires the enum
to be declared in the std namespace). LIBC_NAMESPACE::cpp::byte lives in
libc's cpp namespace, so it gets its own TBAA node disjoint from char
even though it has the same shape as std::byte.

That mismatch lets the optimizer reorder typed loads past raw-byte
writes through cpp::byte *, miscompiling HeapSort on rv64/Release
(UnsortedThreeElementArray{1,2,3}, UnsortedTwoElementArray1 in
SortingTest.h). The same hazard is latent in every cpp::byte *-based
raw-aliasing site: memory_utils Ptr/CPtr, lsearch/lfind, block.h and
freelist_heap.h allocator metadata.

Tag the type with gnu::may_alias so accesses through cpp::byte * share
the universal char-aliasing TBAA node, fixing all of the above in one
place. This patch also reverts PR #194171, as the may_alias attribute
fixes it too.



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