[all-commits] [llvm/llvm-project] 511e93: Handle constant "pointers" for `__atomic_always_lo...

James Y Knight via All-commits all-commits at lists.llvm.org
Mon Jul 22 11:20:47 PDT 2024


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 511e93b96ee74438cbd643cec63281aff0663933
      https://github.com/llvm/llvm-project/commit/511e93b96ee74438cbd643cec63281aff0663933
  Author: James Y Knight <jyknight at google.com>
  Date:   2024-07-22 (Mon, 22 Jul 2024)

  Changed paths:
    M clang/docs/ReleaseNotes.rst
    M clang/lib/AST/ExprConstant.cpp
    M clang/test/Sema/atomic-ops.c

  Log Message:
  -----------
  Handle constant "pointers" for `__atomic_always_lock_free`/`__atomic_is_lock_free`. (#99340)

The second argument passed to these builtins is used to validate whether
the object's alignment is sufficient for atomic operations of the given
size.

Currently, the builtins can be folded at compile time only when the
argument is 0/nullptr, or if the _type_ of the pointer guarantees
appropriate alignment.

This change allows the compiler to also evaluate non-null constant
pointers, which enables callers to check a specified alignment, instead
of only the type or an exact object. E.g.:
 `__atomic_is_lock_free(sizeof(T), (void*)4)`
can be potentially evaluated to true at compile time, instead of
generating a libcall. This is also supported by GCC, and used by
libstdc++, and is also useful for libc++'s atomic_ref.

Also helps with (but doesn't fix) issue #75081.

This also fixes a crash bug, when the second argument was a non-pointer
implicitly convertible to a pointer (such as an array, or a function).



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